Skip to content

Commit

Permalink
Merge pull request #50 from dmamontov/dev
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
dmamontov authored Apr 22, 2022
2 parents bd535ea + 7f9e54b commit 9041162
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
1 change: 1 addition & 0 deletions custom_components/miwifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miwifi/manifest.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
34 changes: 11 additions & 23 deletions custom_components/miwifi/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9041162

Please sign in to comment.