From 6d110fa684e71dbad2528865eb7ab1dc3d7a4ebd Mon Sep 17 00:00:00 2001 From: Dmitry Mamontov Date: Mon, 4 Apr 2022 15:06:45 +0300 Subject: [PATCH] fix bugs --- custom_components/miwifi/__init__.py | 2 +- custom_components/miwifi/binary_sensor.py | 16 +- custom_components/miwifi/button.py | 16 +- custom_components/miwifi/config_flow.py | 16 +- custom_components/miwifi/device_tracker.py | 22 +-- custom_components/miwifi/discovery.py | 6 +- custom_components/miwifi/helper.py | 2 +- custom_components/miwifi/light.py | 16 +- custom_components/miwifi/luci.py | 12 +- custom_components/miwifi/manifest.json | 2 +- custom_components/miwifi/sensor.py | 26 +-- custom_components/miwifi/switch.py | 18 +- custom_components/miwifi/updater.py | 198 ++++++++++++++------- 13 files changed, 211 insertions(+), 141 deletions(-) diff --git a/custom_components/miwifi/__init__.py b/custom_components/miwifi/__init__.py index cb67627..9b85a59 100644 --- a/custom_components/miwifi/__init__.py +++ b/custom_components/miwifi/__init__.py @@ -148,7 +148,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_remove_config_entry_device( - hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry + hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry ) -> bool: """Remove cast config entry from a device. diff --git a/custom_components/miwifi/binary_sensor.py b/custom_components/miwifi/binary_sensor.py index 45cfc2e..51b6663 100644 --- a/custom_components/miwifi/binary_sensor.py +++ b/custom_components/miwifi/binary_sensor.py @@ -71,9 +71,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi binary sensor entry. @@ -92,7 +92,7 @@ async def async_setup_entry( entities: list[MiWifiBinarySensor] = [ MiWifiBinarySensor( - f"{config_entry.unique_id}-{description.key}", + f"{config_entry.entry_id}-{description.key}", description, updater, ) @@ -107,10 +107,10 @@ class MiWifiBinarySensor(BinarySensorEntity, CoordinatorEntity, RestoreEntity): _attr_attribution: str = ATTRIBUTION def __init__( - self, - unique_id: str, - description: BinarySensorEntityDescription, - updater: LuciUpdater, + self, + unique_id: str, + description: BinarySensorEntityDescription, + updater: LuciUpdater, ) -> None: """Initialize sensor. diff --git a/custom_components/miwifi/button.py b/custom_components/miwifi/button.py index a938237..030549e 100644 --- a/custom_components/miwifi/button.py +++ b/custom_components/miwifi/button.py @@ -45,9 +45,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi button entry. @@ -64,7 +64,7 @@ async def async_setup_entry( entities: list[MiWifiButton] = [ MiWifiButton( - f"{config_entry.unique_id}-{description.key}", + f"{config_entry.entry_id}-{description.key}", description, updater, ) @@ -79,10 +79,10 @@ class MiWifiButton(ButtonEntity, CoordinatorEntity, RestoreEntity): _attr_attribution: str = ATTRIBUTION def __init__( - self, - unique_id: str, - description: ButtonEntityDescription, - updater: LuciUpdater, + self, + unique_id: str, + description: ButtonEntityDescription, + updater: LuciUpdater, ) -> None: """Initialize button. diff --git a/custom_components/miwifi/config_flow.py b/custom_components/miwifi/config_flow.py index 95c9e25..4878ac9 100644 --- a/custom_components/miwifi/config_flow.py +++ b/custom_components/miwifi/config_flow.py @@ -43,7 +43,7 @@ class MiWifiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @staticmethod @callback def async_get_options_flow( - config_entry: config_entries.ConfigEntry, + config_entry: config_entries.ConfigEntry, ) -> MiWifiOptionsFlow: """Get the options flow for this handler. @@ -89,7 +89,7 @@ async def _async_discovery_handoff(self) -> FlowResult: return self.async_abort(reason="discovery_started") async def async_step_integration_discovery( - self, discovery_info: DiscoveryInfoType + self, discovery_info: DiscoveryInfoType ) -> FlowResult: """Handle discovery via integration. @@ -105,7 +105,7 @@ async def async_step_integration_discovery( return await self.async_step_discovery_confirm() async def async_step_user( - self, user_input: ConfigType | None = None, errors: dict[str, str] | None = None + self, user_input: ConfigType | None = None, errors: dict[str, str] | None = None ) -> FlowResult: """Handle a flow initialized by the user. @@ -132,7 +132,7 @@ async def async_step_user( ) async def async_step_discovery_confirm( - self, user_input: ConfigType | None = None + self, user_input: ConfigType | None = None ) -> FlowResult: """Handle a flow initialized by discovery. @@ -268,10 +268,10 @@ def _get_options_schema(self) -> vol.Schema: } if ( - DOMAIN not in self.hass.data - or self._config_entry.entry_id not in self.hass.data[DOMAIN] - or UPDATER not in self.hass.data[DOMAIN][self._config_entry.entry_id] - or self.hass.data[DOMAIN][self._config_entry.entry_id][UPDATER].is_repeater + DOMAIN not in self.hass.data + or self._config_entry.entry_id not in self.hass.data[DOMAIN] + or UPDATER not in self.hass.data[DOMAIN][self._config_entry.entry_id] + or self.hass.data[DOMAIN][self._config_entry.entry_id][UPDATER].is_repeater ): schema |= { vol.Optional( diff --git a/custom_components/miwifi/device_tracker.py b/custom_components/miwifi/device_tracker.py index 7c8c617..aa87b2c 100644 --- a/custom_components/miwifi/device_tracker.py +++ b/custom_components/miwifi/device_tracker.py @@ -59,9 +59,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi device tracker entry. @@ -108,10 +108,10 @@ class MiWifiDeviceTracker(ScannerEntity, CoordinatorEntity): _device: dict def __init__( - self, - unique_id: str, - device: dict, - updater: LuciUpdater, + self, + unique_id: str, + device: dict, + updater: LuciUpdater, ) -> None: """Initialize device_tracker. @@ -150,7 +150,7 @@ def mac_address(self) -> str | None: return self._device.get(ATTR_TRACKER_MAC, None) - @cached_property + @property def manufacturer(self) -> str | None: """Return manufacturer of the device. @@ -325,9 +325,9 @@ def _handle_coordinator_update(self) -> None: break if ( - self._attr_available == is_available - and self._is_connected == is_connected - and not is_update + self._attr_available == is_available + and self._is_connected == is_connected + and not is_update ): return diff --git a/custom_components/miwifi/discovery.py b/custom_components/miwifi/discovery.py index 79982e5..e3d7ec5 100644 --- a/custom_components/miwifi/discovery.py +++ b/custom_components/miwifi/discovery.py @@ -81,8 +81,8 @@ async def async_discover_devices(client: AsyncClient) -> list: @callback def async_trigger_discovery( - hass: HomeAssistant, - discovered_devices: list, + hass: HomeAssistant, + discovered_devices: list, ) -> None: """Trigger config flows for discovered devices. @@ -109,7 +109,7 @@ def parse_leafs(devices: list, leafs: list) -> list: """ for leaf in leafs: - if "ip" not in leaf: + if "ip" not in leaf or len(leaf["ip"]) == 0: continue devices.append(leaf["ip"]) diff --git a/custom_components/miwifi/helper.py b/custom_components/miwifi/helper.py index 380d81a..a65b654 100644 --- a/custom_components/miwifi/helper.py +++ b/custom_components/miwifi/helper.py @@ -19,7 +19,7 @@ def get_config_value( - config_entry: config_entries.ConfigEntry | None, param: str, default=None + config_entry: config_entries.ConfigEntry | None, param: str, default=None ) -> Any: """Get current value for configuration parameter. diff --git a/custom_components/miwifi/light.py b/custom_components/miwifi/light.py index 69574f8..019c620 100644 --- a/custom_components/miwifi/light.py +++ b/custom_components/miwifi/light.py @@ -52,9 +52,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi light entry. @@ -71,7 +71,7 @@ async def async_setup_entry( entities: list[MiWifiLight] = [ MiWifiLight( - f"{config_entry.unique_id}-{description.key}", + f"{config_entry.entry_id}-{description.key}", description, updater, ) @@ -86,10 +86,10 @@ class MiWifiLight(LightEntity, CoordinatorEntity, RestoreEntity): _attr_attribution: str = ATTRIBUTION def __init__( - self, - unique_id: str, - description: LightEntityDescription, - updater: LuciUpdater, + self, + unique_id: str, + description: LightEntityDescription, + updater: LuciUpdater, ) -> None: """Initialize light. diff --git a/custom_components/miwifi/luci.py b/custom_components/miwifi/luci.py index 42b7fdf..d548a24 100644 --- a/custom_components/miwifi/luci.py +++ b/custom_components/miwifi/luci.py @@ -37,11 +37,11 @@ class LuciClient(object): _url: str def __init__( - self, - client: AsyncClient, - ip: str = CLIENT_ADDRESS, - password: str | None = None, - timeout: int = DEFAULT_TIMEOUT, + self, + client: AsyncClient, + ip: str = CLIENT_ADDRESS, + password: str | None = None, + timeout: int = DEFAULT_TIMEOUT, ) -> None: """Initialize API client. @@ -279,7 +279,7 @@ def get_mac_address() -> str: as_hex: str = f"{uuid.getnode():012x}" - return ":".join(as_hex[i: i + 2] for i in range(0, 12, 2)) + return ":".join(as_hex[i : i + 2] for i in range(0, 12, 2)) def generate_nonce(self) -> str: """Generate fake nonce. diff --git a/custom_components/miwifi/manifest.json b/custom_components/miwifi/manifest.json index 523bb0f..11a2d68 100644 --- a/custom_components/miwifi/manifest.json +++ b/custom_components/miwifi/manifest.json @@ -1,7 +1,7 @@ { "domain": "miwifi", "name": "MiWiFi", - "version": "2.0.0", + "version": "2.0.1", "documentation": "https://github.com/dmamontov/hass-miwifi", "issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues", "config_flow": true, diff --git a/custom_components/miwifi/sensor.py b/custom_components/miwifi/sensor.py index 3bcfa65..137e8b2 100644 --- a/custom_components/miwifi/sensor.py +++ b/custom_components/miwifi/sensor.py @@ -120,14 +120,6 @@ state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, ), - SensorEntityDescription( - key=ATTR_SENSOR_DEVICES_GUEST, - name=ATTR_SENSOR_DEVICES_GUEST_NAME, - icon="mdi:counter", - native_unit_of_measurement=PCS, - state_class=SensorStateClass.MEASUREMENT, - entity_registry_enabled_default=False, - ), SensorEntityDescription( key=ATTR_SENSOR_DEVICES_2_4, name=ATTR_SENSOR_DEVICES_2_4_NAME, @@ -158,9 +150,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi sensor entry. @@ -177,13 +169,13 @@ async def async_setup_entry( entities: list[MiWifiSensor] = [ MiWifiSensor( - f"{config_entry.unique_id}-{description.key}", + f"{config_entry.entry_id}-{description.key}", description, updater, ) for description in MIWIFI_SENSORS if description.key != ATTR_SENSOR_DEVICES_5_0_GAME - or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3 + or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3 ] async_add_entities(entities) @@ -194,10 +186,10 @@ class MiWifiSensor(SensorEntity, CoordinatorEntity, RestoreEntity): _attr_attribution: str = ATTRIBUTION def __init__( - self, - unique_id: str, - description: SensorEntityDescription, - updater: LuciUpdater, + self, + unique_id: str, + description: SensorEntityDescription, + updater: LuciUpdater, ) -> None: """Initialize sensor. diff --git a/custom_components/miwifi/switch.py b/custom_components/miwifi/switch.py index 7753ba9..f7438ea 100644 --- a/custom_components/miwifi/switch.py +++ b/custom_components/miwifi/switch.py @@ -77,9 +77,9 @@ async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, ) -> None: """Set up MiWifi switch entry. @@ -96,13 +96,13 @@ async def async_setup_entry( entities: list[MiWifiSwitch] = [ MiWifiSwitch( - f"{config_entry.unique_id}-{description.key}", + f"{config_entry.entry_id}-{description.key}", description, updater, ) for description in MIWIFI_SWITCHES if description.key != ATTR_SWITCH_WIFI_5_0_GAME - or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3 + or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3 ] async_add_entities(entities) @@ -113,10 +113,10 @@ class MiWifiSwitch(SwitchEntity, CoordinatorEntity, RestoreEntity): _attr_attribution: str = ATTRIBUTION def __init__( - self, - unique_id: str, - description: SwitchEntityDescription, - updater: LuciUpdater, + self, + unique_id: str, + description: SwitchEntityDescription, + updater: LuciUpdater, ) -> None: """Initialize switch. diff --git a/custom_components/miwifi/updater.py b/custom_components/miwifi/updater.py index 1f1fd12..13a5721 100644 --- a/custom_components/miwifi/updater.py +++ b/custom_components/miwifi/updater.py @@ -85,6 +85,7 @@ "wifi", "devices", "device_list", + "device_restore", "new_status", ] @@ -108,21 +109,22 @@ class LuciUpdater(DataUpdateCoordinator): _activity_days: int _is_only_login: bool = False _is_reauthorization: bool = True + _is_first_update: bool = True _signals: dict[str, int] = {} _moved_devices: list = [] def __init__( - self, - hass: HomeAssistant, - ip: str, - password: str, - scan_interval: int = DEFAULT_SCAN_INTERVAL, - timeout: int = DEFAULT_TIMEOUT, - is_force_load: bool = False, - activity_days: int = DEFAULT_ACTIVITY_DAYS, - store: Store | None = None, - is_only_login: bool = False, + self, + hass: HomeAssistant, + ip: str, + password: str, + scan_interval: int = DEFAULT_SCAN_INTERVAL, + timeout: int = DEFAULT_TIMEOUT, + is_force_load: bool = False, + activity_days: int = DEFAULT_ACTIVITY_DAYS, + store: Store | None = None, + is_only_login: bool = False, ) -> None: """Initialize updater. @@ -166,8 +168,6 @@ def __init__( lambda: hass.async_create_task(self._async_load_manufacturers()), ) - hass.async_create_task(self._async_load_devices()) - async def async_stop(self) -> None: """Stop updater""" @@ -209,6 +209,8 @@ async def update(self, is_force: bool = False, retry: int = 1) -> dict: if not self._is_only_login or is_force: for method in PREPARE_METHODS: await self._async_prepare(method, self.data) + + self._is_first_update = False except LuciConnectionException as e: err = e @@ -248,6 +250,21 @@ 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. @@ -304,6 +321,9 @@ async def _async_prepare_init(self, data: dict) -> None: :param data: dict """ + if not self._is_first_update: + return + response: dict = await self.luci.init_info() if "model" in response: @@ -331,9 +351,9 @@ async def _async_prepare_status(self, data: dict) -> None: response: dict = await self.luci.status() if ( - "hardware" in response - and isinstance(response["hardware"], dict) - and "mac" in response["hardware"] + "hardware" in response + and isinstance(response["hardware"], dict) + and "mac" in response["hardware"] ): data[ATTR_DEVICE_MAC_ADDRESS] = response["hardware"]["mac"] @@ -379,9 +399,9 @@ async def _async_prepare_wan(self, data: dict) -> None: response: dict = await self.luci.wan_info() if ( - "info" in response - and isinstance(response["info"], dict) - and "uptime" in response["info"] + "info" in response + and isinstance(response["info"], dict) + and "uptime" in response["info"] ): data[ATTR_BINARY_SENSOR_WAN_STATE] = response["info"]["uptime"] > 0 else: @@ -451,9 +471,10 @@ async def _async_prepare_devices(self, data: dict) -> None: ) if self.is_repeater and self.is_force_load: - device[ATTR_TRACKER_ENTRY_ID] = device[ - ATTR_TRACKER_UPDATER_ENTRY_ID - ] = integrations[self.ip][ATTR_TRACKER_ENTRY_ID] + device |= { + ATTR_TRACKER_ENTRY_ID: self.entry_id, + ATTR_TRACKER_UPDATER_ENTRY_ID: self.entry_id, + } action: DeviceAction = DeviceAction.ADD if self._mass_update_device(device, integrations): @@ -492,11 +513,11 @@ async def _async_prepare_device_list(self, data: dict) -> None: action: DeviceAction = DeviceAction.ADD if ( - "parent" in device - and len(device["parent"]) > 0 - and device["parent"] in mac_to_ip - and mac_to_ip[device["parent"]] in integrations - and mac_to_ip[device["parent"]] != self.ip + "parent" in device + and len(device["parent"]) > 0 + and device["parent"] in mac_to_ip + and mac_to_ip[device["parent"]] in integrations + and mac_to_ip[device["parent"]] != self.ip ): integration: dict = integrations[mac_to_ip[device["parent"]]] @@ -512,13 +533,14 @@ async def _async_prepare_device_list(self, data: dict) -> None: if ATTR_DEVICE_MAC_ADDRESS in integration[UPDATER].data: if mac_to_ip[device["parent"]] not in add_to: - add_to[mac_to_ip[device["parent"]]] = [] + add_to[mac_to_ip[device["parent"]]] = {} - add_to[mac_to_ip[device["parent"]]].append((device, action)) + add_to[mac_to_ip[device["parent"]]][device[ATTR_TRACKER_MAC]] = ( + device, + action, + ) else: - device[ATTR_TRACKER_ENTRY_ID] = integrations[self.ip][ - ATTR_TRACKER_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): @@ -536,19 +558,70 @@ async def _async_prepare_device_list(self, data: dict) -> None: if len(add_to) == 0: return + await asyncio.sleep(DEFAULT_CALL_DELAY) + for ip, devices in add_to.items(): if ip not in integrations: continue integrations[ip][UPDATER].reset_counter(True) - for device in devices: + for device in devices.values(): integrations[ip][UPDATER].add_device(device[0], True, device[1]) + async def _async_prepare_device_restore(self, data: dict) -> None: + """Restore devices + + :param data: dict + """ + + if not self._is_first_update: + return + + devices: dict | None = await self._async_load_devices() + + if devices is None: + return + + integrations: dict = self.get_integrations() + + for mac, device in devices.items(): + if mac in self.devices: + continue + + if device[ATTR_TRACKER_ENTRY_ID] != self.entry_id: + for integration in integrations.values(): + if ( + not integration[UPDATER].is_force_load + and integration[ATTR_TRACKER_ENTRY_ID] + == device[ATTR_TRACKER_ENTRY_ID] + and mac not in integration[UPDATER].devices + ): + device[ATTR_TRACKER_ROUTER_MAC_ADDRESS] = integration[ + UPDATER + ].data.get( + ATTR_DEVICE_MAC_ADDRESS, + device[ATTR_TRACKER_ROUTER_MAC_ADDRESS], + ) + + integration[UPDATER].devices[mac] = device + + self._moved_devices.append(mac) + + break + + self.devices[mac] = device + + async_dispatcher_send(self.hass, SIGNAL_NEW_DEVICE, device) + + _LOGGER.debug("Restore device: %s, %s", mac, device) + + self._clean_devices() + def add_device( - self, - device: dict, - is_from_parent: bool = False, - action: DeviceAction = DeviceAction.ADD, + self, + device: dict, + is_from_parent: bool = False, + action: DeviceAction = DeviceAction.ADD, ) -> None: """Prepare device. @@ -563,6 +636,10 @@ def add_device( is_new: bool = device[ATTR_TRACKER_MAC] not in self.devices ip_attr: dict | None = device["ip"][0] if "ip" in device else None + + if self.is_force_load and "wifiIndex" in device: + device["type"] = 6 if device["wifiIndex"] == 3 else device["wifiIndex"] + connection: Connection | None = ( Connection(int(device["type"])) if "type" in device else None ) @@ -586,20 +663,20 @@ def add_device( ATTR_TRACKER_CONNECTION: connection, ATTR_TRACKER_DOWN_SPEED: float(ip_attr["downspeed"]) if ip_attr is not None - and "downspeed" in ip_attr - and float(ip_attr["downspeed"]) > 0 + and "downspeed" in ip_attr + and float(ip_attr["downspeed"]) > 0 else 0.0, ATTR_TRACKER_UP_SPEED: float(ip_attr["upspeed"]) if ip_attr is not None - and "upspeed" in ip_attr - and float(ip_attr["upspeed"]) > 0 + and "upspeed" in ip_attr + and float(ip_attr["upspeed"]) > 0 else 0.0, ATTR_TRACKER_ONLINE: str( timedelta(seconds=int(ip_attr["online"] if ip_attr is not None else 0)) ), ATTR_TRACKER_LAST_ACTIVITY: datetime.now() - .replace(microsecond=0) - .isoformat(), + .replace(microsecond=0) + .isoformat(), } if not is_from_parent and action == DeviceAction.MOVE: @@ -608,9 +685,9 @@ def add_device( action = DeviceAction.ADD if ( - is_new - and action == DeviceAction.ADD - and self.new_device_callback is not None + is_new + and action == DeviceAction.ADD + and self.new_device_callback is not None ): async_dispatcher_send( self.hass, SIGNAL_NEW_DEVICE, self.devices[device[ATTR_TRACKER_MAC]] @@ -639,7 +716,7 @@ def add_device( self.data[code] += 1 def _mass_update_device( - self, device: dict, integrations: dict | None = None + self, device: dict, integrations: dict | None = None ) -> bool: """Mass update devices @@ -693,6 +770,13 @@ def _clean_devices(self) -> None: devices: dict = self.devices for mac, device in devices.items(): + if ATTR_TRACKER_LAST_ACTIVITY not in device: + self.devices[mac][ATTR_TRACKER_LAST_ACTIVITY] = ( + datetime.now().replace(microsecond=0).isoformat(), + ) + + continue + delta = now - datetime.strptime( device[ATTR_TRACKER_LAST_ACTIVITY], "%Y-%m-%dT%H:%M:%S" ) @@ -702,9 +786,9 @@ def _clean_devices(self) -> None: for ip, integration in integrations.items(): if ( - ip != self.ip - and not integration[UPDATER].is_force_load - and mac in integration[UPDATER].devices + ip != self.ip + and not integration[UPDATER].is_force_load + and mac in integration[UPDATER].devices ): del integration[UPDATER].devices[mac] @@ -741,24 +825,18 @@ def reset_counter(self, is_force: bool = False) -> None: self.data[ATTR_SENSOR_DEVICES_5_0] = 0 self.data[ATTR_SENSOR_DEVICES_5_0_GAME] = 0 - async def _async_load_devices(self) -> None: + async def _async_load_devices(self) -> dict | None: """Async load devices from Store""" if self._store is None: - return + return None devices: dict | None = await self._store.async_load() if devices is None or not isinstance(devices, dict) or len(devices) == 0: - return - - for mac, data in devices.items(): - if mac in self.devices: - continue - - self.devices[mac] = data + return None - self._clean_devices() + return devices async def _async_save_devices(self) -> None: """Async save devices to Store""" @@ -773,7 +851,7 @@ async def _async_load_manufacturers(self) -> None: self._manufacturers = await self.hass.async_add_executor_job( json.load_json, - f"{os.path.dirname(os.path.abspath(__file__))}/_manufacturers.json", + f"{os.path.dirname(os.path.abspath(__file__))}/manufacturers.json", ) def manufacturer(self, mac: str | None) -> str | None: