Use dataclass properties in homekit_controller discovery (#60626)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
3f22905709
commit
0d24862a28
2 changed files with 13 additions and 11 deletions
|
@ -208,8 +208,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# homekit_python has code to do this, but not in a form we can
|
||||
# easily use, so do the bare minimum ourselves here instead.
|
||||
properties = {
|
||||
key.lower(): value
|
||||
for (key, value) in discovery_info[zeroconf.ATTR_PROPERTIES].items()
|
||||
key.lower(): value for (key, value) in discovery_info.properties.items()
|
||||
}
|
||||
|
||||
if zeroconf.ATTR_PROPERTIES_ID not in properties:
|
||||
|
@ -225,7 +224,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# It changes if a device is factory reset.
|
||||
hkid = properties[zeroconf.ATTR_PROPERTIES_ID]
|
||||
model = properties["md"]
|
||||
name = discovery_info[zeroconf.ATTR_NAME].replace("._hap._tcp.local.", "")
|
||||
name = discovery_info.name.replace("._hap._tcp.local.", "")
|
||||
status_flags = int(properties["sf"])
|
||||
paired = not status_flags & 0x01
|
||||
|
||||
|
@ -243,8 +242,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# Set unique-id and error out if it's already configured
|
||||
existing_entry = await self.async_set_unique_id(normalize_hkid(hkid))
|
||||
updated_ip_port = {
|
||||
"AccessoryIP": discovery_info[zeroconf.ATTR_HOST],
|
||||
"AccessoryPort": discovery_info[zeroconf.ATTR_PORT],
|
||||
"AccessoryIP": discovery_info.host,
|
||||
"AccessoryPort": discovery_info.port,
|
||||
}
|
||||
|
||||
# If the device is already paired and known to us we should monitor c#
|
||||
|
|
|
@ -9,6 +9,7 @@ from aiohomekit.model.characteristics import CharacteristicsTypes
|
|||
from aiohomekit.model.services import ServicesTypes
|
||||
from aiohomekit.testing import FakeController
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.homekit_controller import config_flow
|
||||
from homeassistant.components.homekit_controller.const import (
|
||||
CONTROLLER,
|
||||
|
@ -118,17 +119,19 @@ async def device_config_changed(hass, accessories):
|
|||
accessories_obj.add_accessory(accessory)
|
||||
pairing.accessories = accessories_obj
|
||||
|
||||
discovery_info = {
|
||||
"name": "TestDevice",
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
"properties": {
|
||||
discovery_info = zeroconf.ZeroconfServiceInfo(
|
||||
host="127.0.0.1",
|
||||
hostname="mock_hostname",
|
||||
name="TestDevice",
|
||||
port=8080,
|
||||
properties={
|
||||
"md": "TestDevice",
|
||||
"id": "00:00:00:00:00:00",
|
||||
"c#": "2",
|
||||
"sf": "0",
|
||||
},
|
||||
}
|
||||
type="mock_type",
|
||||
)
|
||||
|
||||
# Config Flow will abort and notify us if the discovery event is of
|
||||
# interest - in this case c# has incremented
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue