Fix onvif failing to reload (#91482)

pull/91498/head
J. Nick Koston 2023-04-16 02:05:10 -10:00 committed by GitHub
parent 0cf29f0f84
commit e7373d979b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -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):

View File

@ -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