Remove zeroconf options from homekit (#35687)

* Remove zeroconf options from homekit

homekit uses the system shared zeroconf instance which
made the interface choice option controlled by the
zeroconf integration setting.

* change to cv.deprecated

* adj

* fix remaining tests from original merge conflict

* remove invalidation_version
This commit is contained in:
J. Nick Koston 2020-06-02 17:47:39 -05:00 committed by GitHub
parent bfc5aa90b1
commit 5f4fdaa171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 149 deletions

View File

@ -6,7 +6,6 @@ import os
from aiohttp import web from aiohttp import web
import voluptuous as vol import voluptuous as vol
from zeroconf import InterfaceChoice
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
@ -71,7 +70,6 @@ from .const import (
DEFAULT_AUTO_START, DEFAULT_AUTO_START,
DEFAULT_PORT, DEFAULT_PORT,
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
DOMAIN, DOMAIN,
EVENT_HOMEKIT_CHANGED, EVENT_HOMEKIT_CHANGED,
HOMEKIT, HOMEKIT,
@ -113,23 +111,24 @@ def _has_all_unique_names_and_ports(bridges):
return bridges return bridges
BRIDGE_SCHEMA = vol.Schema( BRIDGE_SCHEMA = vol.All(
{ cv.deprecated(CONF_ZEROCONF_DEFAULT_INTERFACE),
vol.Optional(CONF_NAME, default=BRIDGE_NAME): vol.All( vol.Schema(
cv.string, vol.Length(min=3, max=25) {
), vol.Optional(CONF_NAME, default=BRIDGE_NAME): vol.All(
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, cv.string, vol.Length(min=3, max=25)
vol.Optional(CONF_IP_ADDRESS): vol.All(ipaddress.ip_address, cv.string), ),
vol.Optional(CONF_ADVERTISE_IP): vol.All(ipaddress.ip_address, cv.string), vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): cv.boolean, vol.Optional(CONF_IP_ADDRESS): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_SAFE_MODE, default=DEFAULT_SAFE_MODE): cv.boolean, vol.Optional(CONF_ADVERTISE_IP): vol.All(ipaddress.ip_address, cv.string),
vol.Optional(CONF_FILTER, default={}): BASE_FILTER_SCHEMA, vol.Optional(CONF_AUTO_START, default=DEFAULT_AUTO_START): cv.boolean,
vol.Optional(CONF_ENTITY_CONFIG, default={}): validate_entity_config, vol.Optional(CONF_SAFE_MODE, default=DEFAULT_SAFE_MODE): cv.boolean,
vol.Optional( vol.Optional(CONF_FILTER, default={}): BASE_FILTER_SCHEMA,
CONF_ZEROCONF_DEFAULT_INTERFACE, default=DEFAULT_ZEROCONF_DEFAULT_INTERFACE, vol.Optional(CONF_ENTITY_CONFIG, default={}): validate_entity_config,
): cv.boolean, vol.Optional(CONF_ZEROCONF_DEFAULT_INTERFACE): cv.boolean,
}, },
extra=vol.ALLOW_EXTRA, extra=vol.ALLOW_EXTRA,
),
) )
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(
@ -233,11 +232,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
}, },
) )
) )
interface_choice = (
InterfaceChoice.Default
if options.get(CONF_ZEROCONF_DEFAULT_INTERFACE)
else None
)
homekit = HomeKit( homekit = HomeKit(
hass, hass,
@ -248,11 +242,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
entity_config, entity_config,
safe_mode, safe_mode,
advertise_ip, advertise_ip,
interface_choice,
entry.entry_id, entry.entry_id,
) )
await hass.async_add_executor_job(homekit.setup) zeroconf_instance = await zeroconf.async_get_instance(hass)
await homekit.async_setup_zeroconf() await hass.async_add_executor_job(homekit.setup, zeroconf_instance)
undo_listener = entry.add_update_listener(_async_update_listener) undo_listener = entry.add_update_listener(_async_update_listener)
@ -404,7 +397,6 @@ class HomeKit:
entity_config, entity_config,
safe_mode, safe_mode,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=None, entry_id=None,
): ):
"""Initialize a HomeKit object.""" """Initialize a HomeKit object."""
@ -416,14 +408,13 @@ class HomeKit:
self._config = entity_config self._config = entity_config
self._safe_mode = safe_mode self._safe_mode = safe_mode
self._advertise_ip = advertise_ip self._advertise_ip = advertise_ip
self._interface_choice = interface_choice
self._entry_id = entry_id self._entry_id = entry_id
self.status = STATUS_READY self.status = STATUS_READY
self.bridge = None self.bridge = None
self.driver = None self.driver = None
def setup(self): def setup(self, zeroconf_instance):
"""Set up bridge and accessory driver.""" """Set up bridge and accessory driver."""
# pylint: disable=import-outside-toplevel # pylint: disable=import-outside-toplevel
from .accessories import HomeBridge, HomeDriver from .accessories import HomeBridge, HomeDriver
@ -440,7 +431,7 @@ class HomeKit:
port=self._port, port=self._port,
persist_file=persist_file, persist_file=persist_file,
advertised_address=self._advertise_ip, advertised_address=self._advertise_ip,
interface_choice=self._interface_choice, zeroconf_instance=zeroconf_instance,
) )
# If we do not load the mac address will be wrong # If we do not load the mac address will be wrong
@ -455,12 +446,6 @@ class HomeKit:
_LOGGER.debug("Safe_mode selected for %s", self._name) _LOGGER.debug("Safe_mode selected for %s", self._name)
self.driver.safe_mode = True self.driver.safe_mode = True
async def async_setup_zeroconf(self):
"""Share the system zeroconf instance."""
# Replace the existing zeroconf instance.
await self.hass.async_add_executor_job(self.driver.advertiser.close)
self.driver.advertiser = await zeroconf.async_get_instance(self.hass)
def reset_accessories(self, entity_ids): def reset_accessories(self, entity_ids):
"""Reset the accessory to load the latest configuration.""" """Reset the accessory to load the latest configuration."""
aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE] aid_storage = self.hass.data[DOMAIN][self._entry_id][AID_STORAGE]

