Skip to content

Commit 62ce373

Browse files
Fixing issue #116 (#117)
* Fix issue #116 * Format code with black
1 parent d0350e1 commit 62ce373

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

custom_components/sagemcom_fast/device_tracker.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from homeassistant.components.device_tracker import SourceType
55
from homeassistant.components.device_tracker.config_entry import ScannerEntity
66
from homeassistant.config_entries import ConfigEntry
7-
from homeassistant.core import HomeAssistant
7+
from homeassistant.core import HomeAssistant, callback
88
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
99
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1010
from homeassistant.helpers.restore_state import RestoreEntity
@@ -24,11 +24,22 @@ async def async_setup_entry(
2424
) -> None:
2525
"""Set up device tracker from config entry."""
2626
data: HomeAssistantSagemcomFastData = hass.data[DOMAIN][entry.entry_id]
27-
28-
async_add_entities(
29-
SagemcomScannerEntity(data.coordinator, idx, entry.entry_id)
30-
for idx, device in data.coordinator.data.items()
31-
)
27+
tracked: dict[str, SagemcomScannerEntity] = {}
28+
29+
@callback
30+
def async_update_router() -> None:
31+
"""Update the values of the router."""
32+
newly_discovered: list[SagemcomScannerEntity] = []
33+
for idx, device in data.coordinator.data.items():
34+
if idx not in tracked:
35+
tracked[idx] = SagemcomScannerEntity(
36+
data.coordinator, idx, entry.entry_id
37+
)
38+
newly_discovered.append(tracked[idx])
39+
async_add_entities(newly_discovered)
40+
41+
entry.async_on_unload(data.coordinator.async_add_listener(async_update_router))
42+
async_update_router()
3243

3344

3445
class SagemcomScannerEntity(

0 commit comments

Comments
 (0)