44from homeassistant .components .device_tracker import SourceType
55from homeassistant .components .device_tracker .config_entry import ScannerEntity
66from homeassistant .config_entries import ConfigEntry
7- from homeassistant .core import HomeAssistant
7+ from homeassistant .core import HomeAssistant , callback
88from homeassistant .helpers .device_registry import CONNECTION_NETWORK_MAC , DeviceInfo
99from homeassistant .helpers .entity_platform import AddEntitiesCallback
1010from 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
3445class SagemcomScannerEntity (
0 commit comments