diff --git a/homeassistant/components/homekit_controller/config_flow.py b/homeassistant/components/homekit_controller/config_flow.py index 82ab670f8db..48551129b67 100644 --- a/homeassistant/components/homekit_controller/config_flow.py +++ b/homeassistant/components/homekit_controller/config_flow.py @@ -125,10 +125,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): if self.controller is None: await self._async_setup_controller() - all_hosts = await self.controller.discover_ip() - self.devices = {} - for host in all_hosts: + + async for host in self.controller.async_discover(): status_flags = int(host.info["sf"]) paired = not status_flags & 0x01 if paired: @@ -155,7 +154,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): await self._async_setup_controller() try: - device = await self.controller.find_ip_by_device_id(unique_id) + device = await self.controller.async_find(unique_id) except aiohomekit.AccessoryNotFoundError: return self.async_abort(reason="accessory_not_found_error") @@ -339,12 +338,12 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # If it doesn't have a screen then the pin is static. # If it has a display it will display a pin on that display. In - # this case the code is random. So we have to call the start_pairing + # this case the code is random. So we have to call the async_start_pairing # API before the user can enter a pin. But equally we don't want to - # call start_pairing when the device is discovered, only when they + # call async_start_pairing when the device is discovered, only when they # click on 'Configure' in the UI. - # start_pairing will make the device show its pin and return a + # async_start_pairing will make the device show its pin and return a # callable. We call the callable with the pin that the user has typed # in. @@ -399,8 +398,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # we always check to see if self.finish_paring has been # set. try: - discovery = await self.controller.find_ip_by_device_id(self.hkid) - self.finish_pairing = await discovery.start_pairing(self.hkid) + discovery = await self.controller.async_find(self.hkid) + self.finish_pairing = await discovery.async_start_pairing(self.hkid) except aiohomekit.BusyError: # Already performing a pair setup operation with a different diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index 4e216474ec0..43b0a614f44 100644 --- a/homeassistant/components/homekit_controller/manifest.json +++ b/homeassistant/components/homekit_controller/manifest.json @@ -3,7 +3,7 @@ "name": "HomeKit Controller", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/homekit_controller", - "requirements": ["aiohomekit==0.7.11"], + "requirements": ["aiohomekit==0.7.13"], "zeroconf": ["_hap._tcp.local."], "after_dependencies": ["zeroconf"], "codeowners": ["@Jc2k", "@bdraco"], diff --git a/requirements_all.txt b/requirements_all.txt index 9186eeed738..7ef4a52b8cb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -184,7 +184,7 @@ aioguardian==2021.11.0 aioharmony==0.2.9 # homeassistant.components.homekit_controller -aiohomekit==0.7.11 +aiohomekit==0.7.13 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b9ece9bf5cf..a1210060d6b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -134,7 +134,7 @@ aioguardian==2021.11.0 aioharmony==0.2.9 # homeassistant.components.homekit_controller -aiohomekit==0.7.11 +aiohomekit==0.7.13 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index 101e4ebd024..54408e5882d 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -86,13 +86,11 @@ def _setup_flow_handler(hass, pairing=None): discovery = mock.Mock() discovery.device_id = "00:00:00:00:00:00" - discovery.start_pairing = unittest.mock.AsyncMock(return_value=finish_pairing) + discovery.async_start_pairing = unittest.mock.AsyncMock(return_value=finish_pairing) flow.controller = mock.Mock() flow.controller.pairings = {} - flow.controller.find_ip_by_device_id = unittest.mock.AsyncMock( - return_value=discovery - ) + flow.controller.async_find = unittest.mock.AsyncMock(return_value=discovery) return flow @@ -520,7 +518,7 @@ async def test_pair_abort_errors_on_start(hass, controller, exception, expected) # User initiates pairing - device refuses to enter pairing mode test_exc = exception("error") - with patch.object(device, "start_pairing", side_effect=test_exc): + with patch.object(device, "async_start_pairing", side_effect=test_exc): result = await hass.config_entries.flow.async_configure(result["flow_id"]) assert result["type"] == "abort" assert result["reason"] == expected @@ -542,7 +540,7 @@ async def test_pair_try_later_errors_on_start(hass, controller, exception, expec # User initiates pairing - device refuses to enter pairing mode but may be successful after entering pairing mode or rebooting test_exc = exception("error") - with patch.object(device, "start_pairing", side_effect=test_exc): + with patch.object(device, "async_start_pairing", side_effect=test_exc): result2 = await hass.config_entries.flow.async_configure(result["flow_id"]) assert result2["step_id"] == expected assert result2["type"] == "form" @@ -585,7 +583,7 @@ async def test_pair_form_errors_on_start(hass, controller, exception, expected): # User initiates pairing - device refuses to enter pairing mode test_exc = exception("error") - with patch.object(device, "start_pairing", side_effect=test_exc): + with patch.object(device, "async_start_pairing", side_effect=test_exc): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={"pairing_code": "111-22-333"} ) @@ -634,7 +632,7 @@ async def test_pair_abort_errors_on_finish(hass, controller, exception, expected # User initiates pairing - this triggers the device to show a pairing code # and then HA to show a pairing form finish_pairing = unittest.mock.AsyncMock(side_effect=exception("error")) - with patch.object(device, "start_pairing", return_value=finish_pairing): + with patch.object(device, "async_start_pairing", return_value=finish_pairing): result = await hass.config_entries.flow.async_configure(result["flow_id"]) assert result["type"] == "form" @@ -674,7 +672,7 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected) # User initiates pairing - this triggers the device to show a pairing code # and then HA to show a pairing form finish_pairing = unittest.mock.AsyncMock(side_effect=exception("error")) - with patch.object(device, "start_pairing", return_value=finish_pairing): + with patch.object(device, "async_start_pairing", return_value=finish_pairing): result = await hass.config_entries.flow.async_configure(result["flow_id"]) assert result["type"] == "form" @@ -789,7 +787,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.start_pairing(device.device_id) + finish_pairing = await device.async_start_pairing(device.device_id) await finish_pairing(device.pairing_code) # Device discovery is requested