2020-12-02 21:28:17 +00:00
|
|
|
"""Config flow for Kuler Sky."""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import pykulersky
|
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.helpers import config_entry_flow
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
async def _async_has_devices(hass) -> bool:
|
|
|
|
"""Return if there are devices that can be discovered."""
|
|
|
|
# Check if there are any devices that can be discovered in the network.
|
|
|
|
try:
|
2021-03-05 20:24:55 +00:00
|
|
|
devices = await pykulersky.discover()
|
2020-12-02 21:28:17 +00:00
|
|
|
except pykulersky.PykulerskyException as exc:
|
|
|
|
_LOGGER.error("Unable to discover nearby Kuler Sky devices: %s", exc)
|
|
|
|
return False
|
|
|
|
return len(devices) > 0
|
|
|
|
|
|
|
|
|
|
|
|
config_entry_flow.register_discovery_flow(
|
2020-12-03 17:08:16 +00:00
|
|
|
DOMAIN, "Kuler Sky", _async_has_devices, config_entries.CONN_CLASS_LOCAL_POLL
|
2020-12-02 21:28:17 +00:00
|
|
|
)
|