diff --git a/homeassistant/components/lutron_caseta/config_flow.py b/homeassistant/components/lutron_caseta/config_flow.py index dac0d6c5f94..d75fc77c66e 100644 --- a/homeassistant/components/lutron_caseta/config_flow.py +++ b/homeassistant/components/lutron_caseta/config_flow.py @@ -67,14 +67,14 @@ class LutronCasetaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by zeroconf discovery.""" - hostname = discovery_info[zeroconf.ATTR_HOSTNAME] + hostname = discovery_info.hostname if hostname is None or not hostname.startswith("lutron-"): return self.async_abort(reason="not_lutron_device") self.lutron_id = hostname.split("-")[1].replace(".local.", "") await self.async_set_unique_id(self.lutron_id) - host = discovery_info[zeroconf.ATTR_HOST] + host = discovery_info.host self._abort_if_unique_id_configured({CONF_HOST: host}) self.data[CONF_HOST] = host diff --git a/homeassistant/components/samsungtv/config_flow.py b/homeassistant/components/samsungtv/config_flow.py index 45b2789d478..ba464a17b82 100644 --- a/homeassistant/components/samsungtv/config_flow.py +++ b/homeassistant/components/samsungtv/config_flow.py @@ -302,8 +302,8 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) -> data_entry_flow.FlowResult: """Handle a flow initialized by zeroconf discovery.""" LOGGER.debug("Samsung device found via ZEROCONF: %s", discovery_info) - self._mac = format_mac(discovery_info[zeroconf.ATTR_PROPERTIES]["deviceid"]) - self._host = discovery_info[zeroconf.ATTR_HOST] + self._mac = format_mac(discovery_info.properties["deviceid"]) + self._host = discovery_info.host await self._async_start_discovery_with_mac_address() await self._async_set_device_unique_id() self.context["title_placeholders"] = {"device": self._title} diff --git a/homeassistant/components/xiaomi_miio/config_flow.py b/homeassistant/components/xiaomi_miio/config_flow.py index 4e4f1688a04..04e2b58ad0f 100644 --- a/homeassistant/components/xiaomi_miio/config_flow.py +++ b/homeassistant/components/xiaomi_miio/config_flow.py @@ -160,11 +160,11 @@ class XiaomiMiioFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" - name = discovery_info[zeroconf.ATTR_NAME] - self.host = discovery_info[zeroconf.ATTR_HOST] - self.mac = discovery_info[zeroconf.ATTR_PROPERTIES].get("mac") + name = discovery_info.name + self.host = discovery_info.host + self.mac = discovery_info.properties.get("mac") if self.mac is None: - poch = discovery_info[zeroconf.ATTR_PROPERTIES].get("poch", "") + poch = discovery_info.properties.get("poch", "") if (result := search(r"mac=\w+", poch)) is not None: self.mac = result.group(0).split("=")[1] diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index 33fe73de617..5d029b56c0b 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -75,14 +75,6 @@ MAX_PROPERTY_VALUE_LEN = 230 # Dns label max length MAX_NAME_LEN = 63 -# Attributes for ZeroconfServiceInfo -ATTR_HOST: Final = "host" -ATTR_HOSTNAME: Final = "hostname" -ATTR_NAME: Final = "name" -ATTR_PORT: Final = "port" -ATTR_PROPERTIES: Final = "properties" -ATTR_TYPE: Final = "type" - # Attributes for ZeroconfServiceInfo[ATTR_PROPERTIES] ATTR_PROPERTIES_ID: Final = "id" diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index 5026840a4e1..21a3792cd62 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -273,7 +273,7 @@ async def test_id_missing(hass, controller): discovery_info = get_device_discovery_info(device) # Remove id from device - del discovery_info[zeroconf.ATTR_PROPERTIES][zeroconf.ATTR_PROPERTIES_ID] + del discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] # Device is discovered result = await hass.config_entries.flow.async_init( @@ -289,10 +289,8 @@ async def test_discovery_ignored_model(hass, controller): """Already paired.""" device = setup_mock_accessory(controller) discovery_info = get_device_discovery_info(device) - discovery_info[zeroconf.ATTR_PROPERTIES][ - zeroconf.ATTR_PROPERTIES_ID - ] = "AA:BB:CC:DD:EE:FF" - discovery_info[zeroconf.ATTR_PROPERTIES]["md"] = "HHKBridge1,1" + discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] = "AA:BB:CC:DD:EE:FF" + discovery_info.properties["md"] = "HHKBridge1,1" # Device is discovered result = await hass.config_entries.flow.async_init( @@ -319,9 +317,7 @@ async def test_discovery_ignored_hk_bridge(hass, controller): connections={(device_registry.CONNECTION_NETWORK_MAC, formatted_mac)}, ) - discovery_info[zeroconf.ATTR_PROPERTIES][ - zeroconf.ATTR_PROPERTIES_ID - ] = "AA:BB:CC:DD:EE:FF" + discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] = "AA:BB:CC:DD:EE:FF" # Device is discovered result = await hass.config_entries.flow.async_init( @@ -348,9 +344,7 @@ async def test_discovery_does_not_ignore_non_homekit(hass, controller): connections={(device_registry.CONNECTION_NETWORK_MAC, formatted_mac)}, ) - discovery_info[zeroconf.ATTR_PROPERTIES][ - zeroconf.ATTR_PROPERTIES_ID - ] = "AA:BB:CC:DD:EE:FF" + discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] = "AA:BB:CC:DD:EE:FF" # Device is discovered result = await hass.config_entries.flow.async_init( @@ -382,7 +376,7 @@ async def test_discovery_broken_pairing_flag(hass, controller): discovery_info = get_device_discovery_info(device) # Make sure that we are pairable - assert discovery_info[zeroconf.ATTR_PROPERTIES]["sf"] != 0x0 + assert discovery_info.properties["sf"] != 0x0 # Device is discovered result = await hass.config_entries.flow.async_init( @@ -454,7 +448,7 @@ async def test_discovery_already_configured(hass, controller): discovery_info = get_device_discovery_info(device) # Set device as already paired - discovery_info[zeroconf.ATTR_PROPERTIES]["sf"] = 0x00 + discovery_info.properties["sf"] = 0x00 # Device is discovered result = await hass.config_entries.flow.async_init( @@ -490,11 +484,9 @@ async def test_discovery_already_configured_update_csharp(hass, controller): discovery_info = get_device_discovery_info(device) # Set device as already paired - discovery_info[zeroconf.ATTR_PROPERTIES]["sf"] = 0x00 - discovery_info[zeroconf.ATTR_PROPERTIES]["c#"] = 99999 - discovery_info[zeroconf.ATTR_PROPERTIES][ - zeroconf.ATTR_PROPERTIES_ID - ] = "AA:BB:CC:DD:EE:FF" + discovery_info.properties["sf"] = 0x00 + discovery_info.properties["c#"] = 99999 + discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] = "AA:BB:CC:DD:EE:FF" # Device is discovered result = await hass.config_entries.flow.async_init( diff --git a/tests/components/ipp/test_config_flow.py b/tests/components/ipp/test_config_flow.py index 1f24d9fd7cd..8eefa4251f7 100644 --- a/tests/components/ipp/test_config_flow.py +++ b/tests/components/ipp/test_config_flow.py @@ -2,7 +2,6 @@ import dataclasses from unittest.mock import patch -from homeassistant.components import zeroconf from homeassistant.components.ipp.const import CONF_BASE_PATH, CONF_UUID, DOMAIN from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST, CONF_NAME, CONF_SSL @@ -282,7 +281,7 @@ async def test_zeroconf_with_uuid_device_exists_abort( discovery_info = dataclasses.replace(MOCK_ZEROCONF_IPP_SERVICE_INFO) discovery_info.properties = { - **MOCK_ZEROCONF_IPP_SERVICE_INFO[zeroconf.ATTR_PROPERTIES], + **MOCK_ZEROCONF_IPP_SERVICE_INFO.properties, "UUID": "cfe92100-67c4-11d4-a45f-f8d027761251", } @@ -304,7 +303,7 @@ async def test_zeroconf_empty_unique_id( discovery_info = dataclasses.replace(MOCK_ZEROCONF_IPP_SERVICE_INFO) discovery_info.properties = { - **MOCK_ZEROCONF_IPP_SERVICE_INFO[zeroconf.ATTR_PROPERTIES], + **MOCK_ZEROCONF_IPP_SERVICE_INFO.properties, "UUID": "", } result = await hass.config_entries.flow.async_init( diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index d02008c6d3d..817f23d52c5 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -5,7 +5,6 @@ import pytest import voluptuous as vol from homeassistant import data_entry_flow -from homeassistant.components import zeroconf from homeassistant.components.media_player import DEVICE_CLASS_SPEAKER, DEVICE_CLASS_TV from homeassistant.components.vizio.config_flow import _get_config_schema from homeassistant.components.vizio.const import ( @@ -743,10 +742,8 @@ async def test_zeroconf_flow( # defaults which were set from discovery parameters user_input = result["data_schema"]( { - CONF_HOST: f"{discovery_info[zeroconf.ATTR_HOST]}:{discovery_info[zeroconf.ATTR_PORT]}", - CONF_NAME: discovery_info[zeroconf.ATTR_NAME][ - : -(len(discovery_info[zeroconf.ATTR_TYPE]) + 1) - ], + CONF_HOST: f"{discovery_info.host}:{discovery_info.port}", + CONF_NAME: discovery_info.name[: -(len(discovery_info.type) + 1)], CONF_DEVICE_CLASS: "speaker", } ) diff --git a/tests/components/volumio/test_config_flow.py b/tests/components/volumio/test_config_flow.py index 53eaef2ddf0..3eb254784d1 100644 --- a/tests/components/volumio/test_config_flow.py +++ b/tests/components/volumio/test_config_flow.py @@ -27,10 +27,10 @@ TEST_DISCOVERY = zeroconf.ZeroconfServiceInfo( ) TEST_DISCOVERY_RESULT = { - "host": TEST_DISCOVERY[zeroconf.ATTR_HOST], - "port": TEST_DISCOVERY[zeroconf.ATTR_PORT], - "id": TEST_DISCOVERY[zeroconf.ATTR_PROPERTIES]["UUID"], - "name": TEST_DISCOVERY[zeroconf.ATTR_PROPERTIES]["volumioName"], + "host": TEST_DISCOVERY.host, + "port": TEST_DISCOVERY.port, + "id": TEST_DISCOVERY.properties["UUID"], + "name": TEST_DISCOVERY.properties["volumioName"], }