View File

@ -23,11 +23,9 @@ from .const import (
CONF_FILTER, CONF_FILTER,
CONF_SAFE_MODE, CONF_SAFE_MODE,
CONF_VIDEO_CODEC, CONF_VIDEO_CODEC,
CONF_ZEROCONF_DEFAULT_INTERFACE,
DEFAULT_AUTO_START, DEFAULT_AUTO_START,
DEFAULT_CONFIG_FLOW_PORT, DEFAULT_CONFIG_FLOW_PORT,
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
SHORT_BRIDGE_NAME, SHORT_BRIDGE_NAME,
VIDEO_CODEC_COPY, VIDEO_CODEC_COPY,
) )
@ -227,14 +225,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
vol.Optional( vol.Optional(
CONF_SAFE_MODE, CONF_SAFE_MODE,
default=self.homekit_options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE), default=self.homekit_options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE),
): bool, ): bool
vol.Optional(
CONF_ZEROCONF_DEFAULT_INTERFACE,
default=self.homekit_options.get(
CONF_ZEROCONF_DEFAULT_INTERFACE,
DEFAULT_ZEROCONF_DEFAULT_INTERFACE,
),
): bool,
} }
) )

View File

@ -68,7 +68,6 @@ DEFAULT_MAX_WIDTH = 1920
DEFAULT_PORT = 51827 DEFAULT_PORT = 51827
DEFAULT_CONFIG_FLOW_PORT = 51828 DEFAULT_CONFIG_FLOW_PORT = 51828
DEFAULT_SAFE_MODE = False DEFAULT_SAFE_MODE = False
DEFAULT_ZEROCONF_DEFAULT_INTERFACE = False
DEFAULT_VIDEO_CODEC = VIDEO_CODEC_LIBX264 DEFAULT_VIDEO_CODEC = VIDEO_CODEC_LIBX264
DEFAULT_VIDEO_MAP = "0:v:0" DEFAULT_VIDEO_MAP = "0:v:0"
DEFAULT_VIDEO_PACKET_SIZE = 1316 DEFAULT_VIDEO_PACKET_SIZE = 1316
@ -267,7 +266,6 @@ HK_NOT_CHARGABLE = 2
CONFIG_OPTIONS = [ CONFIG_OPTIONS = [
CONF_FILTER, CONF_FILTER,
CONF_AUTO_START, CONF_AUTO_START,
CONF_ZEROCONF_DEFAULT_INTERFACE,
CONF_SAFE_MODE, CONF_SAFE_MODE,
CONF_ENTITY_CONFIG, CONF_ENTITY_CONFIG,
] ]

