1 """Config flow for SONOS."""
3 from collections.abc
import Awaitable
11 from .const
import DATA_SONOS_DISCOVERY_MANAGER, DOMAIN, UPNP_ST
12 from .helpers
import hostname_to_uid
16 """Return if Sonos devices have been seen recently with SSDP."""
17 return bool(await ssdp.async_get_discovery_info_by_st(hass, UPNP_ST))
21 """Sonos discovery flow that callsback zeroconf updates."""
24 """Init discovery flow."""
25 super().
__init__(DOMAIN,
"Sonos", _async_has_devices)
28 self, discovery_info: zeroconf.ZeroconfServiceInfo
29 ) -> ConfigFlowResult:
30 """Handle a flow initialized by zeroconf."""
31 hostname = discovery_info.hostname
32 if hostname
is None or not hostname.lower().startswith(
"sonos"):
33 return self.async_abort(reason=
"not_sonos_device")
34 await self.async_set_unique_id(self._domain, raise_on_progress=
False)
35 host = discovery_info.host
36 mdns_name = discovery_info.name
37 properties = discovery_info.properties
38 boot_seqnum = properties.get(
"bootseq")
39 model = properties.get(
"model")
41 if discovery_manager := self.hass.data.get(DATA_SONOS_DISCOVERY_MANAGER):
42 discovery_manager.async_discovered_player(
43 "Zeroconf", properties, host, uid, boot_seqnum, model, mdns_name
45 return await self.async_step_discovery(dataclasses.asdict(discovery_info))
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
bool _async_has_devices(HomeAssistant hass)
str hostname_to_uid(str hostname)