UniFi - Update device registry after device has been upgraded (#35430)
* Update device registry if received event saying device has been updated * Make sure event was the last updated
This commit is contained in:
1 parent
4395fe9298
commit
c71b6c8a71
2 files changed
+49
No files matched your search
@@ -4,6 +4,9 @@ import logging
|
||||
|
||||
from aiounifi.api import SOURCE_DATA, SOURCE_EVENT
|
||||
from aiounifi.events import (
|
||||
ACCESS_POINT_UPGRADED,
|
||||
GATEWAY_UPGRADED,
|
||||
SWITCH_UPGRADED,
|
||||
WIRED_CLIENT_CONNECTED,
|
||||
WIRELESS_CLIENT_CONNECTED,
|
||||
WIRELESS_CLIENT_ROAM,
|
||||
@@ -50,6 +53,8 @@ CLIENT_STATIC_ATTRIBUTES = [
|
||||
"oui",
|
||||
]
|
||||
|
||||
DEVICE_UPGRADED = (ACCESS_POINT_UPGRADED, GATEWAY_UPGRADED, SWITCH_UPGRADED)
|
||||
|
||||
WIRED_CONNECTION = (WIRED_CLIENT_CONNECTED,)
|
||||
WIRELESS_CONNECTION = (
|
||||
WIRELESS_CLIENT_CONNECTED,
|
||||
@@ -299,6 +304,13 @@ class UniFiDeviceTracker(UniFiBase, ScannerEntity):
|
||||
dt_util.utcnow() + timedelta(seconds=self.device.next_interval + 10),
|
||||
)
|
||||
|
||||
elif (
|
||||
self.device.last_updated == SOURCE_EVENT
|
||||
and self.device.event.event in DEVICE_UPGRADED
|
||||
):
|
||||
self.hass.async_create_task(self.async_update_device_registry())
|
||||
return
|
||||
|
||||
super().async_update_callback()
|
||||
|
||||
@property
|
||||
@@ -341,6 +353,14 @@ class UniFiDeviceTracker(UniFiBase, ScannerEntity):
|
||||
|
||||
return info
|
||||
|
||||
async def async_update_device_registry(self) -> None:
|
||||
"""Update device registry."""
|
||||
device_registry = await self.hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=self.controller.config_entry.entry_id, **self.device_info
|
||||
)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
|
||||
Reference in new issue
Block a user