From f38a00740f20c4cd4c741d2d194a5565884cdd62 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Jan 2022 21:50:24 -1000 Subject: [PATCH] Unifi protect discovery cleanups (#64413) --- homeassistant/components/unifiprotect/__init__.py | 2 +- homeassistant/components/unifiprotect/config_flow.py | 2 +- homeassistant/components/unifiprotect/discovery.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/unifiprotect/__init__.py b/homeassistant/components/unifiprotect/__init__.py index 9dda52b9278..97fdc6eac20 100644 --- a/homeassistant/components/unifiprotect/__init__.py +++ b/homeassistant/components/unifiprotect/__init__.py @@ -44,7 +44,7 @@ SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the UniFi Protect config entries.""" - await async_start_discovery(hass) + async_start_discovery(hass) session = async_create_clientsession(hass, cookie_jar=CookieJar(unsafe=True)) protect = ProtectApiClient( host=entry.data[CONF_HOST], diff --git a/homeassistant/components/unifiprotect/config_flow.py b/homeassistant/components/unifiprotect/config_flow.py index 720ba9aa37f..7398d755b90 100644 --- a/homeassistant/components/unifiprotect/config_flow.py +++ b/homeassistant/components/unifiprotect/config_flow.py @@ -71,7 +71,7 @@ class ProtectFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # Discovery requires an additional check so we use # SSDP and DHCP to tell us to start it so it only # runs on networks where unifi devices are present. - await async_start_discovery(self.hass) + async_start_discovery(self.hass) return self.async_abort(reason="discovery_started") async def async_step_discovery( diff --git a/homeassistant/components/unifiprotect/discovery.py b/homeassistant/components/unifiprotect/discovery.py index 0efa6bc1fb1..4613aee954d 100644 --- a/homeassistant/components/unifiprotect/discovery.py +++ b/homeassistant/components/unifiprotect/discovery.py @@ -21,7 +21,8 @@ DISCOVERY = "discovery" DISCOVERY_INTERVAL = timedelta(minutes=60) -async def async_start_discovery(hass: HomeAssistant) -> None: +@callback +def async_start_discovery(hass: HomeAssistant) -> None: """Start discovery.""" domain_data = hass.data.setdefault(DOMAIN, {}) if DISCOVERY in domain_data: @@ -29,7 +30,7 @@ async def async_start_discovery(hass: HomeAssistant) -> None: domain_data[DISCOVERY] = True async def _async_discovery(*_: Any) -> None: - async_trigger_discovery(hass, await async_discover_devices(hass)) + async_trigger_discovery(hass, await async_discover_devices()) # Do not block startup since discovery takes 31s or more asyncio.create_task(_async_discovery()) @@ -37,7 +38,7 @@ async def async_start_discovery(hass: HomeAssistant) -> None: async_track_time_interval(hass, _async_discovery, DISCOVERY_INTERVAL) -async def async_discover_devices(hass: HomeAssistant) -> list[UnifiDevice]: +async def async_discover_devices() -> list[UnifiDevice]: """Discover devices.""" scanner = AIOUnifiScanner() devices = await scanner.async_scan()