diff --git a/homeassistant/components/sonos/config_flow.py b/homeassistant/components/sonos/config_flow.py index 59788d17a92..e6d2bb337b8 100644 --- a/homeassistant/components/sonos/config_flow.py +++ b/homeassistant/components/sonos/config_flow.py @@ -1,5 +1,5 @@ """Config flow for SONOS.""" -from typing import cast +import dataclasses import soco @@ -30,13 +30,13 @@ class SonosDiscoveryFlowHandler(DiscoveryFlowHandler): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by zeroconf.""" - hostname = discovery_info[zeroconf.ATTR_HOSTNAME] + hostname = discovery_info.hostname if hostname is None or not hostname.lower().startswith("sonos"): return self.async_abort(reason="not_sonos_device") await self.async_set_unique_id(self._domain, raise_on_progress=False) - host = discovery_info[zeroconf.ATTR_HOST] - mdns_name = discovery_info[zeroconf.ATTR_NAME] - properties = discovery_info[zeroconf.ATTR_PROPERTIES] + host = discovery_info.host + mdns_name = discovery_info.name + properties = discovery_info.properties boot_seqnum = properties.get("bootseq") model = properties.get("model") uid = hostname_to_uid(hostname) @@ -44,7 +44,7 @@ class SonosDiscoveryFlowHandler(DiscoveryFlowHandler): discovery_manager.async_discovered_player( "Zeroconf", properties, host, uid, boot_seqnum, model, mdns_name ) - return await self.async_step_discovery(cast(dict, discovery_info)) + return await self.async_step_discovery(dataclasses.asdict(discovery_info)) config_entries.HANDLERS.register(DOMAIN)(SonosDiscoveryFlowHandler)