Skip to content

Commit

Permalink
Fix issue iMicknl#14
Browse files Browse the repository at this point in the history
  • Loading branch information
bakonyiferenc authored Mar 15, 2024
1 parent d0350e1 commit 4075f27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions custom_components/sagemcom_fast/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ async def _async_update_data(self) -> dict[str, Device]:
return self.hosts
except Exception as exception:
raise UpdateFailed(f"Error communicating with API: {exception}")

@property
def signal_device_new(self) -> str:
"""Event specific per Sagemcom F@st entry to signal new device."""
return f"{DOMAIN}-device-new-{self._id}"
21 changes: 17 additions & 4 deletions custom_components/sagemcom_fast/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sagemcom_api.models import Device

from . import HomeAssistantSagemcomFastData
from .const import DOMAIN
from .const import LOGGER, DOMAIN
from .coordinator import SagemcomDataUpdateCoordinator


Expand All @@ -23,13 +23,26 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up device tracker from config entry."""

LOGGER.debug("Starting Sagemcom F@st device tracker")
data: HomeAssistantSagemcomFastData = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
SagemcomScannerEntity(data.coordinator, idx, entry.entry_id)
for idx, device in data.coordinator.data.items()
@callback
def async_update_router() -> None:
"""Update the values of the router."""
async_add_entities(
SagemcomScannerEntity(data.coordinator, idx, entry.entry_id)
for idx, device in data.coordinator.data.items()
)

entry.async_on_unload(
async_dispatcher_connect(
hass, data.coordinator.signal_device_new, async_update_router
)
)

async_update_router()


class SagemcomScannerEntity(
ScannerEntity, RestoreEntity, CoordinatorEntity[SagemcomDataUpdateCoordinator]
Expand Down

0 comments on commit 4075f27

Please sign in to comment.