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
|
hass.data[DOMAIN][entry.unique_id] = device
|
||||||
|
|
||||||
platforms = [Platform.BUTTON, Platform.CAMERA]
|
device.platforms = [Platform.BUTTON, Platform.CAMERA]
|
||||||
|
|
||||||
if device.capabilities.events:
|
if device.capabilities.events:
|
||||||
platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
device.platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
if device.capabilities.imaging:
|
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(
|
entry.async_on_unload(
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, device.async_stop)
|
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:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
|
||||||
device = hass.data[DOMAIN][entry.unique_id]
|
device: ONVIFDevice = hass.data[DOMAIN][entry.unique_id]
|
||||||
platforms = ["camera"]
|
|
||||||
|
|
||||||
if device.capabilities.events and device.events.started:
|
if device.capabilities.events and device.events.started:
|
||||||
platforms += [Platform.BINARY_SENSOR, Platform.SENSOR]
|
|
||||||
await device.events.async_stop()
|
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):
|
async def _get_snapshot_auth(device):
|
||||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
@ -55,6 +56,7 @@ class ONVIFDevice:
|
||||||
self.capabilities: Capabilities = Capabilities()
|
self.capabilities: Capabilities = Capabilities()
|
||||||
self.profiles: list[Profile] = []
|
self.profiles: list[Profile] = []
|
||||||
self.max_resolution: int = 0
|
self.max_resolution: int = 0
|
||||||
|
self.platforms: list[Platform] = []
|
||||||
|
|
||||||
self._dt_diff_seconds: float = 0
|
self._dt_diff_seconds: float = 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue