mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
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:
parent
3160b7baa0
commit
037bdb6996
@ -6,7 +6,6 @@ from typing import Any
|
|||||||
from aiounifi.models.client import ClientReconnectRequest, ClientRemoveRequest
|
from aiounifi.models.client import ClientReconnectRequest, ClientRemoveRequest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
|
||||||
from homeassistant.const import ATTR_DEVICE_ID
|
from homeassistant.const import ATTR_DEVICE_ID
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers import device_registry as dr
|
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 == "":
|
if mac == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
|
for config_entry in hass.config_entries.async_loaded_entries(UNIFI_DOMAIN):
|
||||||
if config_entry.state is not ConfigEntryState.LOADED or (
|
if (
|
||||||
((hub := config_entry.runtime_data) and not hub.available)
|
(not (hub := config_entry.runtime_data).available)
|
||||||
or (client := hub.api.clients.get(mac)) is None
|
or (client := hub.api.clients.get(mac)) is None
|
||||||
or client.is_wired
|
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.
|
- Total time between first seen and last seen is less than 15 minutes.
|
||||||
- Neither IP, hostname nor name is configured.
|
- Neither IP, hostname nor name is configured.
|
||||||
"""
|
"""
|
||||||
for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
|
for config_entry in hass.config_entries.async_loaded_entries(UNIFI_DOMAIN):
|
||||||
if config_entry.state is not ConfigEntryState.LOADED or (
|
if not (hub := config_entry.runtime_data).available:
|
||||||
(hub := config_entry.runtime_data) and not hub.available
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
clients_to_remove = []
|
clients_to_remove = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user