mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
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
@ -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
|
# homekit_python has code to do this, but not in a form we can
|
||||||
# easily use, so do the bare minimum ourselves here instead.
|
# easily use, so do the bare minimum ourselves here instead.
|
||||||
properties = {
|
properties = {
|
||||||
key.lower(): value
|
key.lower(): value for (key, value) in discovery_info.properties.items()
|
||||||
for (key, value) in discovery_info[zeroconf.ATTR_PROPERTIES].items()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if zeroconf.ATTR_PROPERTIES_ID not in properties:
|
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.
|
# It changes if a device is factory reset.
|
||||||
hkid = properties[zeroconf.ATTR_PROPERTIES_ID]
|
hkid = properties[zeroconf.ATTR_PROPERTIES_ID]
|
||||||
model = properties["md"]
|
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"])
|
status_flags = int(properties["sf"])
|
||||||
paired = not status_flags & 0x01
|
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
|
# Set unique-id and error out if it's already configured
|
||||||
existing_entry = await self.async_set_unique_id(normalize_hkid(hkid))
|
existing_entry = await self.async_set_unique_id(normalize_hkid(hkid))
|
||||||
updated_ip_port = {
|
updated_ip_port = {
|
||||||
"AccessoryIP": discovery_info[zeroconf.ATTR_HOST],
|
"AccessoryIP": discovery_info.host,
|
||||||
"AccessoryPort": discovery_info[zeroconf.ATTR_PORT],
|
"AccessoryPort": discovery_info.port,
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the device is already paired and known to us we should monitor c#
|
# 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.model.services import ServicesTypes
|
||||||
from aiohomekit.testing import FakeController
|
from aiohomekit.testing import FakeController
|
||||||
|
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.homekit_controller import config_flow
|
from homeassistant.components.homekit_controller import config_flow
|
||||||
from homeassistant.components.homekit_controller.const import (
|
from homeassistant.components.homekit_controller.const import (
|
||||||
CONTROLLER,
|
CONTROLLER,
|
||||||
@ -118,17 +119,19 @@ async def device_config_changed(hass, accessories):
|
|||||||
accessories_obj.add_accessory(accessory)
|
accessories_obj.add_accessory(accessory)
|
||||||
pairing.accessories = accessories_obj
|
pairing.accessories = accessories_obj
|
||||||
|
|
||||||
discovery_info = {
|
discovery_info = zeroconf.ZeroconfServiceInfo(
|
||||||
"name": "TestDevice",
|
host="127.0.0.1",
|
||||||
"host": "127.0.0.1",
|
hostname="mock_hostname",
|
||||||
"port": 8080,
|
name="TestDevice",
|
||||||
"properties": {
|
port=8080,
|
||||||
|
properties={
|
||||||
"md": "TestDevice",
|
"md": "TestDevice",
|
||||||
"id": "00:00:00:00:00:00",
|
"id": "00:00:00:00:00:00",
|
||||||
"c#": "2",
|
"c#": "2",
|
||||||
"sf": "0",
|
"sf": "0",
|
||||||
},
|
},
|
||||||
}
|
type="mock_type",
|
||||||
|
)
|
||||||
|
|
||||||
# Config Flow will abort and notify us if the discovery event is of
|
# Config Flow will abort and notify us if the discovery event is of
|
||||||
# interest - in this case c# has incremented
|
# interest - in this case c# has incremented
|
||||||
|
Loading…
x
Reference in New Issue
Block a user