Drop base ATTR constants in zeroconf (#60561)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/60720/head
parent
2ec49d4ffd
commit
cbab0ba9c0
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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"],
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue