Fix stuck clients in UniFi options (#105028)

This commit is contained in:
Robert Svensson 2023-12-05 09:42:43 +01:00 committed by Franck Nijhof
parent 65c8aa3249
commit 2f727d5fe1
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3

View File

@ -8,6 +8,7 @@ Configuration of options through options flow.
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
import operator
import socket import socket
from types import MappingProxyType from types import MappingProxyType
from typing import Any from typing import Any
@ -309,6 +310,11 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
client.mac: f"{client.name or client.hostname} ({client.mac})" client.mac: f"{client.name or client.hostname} ({client.mac})"
for client in self.controller.api.clients.values() for client in self.controller.api.clients.values()
} }
clients |= {
mac: f"Unknown ({mac})"
for mac in self.options.get(CONF_CLIENT_SOURCE, [])
if mac not in clients
}
return self.async_show_form( return self.async_show_form(
step_id="configure_entity_sources", step_id="configure_entity_sources",
@ -317,7 +323,9 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
vol.Optional( vol.Optional(
CONF_CLIENT_SOURCE, CONF_CLIENT_SOURCE,
default=self.options.get(CONF_CLIENT_SOURCE, []), default=self.options.get(CONF_CLIENT_SOURCE, []),
): cv.multi_select(clients), ): cv.multi_select(
dict(sorted(clients.items(), key=operator.itemgetter(1)))
),
} }
), ),
last_step=False, last_step=False,