Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2 bugs with Unknown Devices Sensor #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions custom_components/edgeos/data_processors/device_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def _process_api_data(self):
system_section = self._api_data.get(API_DATA_SYSTEM, {})
service = system_section.get(DATA_SYSTEM_SERVICE, {})

if len(self._devices.keys()) != 0:
for existing_device in self._devices:
self._devices.get(existing_device).is_leased = False

dhcp_server = service.get(DATA_SYSTEM_SERVICE_DHCP_SERVER, {})
shared_network_names = dhcp_server.get(DHCP_SERVER_SHARED_NETWORK_NAME, {})

Expand Down Expand Up @@ -148,6 +152,12 @@ def _update_leased_devices(self):
data_leases = self._api_data.get(API_DATA_DHCP_LEASES, {})
data_server_leases = data_leases.get(DHCP_SERVER_LEASES, {})

if len(self._devices.keys()) != 0:
for existing_device in self._devices:
existing_device_data = self._devices.get(existing_device)
existing_device_data.is_leased = False
self._devices[existing_device_data.unique_id] = existing_device_data

for subnet in data_server_leases:
subnet_data = data_server_leases.get(subnet, {})

Expand Down Expand Up @@ -202,6 +212,7 @@ def _set_device(

else:
device_data = existing_device_data
existing_device_data.is_leased = True

self._devices[device_data.unique_id] = device_data
self._devices_ip_mapping[device_data.ip] = device_data.unique_id
Expand Down
16 changes: 10 additions & 6 deletions custom_components/edgeos/managers/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ATTR_HOSTNAME,
ATTR_IS_ON,
ATTR_LAST_ACTIVITY,
DHCP_SERVER_LEASED,
DOMAIN,
ENTITY_CONFIG_ENTRY_ID,
HA_NAME,
Expand Down Expand Up @@ -65,11 +66,14 @@ class Coordinator(DataUpdateCoordinator):
_websockets: WebSockets | None
_processors: dict[DeviceTypes, BaseProcessor] | None = None

_data_mapping: dict[
str,
Callable[[IntegrationEntityDescription], dict | None]
| Callable[[IntegrationEntityDescription, str], dict | None],
] | None
_data_mapping: (
dict[
str,
Callable[[IntegrationEntityDescription], dict | None]
| Callable[[IntegrationEntityDescription, str], dict | None],
]
| None
)
_system_status_details: dict | None

_last_update: float
Expand Down Expand Up @@ -529,7 +533,7 @@ def _get_unknown_devices_data(self, _entity_description) -> dict | None:

result = {
ATTR_STATE: len(leased_devices.keys()),
ATTR_ATTRIBUTES: leased_devices,
ATTR_ATTRIBUTES: { DHCP_SERVER_LEASED: leased_devices },
}

return result
Expand Down