Skip to content

Commit

Permalink
Fixing issue #116 (#117)
Browse files Browse the repository at this point in the history
* Fix issue #116

* Format code with black
  • Loading branch information
bakonyiferenc authored Mar 23, 2024
1 parent d0350e1 commit 62ce373
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions custom_components/sagemcom_fast/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from homeassistant.components.device_tracker import SourceType
from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
Expand All @@ -24,11 +24,22 @@ async def async_setup_entry(
) -> None:
"""Set up device tracker from config entry."""
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()
)
tracked: dict[str, SagemcomScannerEntity] = {}

@callback
def async_update_router() -> None:
"""Update the values of the router."""
newly_discovered: list[SagemcomScannerEntity] = []
for idx, device in data.coordinator.data.items():
if idx not in tracked:
tracked[idx] = SagemcomScannerEntity(
data.coordinator, idx, entry.entry_id
)
newly_discovered.append(tracked[idx])
async_add_entities(newly_discovered)

entry.async_on_unload(data.coordinator.async_add_listener(async_update_router))
async_update_router()


class SagemcomScannerEntity(
Expand Down

0 comments on commit 62ce373

Please sign in to comment.