The _update_leased_devices and _set_devices logic was incorrect.
When a device first connects (or the integration is loaded), it will be added to the _devices variable as connected. For all such existing devices, the is_leased attribute does not change e.g. if it disconnects then _set_devices is not called and it remains in the list of _devices with is_leased set to True.
This corrects that logic by:
When _update_leased_devices is called, all _devices set is_leased to False.
When set_devices is called:
(a) if it is a new device it is added as normal; or
(b) if it is an existing known device (e.g. a device connects, disconnects then reconnects some time later), the existing data is used with is_leased set to true.
I considered the possibility to simply delete the entirety of _devices using for example clear() but decided against it since that might give rise to further issues.
Unknown devices leased attribute
During the refactor, the dict leased_devices was erroneously written directly to attributes instead of under the subkey leased (which corresponds to the CONST DHCP_SERVER_LEASED) .
Addresses issues #154 and #153.
Unknown Devices Logic
https://github.com/illuzn/ha-edgeos/blob/cc9678c575eea992d070038aa6cb4d0e7ec94a2a/custom_components/edgeos/data_processors/device_processor.py#L146-L208
The
_update_leased_devices
and_set_devices
logic was incorrect. When a device first connects (or the integration is loaded), it will be added to the_devices
variable as connected. For all such existing devices, theis_leased
attribute does not change e.g. if it disconnects then_set_devices
is not called and it remains in the list of_devices
withis_leased
set to True.This corrects that logic by:
_update_leased_devices
is called, all_devices
setis_leased
to False.set_devices
is called: (a) if it is a new device it is added as normal; or (b) if it is an existing known device (e.g. a device connects, disconnects then reconnects some time later), the existing data is used withis_leased
set to true.I considered the possibility to simply delete the entirety of
_devices
using for example clear() but decided against it since that might give rise to further issues.Unknown devices leased attribute
During the refactor, the dict
leased_devices
was erroneously written directly to attributes instead of under the subkey leased (which corresponds to the CONSTDHCP_SERVER_LEASED
) .