2021-08-20 11:41:36 +00:00
|
|
|
"""Config flow for Fjäråskupan integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-06-03 20:05:37 +00:00
|
|
|
from fjaraskupan import device_filter
|
2021-08-20 11:41:36 +00:00
|
|
|
|
2022-08-01 14:56:08 +00:00
|
|
|
from homeassistant.components.bluetooth import async_discovered_service_info
|
2022-02-14 17:10:50 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-08-20 11:41:36 +00:00
|
|
|
from homeassistant.helpers.config_entry_flow import register_discovery_flow
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
2022-02-14 17:10:50 +00:00
|
|
|
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
2021-08-20 11:41:36 +00:00
|
|
|
"""Return if there are devices that can be discovered."""
|
|
|
|
|
2022-08-01 14:56:08 +00:00
|
|
|
service_infos = async_discovered_service_info(hass)
|
2021-08-20 11:41:36 +00:00
|
|
|
|
2022-08-01 14:56:08 +00:00
|
|
|
for service_info in service_infos:
|
|
|
|
if device_filter(service_info.device, service_info.advertisement):
|
|
|
|
return True
|
2021-08-20 11:41:36 +00:00
|
|
|
|
2022-08-01 14:56:08 +00:00
|
|
|
return False
|
2021-08-20 11:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
register_discovery_flow(DOMAIN, "Fjäråskupan", _async_has_devices)
|