Fix onvif failing to reload (#91482)
parent
0cf29f0f84
commit
e7373d979b
|
@ -39,15 +39,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
hass.data[DOMAIN][entry.unique_id] = device
|
||||
|
||||
platforms = [Platform.BUTTON, Platform.CAMERA]
|
||||
device.platforms = [Platform.BUTTON, Platform.CAMERA]
|
||||
|
||||
if device.capabilities.events:
|
||||
platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
device.platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
|
||||
if device.capabilities.imaging:
|
||||
platforms += [Platform.SWITCH]
|
||||
device.platforms += [Platform.SWITCH]
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, device.platforms)
|
||||
|
||||
entry.async_on_unload(
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.async_stop)
|
||||
|
@ -59,16 +59,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
|
||||
device = hass.data[DOMAIN][entry.unique_id]
|
||||
platforms = ["camera"]
|
||||
device: ONVIFDevice = hass.data[DOMAIN][entry.unique_id]
|
||||
|
||||
if device.capabilities.events and device.events.started:
|
||||
platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
await device.events.async_stop()
|
||||
if device.capabilities.imaging:
|
||||
platforms += [Platform.SWITCH]
|
||||
|
||||
return await hass.config_entries.async_unload_platforms(entry, platforms)
|
||||
return await hass.config_entries.async_unload_platforms(entry, device.platforms)
|
||||
|
||||
|
||||
async def _get_snapshot_auth(device):
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -55,6 +56,7 @@ class ONVIFDevice:
|
|||
self.capabilities: Capabilities = Capabilities()
|
||||
self.profiles: list[Profile] = []
|
||||
self.max_resolution: int = 0
|
||||
self.platforms: list[Platform] = []
|
||||
|
||||
self._dt_diff_seconds: float = 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue