Add support for async_remove_config_entry_device to isy994 (#72737)
This commit is contained in:
parent
a53aaf696c
commit
52643d9abc
4 changed files with 57 additions and 28 deletions
|
@ -579,6 +579,7 @@ omit =
|
|||
homeassistant/components/isy994/sensor.py
|
||||
homeassistant/components/isy994/services.py
|
||||
homeassistant/components/isy994/switch.py
|
||||
homeassistant/components/isy994/util.py
|
||||
homeassistant/components/itach/remote.py
|
||||
homeassistant/components/itunes/media_player.py
|
||||
homeassistant/components/jellyfin/__init__.py
|
||||
|
|
|
@ -45,6 +45,7 @@ from .const import (
|
|||
)
|
||||
from .helpers import _categorize_nodes, _categorize_programs, _categorize_variables
|
||||
from .services import async_setup_services, async_unload_services
|
||||
from .util import unique_ids_for_config_entry_id
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
|
@ -296,3 +297,15 @@ async def async_unload_entry(
|
|||
async_unload_services(hass)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
async def async_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
config_entry: config_entries.ConfigEntry,
|
||||
device_entry: dr.DeviceEntry,
|
||||
) -> bool:
|
||||
"""Remove isy994 config entry from a device."""
|
||||
return not device_entry.identifiers.intersection(
|
||||
(DOMAIN, unique_id)
|
||||
for unique_id in unique_ids_for_config_entry_id(hass, config_entry.entry_id)
|
||||
)
|
||||
|
|
|
@ -21,16 +21,8 @@ from homeassistant.helpers.entity_platform import async_get_platforms
|
|||
import homeassistant.helpers.entity_registry as er
|
||||
from homeassistant.helpers.service import entity_service_call
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
DOMAIN,
|
||||
ISY994_ISY,
|
||||
ISY994_NODES,
|
||||
ISY994_PROGRAMS,
|
||||
ISY994_VARIABLES,
|
||||
PLATFORMS,
|
||||
PROGRAM_PLATFORMS,
|
||||
)
|
||||
from .const import _LOGGER, DOMAIN, ISY994_ISY
|
||||
from .util import unique_ids_for_config_entry_id
|
||||
|
||||
# Common Services for All Platforms:
|
||||
SERVICE_SYSTEM_QUERY = "system_query"
|
||||
|
@ -282,7 +274,7 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
|
|||
"""Remove extra entities that are no longer part of the integration."""
|
||||
entity_registry = er.async_get(hass)
|
||||
config_ids = []
|
||||
current_unique_ids = []
|
||||
current_unique_ids: set[str] = set()
|
||||
|
||||
for config_entry_id in hass.data[DOMAIN]:
|
||||
entries_for_this_config = er.async_entries_for_config_entry(
|
||||
|
@ -294,23 +286,7 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
|
|||
for entity in entries_for_this_config
|
||||
]
|
||||
)
|
||||
|
||||
hass_isy_data = hass.data[DOMAIN][config_entry_id]
|
||||
uuid = hass_isy_data[ISY994_ISY].configuration["uuid"]
|
||||
|
||||
for platform in PLATFORMS:
|
||||
for node in hass_isy_data[ISY994_NODES][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.append(f"{uuid}_{node.address}")
|
||||
|
||||
for platform in PROGRAM_PLATFORMS:
|
||||
for _, node, _ in hass_isy_data[ISY994_PROGRAMS][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.append(f"{uuid}_{node.address}")
|
||||
|
||||
for node in hass_isy_data[ISY994_VARIABLES]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.append(f"{uuid}_{node.address}")
|
||||
current_unique_ids |= unique_ids_for_config_entry_id(hass, config_entry_id)
|
||||
|
||||
extra_entities = [
|
||||
entity_id
|
||||
|
|
39
homeassistant/components/isy994/util.py
Normal file
39
homeassistant/components/isy994/util.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""ISY utils."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
ISY994_ISY,
|
||||
ISY994_NODES,
|
||||
ISY994_PROGRAMS,
|
||||
ISY994_VARIABLES,
|
||||
PLATFORMS,
|
||||
PROGRAM_PLATFORMS,
|
||||
)
|
||||
|
||||
|
||||
def unique_ids_for_config_entry_id(
|
||||
hass: HomeAssistant, config_entry_id: str
|
||||
) -> set[str]:
|
||||
"""Find all the unique ids for a config entry id."""
|
||||
hass_isy_data = hass.data[DOMAIN][config_entry_id]
|
||||
uuid = hass_isy_data[ISY994_ISY].configuration["uuid"]
|
||||
current_unique_ids: set[str] = {uuid}
|
||||
|
||||
for platform in PLATFORMS:
|
||||
for node in hass_isy_data[ISY994_NODES][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
|
||||
for platform in PROGRAM_PLATFORMS:
|
||||
for _, node, _ in hass_isy_data[ISY994_PROGRAMS][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
|
||||
for node in hass_isy_data[ISY994_VARIABLES]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
|
||||
return current_unique_ids
|
Loading…
Add table
Add a link
Reference in a new issue