View File

@ -30,8 +30,7 @@
"advanced": { "advanced": {
"data": { "data": {
"auto_start": "[%key:component::homekit::config::step::user::data::auto_start%]", "auto_start": "[%key:component::homekit::config::step::user::data::auto_start%]",
"safe_mode": "Safe Mode (enable only if pairing fails)", "safe_mode": "Safe Mode (enable only if pairing fails)"
"zeroconf_default_interface": "Use default zeroconf interface (enable if the bridge cannot be found in the Home app)"
}, },
"description": "These settings only need to be adjusted if the HomeKit bridge is not functional.", "description": "These settings only need to be adjusted if the HomeKit bridge is not functional.",
"title": "Advanced Configuration" "title": "Advanced Configuration"

View File

@ -23,8 +23,7 @@
"advanced": { "advanced": {
"data": { "data": {
"auto_start": "Autostart (disable if using Z-Wave or other delayed start system)", "auto_start": "Autostart (disable if using Z-Wave or other delayed start system)",
"safe_mode": "Safe Mode (enable only if pairing fails)", "safe_mode": "Safe Mode (enable only if pairing fails)"
"zeroconf_default_interface": "Use default zeroconf interface (enable if the bridge cannot be found in the Home app)"
}, },
"description": "These settings only need to be adjusted if the HomeKit bridge is not functional.", "description": "These settings only need to be adjusted if the HomeKit bridge is not functional.",
"title": "Advanced Configuration" "title": "Advanced Configuration"

View File

@ -27,7 +27,6 @@ def _mock_config_entry_with_options_populated():
}, },
"auto_start": False, "auto_start": False,
"safe_mode": False, "safe_mode": False,
"zeroconf_default_interface": True,
}, },
) )
@ -149,12 +148,7 @@ async def test_options_flow_advanced(hass):
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True): with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result3 = await hass.config_entries.options.async_configure( result3 = await hass.config_entries.options.async_configure(
result2["flow_id"], result2["flow_id"], user_input={"auto_start": True, "safe_mode": True},
user_input={
"auto_start": True,
"safe_mode": True,
"zeroconf_default_interface": False,
},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -167,7 +161,6 @@ async def test_options_flow_advanced(hass):
"include_entities": [], "include_entities": [],
}, },
"safe_mode": True, "safe_mode": True,
"zeroconf_default_interface": False,
} }
@ -202,8 +195,7 @@ async def test_options_flow_basic(hass):
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True): with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result3 = await hass.config_entries.options.async_configure( result3 = await hass.config_entries.options.async_configure(
result2["flow_id"], result2["flow_id"], user_input={"safe_mode": True},
user_input={"safe_mode": True, "zeroconf_default_interface": False},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -216,7 +208,6 @@ async def test_options_flow_basic(hass):
"include_entities": [], "include_entities": [],
}, },
"safe_mode": True, "safe_mode": True,
"zeroconf_default_interface": False,
} }
@ -264,8 +255,7 @@ async def test_options_flow_with_cameras(hass):
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True): with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure( result4 = await hass.config_entries.options.async_configure(
result3["flow_id"], result3["flow_id"], user_input={"safe_mode": True},
user_input={"safe_mode": True, "zeroconf_default_interface": False},
) )
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -279,7 +269,6 @@ async def test_options_flow_with_cameras(hass):
}, },
"entity_config": {"camera.native_h264": {"video_codec": "copy"}}, "entity_config": {"camera.native_h264": {"video_codec": "copy"}},
"safe_mode": True, "safe_mode": True,
"zeroconf_default_interface": False,
} }
# Now run though again and verify we can turn off copy # Now run though again and verify we can turn off copy
@ -315,8 +304,7 @@ async def test_options_flow_with_cameras(hass):
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True): with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure( result4 = await hass.config_entries.options.async_configure(
result3["flow_id"], result3["flow_id"], user_input={"safe_mode": True},
user_input={"safe_mode": True, "zeroconf_default_interface": False},
) )
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -330,7 +318,6 @@ async def test_options_flow_with_cameras(hass):
}, },
"entity_config": {"camera.native_h264": {}}, "entity_config": {"camera.native_h264": {}},
"safe_mode": True, "safe_mode": True,
"zeroconf_default_interface": False,
} }
@ -353,7 +340,6 @@ async def test_options_flow_blocked_when_from_yaml(hass):
"exclude_entities": ["climate.front_gate"], "exclude_entities": ["climate.front_gate"],
}, },
"safe_mode": False, "safe_mode": False,
"zeroconf_default_interface": True,
}, },
source=SOURCE_IMPORT, source=SOURCE_IMPORT,
) )

