mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Refactor homekit_controller config flow tests (#32141)
* Config flow test refactor * Add a service and characteristic to the accessory so its more realistic * Feedback from review * Missing apostrophe
This commit is contained in:
parent
ba4cc373c8
commit
c9d78aa78c
@ -5,7 +5,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
import aiohomekit
|
import aiohomekit
|
||||||
from aiohomekit import Controller
|
|
||||||
from aiohomekit.controller.ip import IpPairing
|
from aiohomekit.controller.ip import IpPairing
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ def normalize_hkid(hkid):
|
|||||||
def find_existing_host(hass, serial):
|
def find_existing_host(hass, serial):
|
||||||
"""Return a set of the configured hosts."""
|
"""Return a set of the configured hosts."""
|
||||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||||
if entry.data["AccessoryPairingID"] == serial:
|
if entry.data.get("AccessoryPairingID") == serial:
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
|
|||||||
self.model = None
|
self.model = None
|
||||||
self.hkid = None
|
self.hkid = None
|
||||||
self.devices = {}
|
self.devices = {}
|
||||||
self.controller = Controller()
|
self.controller = aiohomekit.Controller()
|
||||||
self.finish_pairing = None
|
self.finish_pairing = None
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
@ -203,6 +202,14 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
_LOGGER.debug("Discovered device %s (%s - %s)", name, model, hkid)
|
_LOGGER.debug("Discovered device %s (%s - %s)", name, model, hkid)
|
||||||
|
|
||||||
|
# Device isn't paired with us or anyone else.
|
||||||
|
# But we have a 'complete' config entry for it - that is probably
|
||||||
|
# invalid. Remove it automatically.
|
||||||
|
existing = find_existing_host(self.hass, hkid)
|
||||||
|
if not paired and existing:
|
||||||
|
await self.hass.config_entries.async_remove(existing.entry_id)
|
||||||
|
|
||||||
|
# Set unique-id and error out if it's already configured
|
||||||
await self.async_set_unique_id(normalize_hkid(hkid))
|
await self.async_set_unique_id(normalize_hkid(hkid))
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
@ -230,13 +237,6 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
|
|||||||
if model in HOMEKIT_IGNORE:
|
if model in HOMEKIT_IGNORE:
|
||||||
return self.async_abort(reason="ignored_model")
|
return self.async_abort(reason="ignored_model")
|
||||||
|
|
||||||
# Device isn't paired with us or anyone else.
|
|
||||||
# But we have a 'complete' config entry for it - that is probably
|
|
||||||
# invalid. Remove it automatically.
|
|
||||||
existing = find_existing_host(self.hass, hkid)
|
|
||||||
if existing:
|
|
||||||
await self.hass.config_entries.async_remove(existing.entry_id)
|
|
||||||
|
|
||||||
self.model = model
|
self.model = model
|
||||||
self.hkid = hkid
|
self.hkid = hkid
|
||||||
|
|
||||||
@ -250,17 +250,6 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
hkid = discovery_props["id"]
|
hkid = discovery_props["id"]
|
||||||
|
|
||||||
existing = find_existing_host(self.hass, hkid)
|
|
||||||
if existing:
|
|
||||||
_LOGGER.info(
|
|
||||||
(
|
|
||||||
"Legacy configuration for homekit accessory %s"
|
|
||||||
"not loaded as already migrated"
|
|
||||||
),
|
|
||||||
hkid,
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
(
|
(
|
||||||
"Legacy configuration %s for homekit"
|
"Legacy configuration %s for homekit"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "HomeKit Controller",
|
"name": "HomeKit Controller",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
|
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
|
||||||
"requirements": ["aiohomekit[IP]==0.2.10"],
|
"requirements": ["aiohomekit[IP]==0.2.11"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"zeroconf": ["_hap._tcp.local."],
|
"zeroconf": ["_hap._tcp.local."],
|
||||||
"codeowners": ["@Jc2k"]
|
"codeowners": ["@Jc2k"]
|
||||||
|
@ -163,7 +163,7 @@ aioftp==0.12.0
|
|||||||
aioharmony==0.1.13
|
aioharmony==0.1.13
|
||||||
|
|
||||||
# homeassistant.components.homekit_controller
|
# homeassistant.components.homekit_controller
|
||||||
aiohomekit[IP]==0.2.10
|
aiohomekit[IP]==0.2.11
|
||||||
|
|
||||||
# homeassistant.components.emulated_hue
|
# homeassistant.components.emulated_hue
|
||||||
# homeassistant.components.http
|
# homeassistant.components.http
|
||||||
|
@ -62,7 +62,7 @@ aiobotocore==0.11.1
|
|||||||
aioesphomeapi==2.6.1
|
aioesphomeapi==2.6.1
|
||||||
|
|
||||||
# homeassistant.components.homekit_controller
|
# homeassistant.components.homekit_controller
|
||||||
aiohomekit[IP]==0.2.10
|
aiohomekit[IP]==0.2.11
|
||||||
|
|
||||||
# homeassistant.components.emulated_hue
|
# homeassistant.components.emulated_hue
|
||||||
# homeassistant.components.http
|
# homeassistant.components.http
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
from aiohomekit.testing import FakeController
|
||||||
|
import asynctest
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -12,3 +14,11 @@ def utcnow(request):
|
|||||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||||
dt_utcnow.return_value = start_dt
|
dt_utcnow.return_value = start_dt
|
||||||
yield dt_utcnow
|
yield dt_utcnow
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def controller(hass):
|
||||||
|
"""Replace aiohomekit.Controller with an instance of aiohomekit.testing.FakeController."""
|
||||||
|
instance = FakeController()
|
||||||
|
with asynctest.patch("aiohomekit.Controller", return_value=instance):
|
||||||
|
yield instance
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user