mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
@@ -16,7 +16,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@@ -183,7 +183,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
def cleanup_disconnected_cams(
|
def cleanup_disconnected_cams(
|
||||||
hass: HomeAssistant, config_entry_id: str, host: ReolinkHost
|
hass: HomeAssistant, config_entry_id: str, host: ReolinkHost
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Clean-up disconnected camera channels or channels where a different model camera is connected."""
|
"""Clean-up disconnected camera channels."""
|
||||||
if not host.api.is_nvr:
|
if not host.api.is_nvr:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -206,14 +206,16 @@ def cleanup_disconnected_cams(
|
|||||||
if ch not in host.api.channels:
|
if ch not in host.api.channels:
|
||||||
remove = True
|
remove = True
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Removing Reolink device %s, since no camera is connected to NVR channel %s anymore",
|
"Removing Reolink device %s, "
|
||||||
|
"since no camera is connected to NVR channel %s anymore",
|
||||||
device.name,
|
device.name,
|
||||||
ch,
|
ch,
|
||||||
)
|
)
|
||||||
if ch_model not in [device.model, "Unknown"]:
|
if ch_model not in [device.model, "Unknown"]:
|
||||||
remove = True
|
remove = True
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Removing Reolink device %s, since the camera model connected to channel %s changed from %s to %s",
|
"Removing Reolink device %s, "
|
||||||
|
"since the camera model connected to channel %s changed from %s to %s",
|
||||||
device.name,
|
device.name,
|
||||||
ch,
|
ch,
|
||||||
device.model,
|
device.model,
|
||||||
@@ -222,12 +224,5 @@ def cleanup_disconnected_cams(
|
|||||||
if not remove:
|
if not remove:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# clean entity and device registry
|
# clean device registry and associated entities
|
||||||
entity_reg = er.async_get(hass)
|
|
||||||
entities = er.async_entries_for_device(
|
|
||||||
entity_reg, device.id, include_disabled_entities=True
|
|
||||||
)
|
|
||||||
for entity in entities:
|
|
||||||
entity_reg.async_remove(entity.entity_id)
|
|
||||||
|
|
||||||
device_reg.async_remove_device(device.id)
|
device_reg.async_remove_device(device.id)
|
||||||
|
Reference in New Issue
Block a user