Unifi protect discovery cleanups (#64413)

pull/64417/head
J. Nick Koston 2022-01-18 21:50:24 -10:00 committed by GitHub
parent 4f5859c612
commit f38a00740f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -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],

View File

@ -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(

View File

@ -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()