UniFi - Improve expected SSID filter behavior (#32785)
* Improve expected ssid filter behavior * Fix tests
This commit is contained in:
parent
b9ad40ed38
commit
fa63dc1e25
2 changed files with 32 additions and 10 deletions
|
@ -45,6 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
option_track_clients = controller.option_track_clients
|
||||
option_track_devices = controller.option_track_devices
|
||||
option_track_wired_clients = controller.option_track_wired_clients
|
||||
option_ssid_filter = controller.option_ssid_filter
|
||||
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
|
@ -86,6 +87,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
nonlocal option_track_clients
|
||||
nonlocal option_track_devices
|
||||
nonlocal option_track_wired_clients
|
||||
nonlocal option_ssid_filter
|
||||
|
||||
update = False
|
||||
remove = set()
|
||||
|
@ -116,6 +118,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
if isinstance(entity, UniFiClientTracker) and entity.is_wired:
|
||||
remove.add(mac)
|
||||
|
||||
if option_ssid_filter != controller.option_ssid_filter:
|
||||
option_ssid_filter = controller.option_ssid_filter
|
||||
update = True
|
||||
|
||||
for mac, entity in tracked.items():
|
||||
if (
|
||||
isinstance(entity, UniFiClientTracker)
|
||||
and not entity.is_wired
|
||||
and entity.client.essid not in option_ssid_filter
|
||||
):
|
||||
remove.add(mac)
|
||||
|
||||
option_track_clients = controller.option_track_clients
|
||||
option_track_devices = controller.option_track_devices
|
||||
option_track_wired_clients = controller.option_track_wired_clients
|
||||
|
@ -157,10 +171,18 @@ def add_entities(controller, async_add_entities, tracked):
|
|||
if item_id in tracked:
|
||||
continue
|
||||
|
||||
if tracker_class is UniFiClientTracker and (
|
||||
not controller.option_track_wired_clients and items[item_id].is_wired
|
||||
):
|
||||
continue
|
||||
if tracker_class is UniFiClientTracker:
|
||||
client = items[item_id]
|
||||
|
||||
if not controller.option_track_wired_clients and client.is_wired:
|
||||
continue
|
||||
|
||||
if (
|
||||
controller.option_ssid_filter
|
||||
and not client.is_wired
|
||||
and client.essid not in controller.option_ssid_filter
|
||||
):
|
||||
continue
|
||||
|
||||
tracked[item_id] = tracker_class(items[item_id], controller)
|
||||
new_tracked.append(tracked[item_id])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue