mirror of https://github.com/home-assistant/core
Update homekit_controller to use the new typed discovery data (#66462)
This commit is contained in:
parent
d40a830b89
commit
40c6832cc1
|
@ -36,8 +36,6 @@ HOMEKIT_IGNORE = [
|
|||
|
||||
PAIRING_FILE = "pairing.json"
|
||||
|
||||
MDNS_SUFFIX = "._hap._tcp.local."
|
||||
|
||||
PIN_FORMAT = re.compile(r"^(\d{3})-{0,1}(\d{2})-{0,1}(\d{3})$")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -113,9 +111,10 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
if user_input is not None:
|
||||
key = user_input["device"]
|
||||
self.hkid = self.devices[key].device_id
|
||||
self.model = self.devices[key].info["md"]
|
||||
self.name = key[: -len(MDNS_SUFFIX)] if key.endswith(MDNS_SUFFIX) else key
|
||||
self.hkid = self.devices[key].description.id
|
||||
self.model = self.devices[key].description.model
|
||||
self.name = self.devices[key].description.name
|
||||
|
||||
await self.async_set_unique_id(
|
||||
normalize_hkid(self.hkid), raise_on_progress=False
|
||||
)
|
||||
|
@ -127,12 +126,10 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
self.devices = {}
|
||||
|
||||
async for host in self.controller.async_discover():
|
||||
status_flags = int(host.info["sf"])
|
||||
paired = not status_flags & 0x01
|
||||
if paired:
|
||||
async for discovery in self.controller.async_discover():
|
||||
if discovery.paired:
|
||||
continue
|
||||
self.devices[host.info["name"]] = host
|
||||
self.devices[discovery.description.name] = discovery
|
||||
|
||||
if not self.devices:
|
||||
return self.async_abort(reason="no_devices")
|
||||
|
@ -158,9 +155,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
except aiohomekit.AccessoryNotFoundError:
|
||||
return self.async_abort(reason="accessory_not_found_error")
|
||||
|
||||
self.name = device.info["name"].replace("._hap._tcp.local.", "")
|
||||
self.model = device.info["md"]
|
||||
self.hkid = normalize_hkid(device.info["id"])
|
||||
self.name = device.description.name
|
||||
self.model = device.description.model
|
||||
self.hkid = device.description.id
|
||||
|
||||
return self._async_step_pair_show_form()
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "HomeKit Controller",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
|
||||
"requirements": ["aiohomekit==0.7.13"],
|
||||
"requirements": ["aiohomekit==0.7.14"],
|
||||
"zeroconf": ["_hap._tcp.local."],
|
||||
"after_dependencies": ["zeroconf"],
|
||||
"codeowners": ["@Jc2k", "@bdraco"],
|
||||
|
|
|
@ -184,7 +184,7 @@ aioguardian==2021.11.0
|
|||
aioharmony==0.2.9
|
||||
|
||||
# homeassistant.components.homekit_controller
|
||||
aiohomekit==0.7.13
|
||||
aiohomekit==0.7.14
|
||||
|
||||
# homeassistant.components.emulated_hue
|
||||
# homeassistant.components.http
|
||||
|
|
|
@ -134,7 +134,7 @@ aioguardian==2021.11.0
|
|||
aioharmony==0.2.9
|
||||
|
||||
# homeassistant.components.homekit_controller
|
||||
aiohomekit==0.7.13
|
||||
aiohomekit==0.7.14
|
||||
|
||||
# homeassistant.components.emulated_hue
|
||||
# homeassistant.components.http
|
||||
|
|
|
@ -85,7 +85,7 @@ def _setup_flow_handler(hass, pairing=None):
|
|||
finish_pairing = unittest.mock.AsyncMock(return_value=pairing)
|
||||
|
||||
discovery = mock.Mock()
|
||||
discovery.device_id = "00:00:00:00:00:00"
|
||||
discovery.description.id = "00:00:00:00:00:00"
|
||||
discovery.async_start_pairing = unittest.mock.AsyncMock(return_value=finish_pairing)
|
||||
|
||||
flow.controller = mock.Mock()
|
||||
|
@ -136,22 +136,21 @@ def get_device_discovery_info(
|
|||
device, upper_case_props=False, missing_csharp=False
|
||||
) -> zeroconf.ZeroconfServiceInfo:
|
||||
"""Turn a aiohomekit format zeroconf entry into a homeassistant one."""
|
||||
record = device.info
|
||||
result = zeroconf.ZeroconfServiceInfo(
|
||||
host=record["address"],
|
||||
addresses=[record["address"]],
|
||||
hostname=record["name"],
|
||||
name=record["name"],
|
||||
port=record["port"],
|
||||
host="127.0.0.1",
|
||||
hostname=device.description.name,
|
||||
name=device.description.name,
|
||||
addresses=["127.0.0.1"],
|
||||
port=8080,
|
||||
properties={
|
||||
"md": record["md"],
|
||||
"pv": record["pv"],
|
||||
zeroconf.ATTR_PROPERTIES_ID: device.device_id,
|
||||
"c#": record["c#"],
|
||||
"s#": record["s#"],
|
||||
"ff": record["ff"],
|
||||
"ci": record["ci"],
|
||||
"sf": 0x01, # record["sf"],
|
||||
"md": device.description.model,
|
||||
"pv": "1.0",
|
||||
zeroconf.ATTR_PROPERTIES_ID: device.description.id,
|
||||
"c#": device.description.config_num,
|
||||
"s#": device.description.state_num,
|
||||
"ff": "0",
|
||||
"ci": "0",
|
||||
"sf": "1",
|
||||
"sh": "",
|
||||
},
|
||||
type="_hap._tcp.local.",
|
||||
|
@ -787,7 +786,7 @@ async def test_user_no_unpaired_devices(hass, controller):
|
|||
device = setup_mock_accessory(controller)
|
||||
|
||||
# Pair the mock device so that it shows as paired in discovery
|
||||
finish_pairing = await device.async_start_pairing(device.device_id)
|
||||
finish_pairing = await device.async_start_pairing(device.description.id)
|
||||
await finish_pairing(device.pairing_code)
|
||||
|
||||
# Device discovery is requested
|
||||
|
@ -807,7 +806,7 @@ async def test_unignore_works(hass, controller):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
"homekit_controller",
|
||||
context={"source": config_entries.SOURCE_UNIGNORE},
|
||||
data={"unique_id": device.device_id},
|
||||
data={"unique_id": device.description.id},
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "pair"
|
||||
|
|
Loading…
Reference in New Issue