View File

@ -2,8 +2,8 @@
import os import os
from typing import Dict from typing import Dict
from asynctest import MagicMock
import pytest import pytest
from zeroconf import InterfaceChoice
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
@ -26,10 +26,10 @@ from homeassistant.components.homekit.const import (
CONF_AUTO_START, CONF_AUTO_START,
CONF_ENTRY_INDEX, CONF_ENTRY_INDEX,
CONF_SAFE_MODE, CONF_SAFE_MODE,
CONF_ZEROCONF_DEFAULT_INTERFACE,
DEFAULT_PORT, DEFAULT_PORT,
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
DOMAIN, DOMAIN,
HOMEKIT,
HOMEKIT_FILE, HOMEKIT_FILE,
SERVICE_HOMEKIT_RESET_ACCESSORY, SERVICE_HOMEKIT_RESET_ACCESSORY,
SERVICE_HOMEKIT_START, SERVICE_HOMEKIT_START,
@ -99,7 +99,6 @@ async def test_setup_min(hass):
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit: with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock() mock_homekit.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock() type(homekit).async_start = AsyncMock()
type(homekit).async_setup_zeroconf = AsyncMock()
assert await hass.config_entries.async_setup(entry.entry_id) assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -112,7 +111,6 @@ async def test_setup_min(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
None, None,
None,
entry.entry_id, entry.entry_id,
) )
assert mock_homekit().setup.called is True assert mock_homekit().setup.called is True
@ -130,18 +128,13 @@ async def test_setup_auto_start_disabled(hass):
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
data={CONF_NAME: "Test Name", CONF_PORT: 11111, CONF_IP_ADDRESS: "172.0.0.0"}, data={CONF_NAME: "Test Name", CONF_PORT: 11111, CONF_IP_ADDRESS: "172.0.0.0"},
options={ options={CONF_AUTO_START: False, CONF_SAFE_MODE: DEFAULT_SAFE_MODE},
CONF_AUTO_START: False,
CONF_SAFE_MODE: DEFAULT_SAFE_MODE,
CONF_ZEROCONF_DEFAULT_INTERFACE: True,
},
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit: with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock() mock_homekit.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock() type(homekit).async_start = AsyncMock()
type(homekit).async_setup_zeroconf = AsyncMock()
assert await hass.config_entries.async_setup(entry.entry_id) assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -154,7 +147,6 @@ async def test_setup_auto_start_disabled(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
None, None,
InterfaceChoice.Default,
entry.entry_id, entry.entry_id,
) )
assert mock_homekit().setup.called is True assert mock_homekit().setup.called is True
@ -201,15 +193,15 @@ async def test_homekit_setup(hass, hk_driver):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
zeroconf_mock = MagicMock()
with patch( with patch(
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver, patch("homeassistant.util.get_local_ip") as mock_ip: ) as mock_driver, patch("homeassistant.util.get_local_ip") as mock_ip:
mock_ip.return_value = IP_ADDRESS mock_ip.return_value = IP_ADDRESS
await hass.async_add_executor_job(homekit.setup) await hass.async_add_executor_job(homekit.setup, zeroconf_mock)
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id) path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
assert isinstance(homekit.bridge, HomeBridge) assert isinstance(homekit.bridge, HomeBridge)
@ -221,7 +213,7 @@ async def test_homekit_setup(hass, hk_driver):
port=DEFAULT_PORT, port=DEFAULT_PORT,
persist_file=path, persist_file=path,
advertised_address=None, advertised_address=None,
interface_choice=None, zeroconf_instance=zeroconf_mock,
) )
assert homekit.driver.safe_mode is False assert homekit.driver.safe_mode is False
@ -245,15 +237,15 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
{}, {},
None, None,
None, None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
mock_zeroconf = MagicMock()
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id) path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
with patch( with patch(
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver: ) as mock_driver:
await hass.async_add_executor_job(homekit.setup) await hass.async_add_executor_job(homekit.setup, mock_zeroconf)
mock_driver.assert_called_with( mock_driver.assert_called_with(
hass, hass,
entry.entry_id, entry.entry_id,
@ -262,7 +254,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
port=DEFAULT_PORT, port=DEFAULT_PORT,
persist_file=path, persist_file=path,
advertised_address=None, advertised_address=None,
interface_choice=None, zeroconf_instance=mock_zeroconf,
) )
@ -282,15 +274,15 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
{}, {},
None, None,
"192.168.1.100", "192.168.1.100",
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
zeroconf_instance = MagicMock()
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id) path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
with patch( with patch(
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver: ) as mock_driver:
await hass.async_add_executor_job(homekit.setup) await hass.async_add_executor_job(homekit.setup, zeroconf_instance)
mock_driver.assert_called_with( mock_driver.assert_called_with(
hass, hass,
entry.entry_id, entry.entry_id,
@ -299,44 +291,7 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
port=DEFAULT_PORT, port=DEFAULT_PORT,
persist_file=path, persist_file=path,
advertised_address="192.168.1.100", advertised_address="192.168.1.100",
interface_choice=None, zeroconf_instance=zeroconf_instance,
)
async def test_homekit_setup_interface_choice(hass, hk_driver):
"""Test setup with interface choice of Default."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_NAME: "mock_name", CONF_PORT: 12345},
source=SOURCE_IMPORT,
)
homekit = HomeKit(
hass,
BRIDGE_NAME,
DEFAULT_PORT,
"0.0.0.0",
{},
{},
None,
None,
InterfaceChoice.Default,
entry_id=entry.entry_id,
)
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
with patch(
f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver
) as mock_driver:
await hass.async_add_executor_job(homekit.setup)
mock_driver.assert_called_with(
hass,
entry.entry_id,
BRIDGE_NAME,
address="0.0.0.0",
port=DEFAULT_PORT,
persist_file=path,
advertised_address=None,
interface_choice=InterfaceChoice.Default,
) )
@ -356,12 +311,11 @@ async def test_homekit_setup_safe_mode(hass, hk_driver):
{}, {},
True, True,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
with patch(f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver): with patch(f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver):
await hass.async_add_executor_job(homekit.setup) await hass.async_add_executor_job(homekit.setup, MagicMock())
assert homekit.driver.safe_mode is True assert homekit.driver.safe_mode is True
@ -378,7 +332,6 @@ async def test_homekit_add_accessory(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = "driver" homekit.driver = "driver"
@ -415,7 +368,6 @@ async def test_homekit_remove_accessory(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = "driver" homekit.driver = "driver"
@ -441,7 +393,6 @@ async def test_homekit_entity_filter(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.bridge = Mock() homekit.bridge = Mock()
@ -476,7 +427,6 @@ async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.bridge = Mock() homekit.bridge = Mock()
@ -566,7 +516,6 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
@ -612,7 +561,6 @@ async def test_homekit_stop(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = Mock() homekit.driver = Mock()
@ -653,7 +601,6 @@ async def test_homekit_reset_accessories(hass):
{entity_id: {}}, {entity_id: {}},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.bridge = Mock() homekit.bridge = Mock()
@ -702,7 +649,6 @@ async def test_homekit_too_many_accessories(hass, hk_driver):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.bridge = Mock() homekit.bridge = Mock()
@ -737,7 +683,6 @@ async def test_homekit_finds_linked_batteries(
{"light.demo": {}}, {"light.demo": {}},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = hk_driver homekit.driver = hk_driver
@ -832,7 +777,6 @@ async def test_setup_imported(hass):
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit: with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock() mock_homekit.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock() type(homekit).async_start = AsyncMock()
type(homekit).async_setup_zeroconf = AsyncMock()
assert await hass.config_entries.async_setup(entry.entry_id) assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -845,7 +789,6 @@ async def test_setup_imported(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
None, None,
None,
entry.entry_id, entry.entry_id,
) )
assert mock_homekit().setup.called is True assert mock_homekit().setup.called is True
@ -887,7 +830,6 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit: with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock() mock_homekit.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock() type(homekit).async_start = AsyncMock()
type(homekit).async_setup_zeroconf = AsyncMock()
assert await async_setup_component( assert await async_setup_component(
hass, "homekit", {"homekit": {CONF_NAME: BRIDGE_NAME, CONF_PORT: 12345}} hass, "homekit", {"homekit": {CONF_NAME: BRIDGE_NAME, CONF_PORT: 12345}}
) )
@ -902,7 +844,6 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
{}, {},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
None, None,
None,
entry.entry_id, entry.entry_id,
) )
assert mock_homekit().setup.called is True assert mock_homekit().setup.called is True
@ -932,7 +873,7 @@ async def test_raise_config_entry_not_ready(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_zeroconf): async def test_homekit_uses_system_zeroconf(hass, mock_zeroconf):
"""Test HomeKit uses system zeroconf.""" """Test HomeKit uses system zeroconf."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -941,13 +882,15 @@ async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_zeroconf):
) )
system_zc = await zeroconf.async_get_instance(hass) system_zc = await zeroconf.async_get_instance(hass)
with patch(f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver), patch( with patch(f"{PATH_HOMEKIT}.HomeKit.add_bridge_accessory"), patch(
f"{PATH_HOMEKIT}.HomeKit.async_start" f"{PATH_HOMEKIT}.show_setup_message"
), patch("pyhap.accessory_driver.AccessoryDriver.add_accessory"), patch(
"pyhap.accessory_driver.AccessoryDriver.start"
): ):
entry.add_to_hass(hass) entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id) assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert hk_driver.advertiser == system_zc assert hass.data[DOMAIN][entry.entry_id][HOMEKIT].driver.advertiser == system_zc
def _write_data(path: str, data: Dict) -> None: def _write_data(path: str, data: Dict) -> None:
@ -972,7 +915,6 @@ async def test_homekit_ignored_missing_devices(
{"light.demo": {}}, {"light.demo": {}},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = hk_driver homekit.driver = hk_driver
@ -1052,7 +994,6 @@ async def test_homekit_finds_linked_motion_sensors(
{"camera.camera_demo": {}}, {"camera.camera_demo": {}},
DEFAULT_SAFE_MODE, DEFAULT_SAFE_MODE,
advertise_ip=None, advertise_ip=None,
interface_choice=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
) )
homekit.driver = hk_driver homekit.driver = hk_driver