Fix 2 bugs with Unknown Devices Sensor #156
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 CONSTDHCP_SERVER_LEASED
) .