Skip to content

Commit

Permalink
Merge pull request #51 from KiraPC/dev
Browse files Browse the repository at this point in the history
#50 remove unregistered devices
  • Loading branch information
KiraPC authored Jul 18, 2024
2 parents 753fbd3 + 7ad3be8 commit c686036
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions custom_components/switchbotremote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from .client import SwitchBot

from .const import DOMAIN
from homeassistant.helpers import (
device_registry as dr,
)

PLATFORMS: list[Platform] = [
Platform.CLIMATE,
Expand Down Expand Up @@ -37,6 +40,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

device_registry = dr.async_get(hass)
for device_entry in dr.async_entries_for_config_entry(
device_registry, entry.entry_id
):
device_id = list(device_entry.identifiers)[0][1]
registered = next((remote for remote in remotes if remote.id == device_id), None)

if not registered:
device_registry.async_remove_device(device_entry.id)

return True


Expand Down

0 comments on commit c686036

Please sign in to comment.