From 92a47f14bbc40831f40f0d05c1b5f19929ca70b1 Mon Sep 17 00:00:00 2001 From: Jc2k Date: Wed, 26 Feb 2020 17:44:04 +0000 Subject: [PATCH] homekit_controller test cleanups (#32212) --- .../components/homekit_controller/connection.py | 7 ++++--- .../components/homekit_controller/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/homekit_controller/common.py | 7 ++----- .../specific_devices/test_ecobee3.py | 10 ++-------- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/homekit_controller/connection.py b/homeassistant/components/homekit_controller/connection.py index 154f9955779..f49480fc69d 100644 --- a/homeassistant/components/homekit_controller/connection.py +++ b/homeassistant/components/homekit_controller/connection.py @@ -3,7 +3,6 @@ import asyncio import datetime import logging -from aiohomekit.controller.ip import IpPairing from aiohomekit.exceptions import ( AccessoryDisconnectedError, AccessoryNotFoundError, @@ -15,7 +14,7 @@ from aiohomekit.model.services import ServicesTypes from homeassistant.core import callback from homeassistant.helpers.event import async_track_time_interval -from .const import DOMAIN, ENTITY_MAP, HOMEKIT_ACCESSORY_DISPATCH +from .const import CONTROLLER, DOMAIN, ENTITY_MAP, HOMEKIT_ACCESSORY_DISPATCH DEFAULT_SCAN_INTERVAL = datetime.timedelta(seconds=60) RETRY_INTERVAL = 60 # seconds @@ -66,7 +65,9 @@ class HKDevice: # don't want to mutate a dict owned by a config entry. self.pairing_data = pairing_data.copy() - self.pairing = IpPairing(self.pairing_data) + self.pairing = hass.data[CONTROLLER].load_pairing( + self.pairing_data["AccessoryPairingID"], self.pairing_data + ) self.accessories = {} self.config_num = 0 diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index cd2d0c67b44..e821efb3a60 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[IP]==0.2.11"], + "requirements": ["aiohomekit[IP]==0.2.15"], "dependencies": [], "zeroconf": ["_hap._tcp.local."], "codeowners": ["@Jc2k"] diff --git a/requirements_all.txt b/requirements_all.txt index d67d9084b5d..c56cd516fc9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -163,7 +163,7 @@ aioftp==0.12.0 aioharmony==0.1.13 # homeassistant.components.homekit_controller -aiohomekit[IP]==0.2.11 +aiohomekit[IP]==0.2.15 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c0510c25d6c..368c40f0487 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -62,7 +62,7 @@ aiobotocore==0.11.1 aioesphomeapi==2.6.1 # homeassistant.components.homekit_controller -aiohomekit[IP]==0.2.11 +aiohomekit[IP]==0.2.15 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/tests/components/homekit_controller/common.py b/tests/components/homekit_controller/common.py index 51a12815124..4a6515a2503 100644 --- a/tests/components/homekit_controller/common.py +++ b/tests/components/homekit_controller/common.py @@ -98,11 +98,8 @@ async def setup_test_accessories(hass, accessories): ) config_entry.add_to_hass(hass) - pairing_cls_loc = "homeassistant.components.homekit_controller.connection.IpPairing" - with mock.patch(pairing_cls_loc) as pairing_cls: - pairing_cls.return_value = pairing - await config_entry.async_setup(hass) - await hass.async_block_till_done() + await config_entry.async_setup(hass) + await hass.async_block_till_done() return config_entry, pairing diff --git a/tests/components/homekit_controller/specific_devices/test_ecobee3.py b/tests/components/homekit_controller/specific_devices/test_ecobee3.py index 7a18dad4f5c..ee048f93ca7 100644 --- a/tests/components/homekit_controller/specific_devices/test_ecobee3.py +++ b/tests/components/homekit_controller/specific_devices/test_ecobee3.py @@ -149,14 +149,8 @@ async def test_ecobee3_setup_connection_failure(hass): # a successful setup. # We just advance time by 5 minutes so that the retry happens, rather - # than manually invoking async_setup_entry - this means we need to - # make sure the IpPairing mock is in place or we'll try to connect to - # a real device. Normally this mocking is done by the helper in - # setup_test_accessories. - pairing_cls_loc = "homeassistant.components.homekit_controller.connection.IpPairing" - with mock.patch(pairing_cls_loc) as pairing_cls: - pairing_cls.return_value = pairing - await time_changed(hass, 5 * 60) + # than manually invoking async_setup_entry. + await time_changed(hass, 5 * 60) climate = entity_registry.async_get("climate.homew") assert climate.unique_id == "homekit-123456789012-16"