Adjust config entry state check in unifi (#138906)

* Adjust config entry state check in unifi

* Apply suggestions from code review

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>

* Format code

---------

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
This commit is contained in:
Erik Montnemery 2025-02-22 13:06:54 +01:00 committed by GitHub
parent 3160b7baa0
commit 037bdb6996
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,6 @@ from typing import Any
from aiounifi.models.client import ClientReconnectRequest, ClientRemoveRequest
import voluptuous as vol
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import device_registry as dr
@ -67,9 +66,9 @@ async def async_reconnect_client(hass: HomeAssistant, data: Mapping[str, Any]) -
if mac == "":
return
for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
if config_entry.state is not ConfigEntryState.LOADED or (
((hub := config_entry.runtime_data) and not hub.available)
for config_entry in hass.config_entries.async_loaded_entries(UNIFI_DOMAIN):
if (
(not (hub := config_entry.runtime_data).available)
or (client := hub.api.clients.get(mac)) is None
or client.is_wired
):
@ -85,10 +84,8 @@ async def async_remove_clients(hass: HomeAssistant, data: Mapping[str, Any]) ->
- Total time between first seen and last seen is less than 15 minutes.
- Neither IP, hostname nor name is configured.
"""
for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
if config_entry.state is not ConfigEntryState.LOADED or (
(hub := config_entry.runtime_data) and not hub.available
):
for config_entry in hass.config_entries.async_loaded_entries(UNIFI_DOMAIN):
if not (hub := config_entry.runtime_data).available:
continue
clients_to_remove = []