diff --git a/custom_components/miwifi/__init__.py b/custom_components/miwifi/__init__.py index 9a2abeb..c19c766 100644 --- a/custom_components/miwifi/__init__.py +++ b/custom_components/miwifi/__init__.py @@ -65,6 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: get_config_value(entry, CONF_IS_FORCE_LOAD, False), get_config_value(entry, CONF_ACTIVITY_DAYS, DEFAULT_ACTIVITY_DAYS), get_store(hass, _ip), + entry_id=entry.entry_id, ) hass.data.setdefault(DOMAIN, {}) diff --git a/custom_components/miwifi/manifest.json b/custom_components/miwifi/manifest.json index 811a03d..931417c 100644 --- a/custom_components/miwifi/manifest.json +++ b/custom_components/miwifi/manifest.json @@ -1,7 +1,7 @@ { "domain": "miwifi", "name": "MiWiFi", - "version": "2.5.0", + "version": "2.5.1", "documentation": "https://github.com/dmamontov/hass-miwifi/blob/main/README.md", "issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues", "config_flow": true, diff --git a/custom_components/miwifi/updater.py b/custom_components/miwifi/updater.py index 4c046a2..d33e393 100644 --- a/custom_components/miwifi/updater.py +++ b/custom_components/miwifi/updater.py @@ -148,6 +148,7 @@ class LuciUpdater(DataUpdateCoordinator): _store: Store | None = None + _entry_id: str | None = None _scan_interval: int _activity_days: int _is_only_login: bool = False @@ -168,6 +169,7 @@ def __init__( activity_days: int = DEFAULT_ACTIVITY_DAYS, store: Store | None = None, is_only_login: bool = False, + entry_id: str | None = None, ) -> None: """Initialize updater. @@ -181,6 +183,7 @@ def __init__( :param activity_days: int: Allowed number of days to wait after the last activity :param store: Store | None: Device store :param is_only_login: bool: Only config flow + :param entry_id: str | None: Entry ID """ self.luci = LuciClient(get_async_client(hass, False), ip, password, timeout) @@ -190,6 +193,8 @@ def __init__( self._store = store + self._entry_id = entry_id + self._scan_interval = scan_interval self._activity_days = activity_days self._is_only_login = is_only_login @@ -245,7 +250,7 @@ async def update(self, retry: int = 1) -> dict: await self.luci.login() for method in PREPARE_METHODS: - if not self._is_only_login or self._is_first_update or method == "init": + if not self._is_only_login or method == "init": await self._async_prepare(method, self.data) except LuciConnectionException as _e: _err = _e @@ -304,21 +309,6 @@ def is_repeater(self) -> bool: return self.data.get(ATTR_SENSOR_MODE, Mode.DEFAULT).value > 0 - @cached_property - def entry_id(self) -> str | None: - """Get entry_id - - :return str | None: entry id - """ - - integrations: dict = self.get_integrations() - - return ( - integrations[self.ip][ATTR_TRACKER_ENTRY_ID] - if self.ip in integrations - else None - ) - @property def device_info(self): """Device info. @@ -664,8 +654,8 @@ async def _async_prepare_devices(self, data: dict) -> None: if self.is_repeater and self.is_force_load: device |= { - ATTR_TRACKER_ENTRY_ID: self.entry_id, - ATTR_TRACKER_UPDATER_ENTRY_ID: self.entry_id, + ATTR_TRACKER_ENTRY_ID: self._entry_id, + ATTR_TRACKER_UPDATER_ENTRY_ID: self._entry_id, } action: DeviceAction = DeviceAction.ADD @@ -732,7 +722,7 @@ async def _async_prepare_device_list(self, data: dict) -> None: action, ) else: - device[ATTR_TRACKER_ENTRY_ID] = self.entry_id + device[ATTR_TRACKER_ENTRY_ID] = self._entry_id if device[ATTR_TRACKER_MAC] in self._moved_devices: if self._mass_update_device(device, integrations): @@ -741,9 +731,7 @@ async def _async_prepare_device_list(self, data: dict) -> None: self._moved_devices.remove(device[ATTR_TRACKER_MAC]) if device[ATTR_TRACKER_MAC] not in self._moved_devices: - device[ATTR_TRACKER_UPDATER_ENTRY_ID] = integrations[self.ip][ - ATTR_TRACKER_ENTRY_ID - ] + device[ATTR_TRACKER_UPDATER_ENTRY_ID] = self._entry_id self.add_device(device, action=action, integrations=integrations) @@ -782,7 +770,7 @@ async def _async_prepare_device_restore(self, data: dict) -> None: if mac in self.devices: continue - if device[ATTR_TRACKER_ENTRY_ID] != self.entry_id: + if device[ATTR_TRACKER_ENTRY_ID] != self._entry_id: for integration in integrations.values(): if ( not integration[UPDATER].is_force_load