Remove safe mode from HomeKit (#45028)

Safe mode was added to work around a race condition where
the mdns announcment was sent too early and would cause
pairing to fail. Since this has been corrected in
HAP-python, there is no longer a need to have
safe mode.
This commit is contained in:
J. Nick Koston 2021-01-11 03:26:09 -10:00 committed by GitHub
parent e584902b8b
commit af21893652
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 194 deletions

View file

@ -114,6 +114,7 @@ def _has_all_unique_names_and_ports(bridges):
BRIDGE_SCHEMA = vol.All( BRIDGE_SCHEMA = vol.All(
cv.deprecated(CONF_ZEROCONF_DEFAULT_INTERFACE), cv.deprecated(CONF_ZEROCONF_DEFAULT_INTERFACE),
cv.deprecated(CONF_SAFE_MODE),
vol.Schema( vol.Schema(
{ {
vol.Optional(CONF_HOMEKIT_MODE, default=DEFAULT_HOMEKIT_MODE): vol.In( vol.Optional(CONF_HOMEKIT_MODE, default=DEFAULT_HOMEKIT_MODE): vol.In(
@ -246,7 +247,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
homekit_mode = options.get(CONF_HOMEKIT_MODE, DEFAULT_HOMEKIT_MODE) homekit_mode = options.get(CONF_HOMEKIT_MODE, DEFAULT_HOMEKIT_MODE)
entity_config = options.get(CONF_ENTITY_CONFIG, {}).copy() entity_config = options.get(CONF_ENTITY_CONFIG, {}).copy()
auto_start = options.get(CONF_AUTO_START, DEFAULT_AUTO_START) auto_start = options.get(CONF_AUTO_START, DEFAULT_AUTO_START)
safe_mode = options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE)
entity_filter = FILTER_SCHEMA(options.get(CONF_FILTER, {})) entity_filter = FILTER_SCHEMA(options.get(CONF_FILTER, {}))
homekit = HomeKit( homekit = HomeKit(
@ -256,7 +256,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
ip_address, ip_address,
entity_filter, entity_filter,
entity_config, entity_config,
safe_mode,
homekit_mode, homekit_mode,
advertise_ip, advertise_ip,
entry.entry_id, entry.entry_id,
@ -421,7 +420,6 @@ class HomeKit:
ip_address, ip_address,
entity_filter, entity_filter,
entity_config, entity_config,
safe_mode,
homekit_mode, homekit_mode,
advertise_ip=None, advertise_ip=None,
entry_id=None, entry_id=None,
@ -433,7 +431,6 @@ class HomeKit:
self._ip_address = ip_address self._ip_address = ip_address
self._filter = entity_filter self._filter = entity_filter
self._config = entity_config self._config = entity_config
self._safe_mode = safe_mode
self._advertise_ip = advertise_ip self._advertise_ip = advertise_ip
self._entry_id = entry_id self._entry_id = entry_id
self._homekit_mode = homekit_mode self._homekit_mode = homekit_mode
@ -470,10 +467,6 @@ class HomeKit:
else: else:
self.driver.persist() self.driver.persist()
if self._safe_mode:
_LOGGER.debug("Safe_mode selected for %s", self._name)
self.driver.safe_mode = True
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."""
if not self.bridge: if not self.bridge:

View file

@ -21,12 +21,10 @@ from .const import (
CONF_ENTITY_CONFIG, CONF_ENTITY_CONFIG,
CONF_FILTER, CONF_FILTER,
CONF_HOMEKIT_MODE, CONF_HOMEKIT_MODE,
CONF_SAFE_MODE,
CONF_VIDEO_CODEC, CONF_VIDEO_CODEC,
DEFAULT_AUTO_START, DEFAULT_AUTO_START,
DEFAULT_CONFIG_FLOW_PORT, DEFAULT_CONFIG_FLOW_PORT,
DEFAULT_HOMEKIT_MODE, DEFAULT_HOMEKIT_MODE,
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_ACCESSORY, HOMEKIT_MODE_ACCESSORY,
HOMEKIT_MODES, HOMEKIT_MODES,
SHORT_BRIDGE_NAME, SHORT_BRIDGE_NAME,
@ -217,40 +215,32 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
async def async_step_advanced(self, user_input=None): async def async_step_advanced(self, user_input=None):
"""Choose advanced options.""" """Choose advanced options."""
if user_input is not None: if not self.show_advanced_options or user_input is not None:
self.homekit_options.update(user_input) if user_input:
for key in (CONF_DOMAINS, CONF_ENTITIES): self.homekit_options.update(user_input)
if key in self.homekit_options:
del self.homekit_options[key]
return self.async_create_entry(title="", data=self.homekit_options)
schema_base = {}
if self.show_advanced_options:
schema_base[
vol.Optional(
CONF_AUTO_START,
default=self.homekit_options.get(
CONF_AUTO_START, DEFAULT_AUTO_START
),
)
] = bool
else:
self.homekit_options[CONF_AUTO_START] = self.homekit_options.get( self.homekit_options[CONF_AUTO_START] = self.homekit_options.get(
CONF_AUTO_START, DEFAULT_AUTO_START CONF_AUTO_START, DEFAULT_AUTO_START
) )
schema_base.update( for key in (CONF_DOMAINS, CONF_ENTITIES):
{ if key in self.homekit_options:
vol.Optional( del self.homekit_options[key]
CONF_SAFE_MODE,
default=self.homekit_options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE), return self.async_create_entry(title="", data=self.homekit_options)
): bool
}
)
return self.async_show_form( return self.async_show_form(
step_id="advanced", data_schema=vol.Schema(schema_base) step_id="advanced",
data_schema=vol.Schema(
{
vol.Optional(
CONF_AUTO_START,
default=self.homekit_options.get(
CONF_AUTO_START, DEFAULT_AUTO_START
),
): bool
}
),
) )
async def async_step_cameras(self, user_input=None): async def async_step_cameras(self, user_input=None):

View file

@ -30,8 +30,7 @@
}, },
"advanced": { "advanced": {
"data": { "data": {
"auto_start": "Autostart (disable if you are calling the homekit.start service manually)", "auto_start": "Autostart (disable if you are calling the homekit.start service manually)"
"safe_mode": "Safe Mode (enable only if pairing fails)"
}, },
"description": "These settings only need to be adjusted if HomeKit is not functional.", "description": "These settings only need to be adjusted if HomeKit is not functional.",
"title": "Advanced Configuration" "title": "Advanced Configuration"

View file

@ -30,8 +30,7 @@
}, },
"advanced": { "advanced": {
"data": { "data": {
"auto_start": "Autostart (disable if you are calling the homekit.start service manually)", "auto_start": "Autostart (disable if you are calling the homekit.start service manually)"
"safe_mode": "Safe Mode (enable only if pairing fails)"
}, },
"description": "These settings only need to be adjusted if HomeKit is not functional.", "description": "These settings only need to be adjusted if HomeKit is not functional.",
"title": "Advanced Configuration" "title": "Advanced Configuration"

View file

@ -28,7 +28,6 @@ def _mock_config_entry_with_options_populated():
], ],
"exclude_entities": ["climate.front_gate"], "exclude_entities": ["climate.front_gate"],
}, },
"safe_mode": False,
}, },
) )
@ -159,7 +158,7 @@ async def test_options_flow_exclude_mode_advanced(auto_start, 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": auto_start, "safe_mode": True}, user_input={"auto_start": auto_start},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -172,7 +171,6 @@ async def test_options_flow_exclude_mode_advanced(auto_start, hass):
"include_domains": ["fan", "vacuum", "climate", "humidifier"], "include_domains": ["fan", "vacuum", "climate", "humidifier"],
"include_entities": [], "include_entities": [],
}, },
"safe_mode": True,
} }
@ -204,16 +202,7 @@ async def test_options_flow_exclude_mode_basic(hass):
result["flow_id"], result["flow_id"],
user_input={"entities": ["climate.old"], "include_exclude_mode": "exclude"}, user_input={"entities": ["climate.old"], "include_exclude_mode": "exclude"},
) )
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result2["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result3 = await hass.config_entries.options.async_configure(
result2["flow_id"],
user_input={"safe_mode": True},
)
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -223,7 +212,6 @@ async def test_options_flow_exclude_mode_basic(hass):
"include_domains": ["fan", "vacuum", "climate"], "include_domains": ["fan", "vacuum", "climate"],
"include_entities": [], "include_entities": [],
}, },
"safe_mode": True,
} }
@ -257,16 +245,7 @@ async def test_options_flow_include_mode_basic(hass):
result["flow_id"], result["flow_id"],
user_input={"entities": ["climate.new"], "include_exclude_mode": "include"}, user_input={"entities": ["climate.new"], "include_exclude_mode": "include"},
) )
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result2["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result3 = await hass.config_entries.options.async_configure(
result2["flow_id"],
user_input={"safe_mode": True},
)
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -276,7 +255,6 @@ async def test_options_flow_include_mode_basic(hass):
"include_domains": ["fan", "vacuum"], "include_domains": ["fan", "vacuum"],
"include_entities": ["climate.new"], "include_entities": ["climate.new"],
}, },
"safe_mode": True,
} }
@ -323,16 +301,7 @@ async def test_options_flow_exclude_mode_with_cameras(hass):
user_input={"camera_copy": ["camera.native_h264"]}, user_input={"camera_copy": ["camera.native_h264"]},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure(
result3["flow_id"],
user_input={"safe_mode": True},
)
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -343,7 +312,6 @@ async def test_options_flow_exclude_mode_with_cameras(hass):
"include_entities": [], "include_entities": [],
}, },
"entity_config": {"camera.native_h264": {"video_codec": "copy"}}, "entity_config": {"camera.native_h264": {"video_codec": "copy"}},
"safe_mode": True,
} }
# Now run though again and verify we can turn off copy # Now run though again and verify we can turn off copy
@ -378,16 +346,7 @@ async def test_options_flow_exclude_mode_with_cameras(hass):
user_input={"camera_copy": []}, user_input={"camera_copy": []},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure(
result3["flow_id"],
user_input={"safe_mode": True},
)
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -398,7 +357,6 @@ async def test_options_flow_exclude_mode_with_cameras(hass):
"include_entities": [], "include_entities": [],
}, },
"entity_config": {"camera.native_h264": {}}, "entity_config": {"camera.native_h264": {}},
"safe_mode": True,
} }
@ -445,16 +403,7 @@ async def test_options_flow_include_mode_with_cameras(hass):
user_input={"camera_copy": ["camera.native_h264"]}, user_input={"camera_copy": ["camera.native_h264"]},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure(
result3["flow_id"],
user_input={"safe_mode": True},
)
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -465,7 +414,6 @@ async def test_options_flow_include_mode_with_cameras(hass):
"include_entities": ["camera.native_h264", "camera.transcode_h264"], "include_entities": ["camera.native_h264", "camera.transcode_h264"],
}, },
"entity_config": {"camera.native_h264": {"video_codec": "copy"}}, "entity_config": {"camera.native_h264": {"video_codec": "copy"}},
"safe_mode": True,
} }
# Now run though again and verify we can turn off copy # Now run though again and verify we can turn off copy
@ -500,16 +448,7 @@ async def test_options_flow_include_mode_with_cameras(hass):
user_input={"camera_copy": []}, user_input={"camera_copy": []},
) )
assert result3["type"] == data_entry_flow.RESULT_TYPE_FORM assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result4 = await hass.config_entries.options.async_configure(
result3["flow_id"],
user_input={"safe_mode": True},
)
assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "bridge", "mode": "bridge",
@ -520,7 +459,6 @@ async def test_options_flow_include_mode_with_cameras(hass):
"include_entities": [], "include_entities": [],
}, },
"entity_config": {"camera.native_h264": {}}, "entity_config": {"camera.native_h264": {}},
"safe_mode": True,
} }
@ -543,7 +481,6 @@ async def test_options_flow_blocked_when_from_yaml(hass):
], ],
"exclude_entities": ["climate.front_gate"], "exclude_entities": ["climate.front_gate"],
}, },
"safe_mode": False,
}, },
source=SOURCE_IMPORT, source=SOURCE_IMPORT,
) )
@ -594,16 +531,7 @@ async def test_options_flow_include_mode_basic_accessory(hass):
result["flow_id"], result["flow_id"],
user_input={"entities": "media_player.tv"}, user_input={"entities": "media_player.tv"},
) )
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result2["step_id"] == "advanced"
with patch("homeassistant.components.homekit.async_setup_entry", return_value=True):
result3 = await hass.config_entries.options.async_configure(
result2["flow_id"],
user_input={"safe_mode": False},
)
assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert config_entry.options == { assert config_entry.options == {
"auto_start": True, "auto_start": True,
"mode": "accessory", "mode": "accessory",
@ -613,5 +541,4 @@ async def test_options_flow_include_mode_basic_accessory(hass):
"include_domains": [], "include_domains": [],
"include_entities": ["media_player.tv"], "include_entities": ["media_player.tv"],
}, },
"safe_mode": False,
} }

View file

@ -28,9 +28,7 @@ from homeassistant.components.homekit.const import (
BRIDGE_SERIAL_NUMBER, BRIDGE_SERIAL_NUMBER,
CONF_AUTO_START, CONF_AUTO_START,
CONF_ENTRY_INDEX, CONF_ENTRY_INDEX,
CONF_SAFE_MODE,
DEFAULT_PORT, DEFAULT_PORT,
DEFAULT_SAFE_MODE,
DOMAIN, DOMAIN,
HOMEKIT, HOMEKIT,
HOMEKIT_FILE, HOMEKIT_FILE,
@ -99,7 +97,7 @@ def debounce_patcher_fixture():
patcher.stop() patcher.stop()
async def test_setup_min(hass): async def test_setup_min(hass, mock_zeroconf):
"""Test async_setup with min config options.""" """Test async_setup with min config options."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -121,7 +119,6 @@ async def test_setup_min(hass):
None, None,
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -136,12 +133,12 @@ async def test_setup_min(hass):
mock_homekit().async_start.assert_called() mock_homekit().async_start.assert_called()
async def test_setup_auto_start_disabled(hass): async def test_setup_auto_start_disabled(hass, mock_zeroconf):
"""Test async_setup with auto start disabled and test service calls.""" """Test async_setup with auto start disabled and test service calls."""
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={CONF_AUTO_START: False, CONF_SAFE_MODE: DEFAULT_SAFE_MODE}, options={CONF_AUTO_START: False},
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -158,7 +155,6 @@ async def test_setup_auto_start_disabled(hass):
"172.0.0.0", "172.0.0.0",
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -191,7 +187,7 @@ async def test_setup_auto_start_disabled(hass):
assert homekit.async_start.called is False assert homekit.async_start.called is False
async def test_homekit_setup(hass, hk_driver): async def test_homekit_setup(hass, hk_driver, mock_zeroconf):
"""Test setup of bridge and driver.""" """Test setup of bridge and driver."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -205,7 +201,6 @@ async def test_homekit_setup(hass, hk_driver):
None, None,
{}, {},
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -238,7 +233,7 @@ async def test_homekit_setup(hass, hk_driver):
assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1 assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1
async def test_homekit_setup_ip_address(hass, hk_driver): async def test_homekit_setup_ip_address(hass, hk_driver, mock_zeroconf):
"""Test setup with given IP address.""" """Test setup with given IP address."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -252,7 +247,6 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
"172.0.0.0", "172.0.0.0",
{}, {},
{}, {},
None,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -277,7 +271,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
) )
async def test_homekit_setup_advertise_ip(hass, hk_driver): async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_zeroconf):
"""Test setup with given IP address to advertise.""" """Test setup with given IP address to advertise."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -291,7 +285,6 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
"0.0.0.0", "0.0.0.0",
{}, {},
{}, {},
None,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
"192.168.1.100", "192.168.1.100",
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -316,31 +309,6 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
) )
async def test_homekit_setup_safe_mode(hass, hk_driver):
"""Test if safe_mode flag is set."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_NAME: "mock_name", CONF_PORT: 12345},
source=SOURCE_IMPORT,
)
homekit = HomeKit(
hass,
BRIDGE_NAME,
DEFAULT_PORT,
None,
{},
{},
True,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
)
with patch(f"{PATH_HOMEKIT}.accessories.HomeDriver", return_value=hk_driver):
await hass.async_add_executor_job(homekit.setup, MagicMock())
assert homekit.driver.safe_mode is True
async def test_homekit_add_accessory(hass, mock_zeroconf): async def test_homekit_add_accessory(hass, mock_zeroconf):
"""Add accessory if config exists and get_acc returns an accessory.""" """Add accessory if config exists and get_acc returns an accessory."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -352,7 +320,6 @@ async def test_homekit_add_accessory(hass, mock_zeroconf):
None, None,
lambda entity_id: True, lambda entity_id: True,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -394,7 +361,6 @@ async def test_homekit_warn_add_accessory_bridge(
None, None,
lambda entity_id: True, lambda entity_id: True,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -431,7 +397,6 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
None, None,
lambda entity_id: True, lambda entity_id: True,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -445,7 +410,7 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
assert len(mock_bridge.accessories) == 0 assert len(mock_bridge.accessories) == 0
async def test_homekit_entity_filter(hass): async def test_homekit_entity_filter(hass, mock_zeroconf):
"""Test the entity filter.""" """Test the entity filter."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -457,7 +422,6 @@ async def test_homekit_entity_filter(hass):
None, None,
entity_filter, entity_filter,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -480,7 +444,7 @@ async def test_homekit_entity_filter(hass):
assert mock_get_acc.called is False assert mock_get_acc.called is False
async def test_homekit_entity_glob_filter(hass): async def test_homekit_entity_glob_filter(hass, mock_zeroconf):
"""Test the entity filter.""" """Test the entity filter."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -494,7 +458,6 @@ async def test_homekit_entity_glob_filter(hass):
None, None,
entity_filter, entity_filter,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -534,7 +497,6 @@ async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
None, None,
{}, {},
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -611,7 +573,9 @@ async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
assert len(device_reg.devices) == 1 assert len(device_reg.devices) == 1
async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_patcher): async def test_homekit_start_with_a_broken_accessory(
hass, hk_driver, debounce_patcher, mock_zeroconf
):
"""Test HomeKit start method.""" """Test HomeKit start method."""
pin = b"123-45-678" pin = b"123-45-678"
entry = MockConfigEntry( entry = MockConfigEntry(
@ -627,7 +591,6 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
None, None,
entity_filter, entity_filter,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -674,7 +637,6 @@ async def test_homekit_stop(hass):
None, None,
{}, {},
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -702,7 +664,7 @@ async def test_homekit_stop(hass):
assert homekit.driver.async_stop.called is True assert homekit.driver.async_stop.called is True
async def test_homekit_reset_accessories(hass): async def test_homekit_reset_accessories(hass, mock_zeroconf):
"""Test adding too many accessories to HomeKit.""" """Test adding too many accessories to HomeKit."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, data={CONF_NAME: "mock_name", CONF_PORT: 12345} domain=DOMAIN, data={CONF_NAME: "mock_name", CONF_PORT: 12345}
@ -715,7 +677,6 @@ async def test_homekit_reset_accessories(hass):
None, None,
{}, {},
{entity_id: {}}, {entity_id: {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -751,7 +712,7 @@ async def test_homekit_reset_accessories(hass):
homekit.status = STATUS_READY homekit.status = STATUS_READY
async def test_homekit_too_many_accessories(hass, hk_driver, caplog): async def test_homekit_too_many_accessories(hass, hk_driver, caplog, mock_zeroconf):
"""Test adding too many accessories to HomeKit.""" """Test adding too many accessories to HomeKit."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -764,7 +725,6 @@ async def test_homekit_too_many_accessories(hass, hk_driver, caplog):
None, None,
entity_filter, entity_filter,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -794,7 +754,7 @@ async def test_homekit_too_many_accessories(hass, hk_driver, caplog):
async def test_homekit_finds_linked_batteries( async def test_homekit_finds_linked_batteries(
hass, hk_driver, debounce_patcher, device_reg, entity_reg hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
): ):
"""Test HomeKit start method.""" """Test HomeKit start method."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -806,7 +766,6 @@ async def test_homekit_finds_linked_batteries(
None, None,
{}, {},
{"light.demo": {}}, {"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -881,7 +840,7 @@ async def test_homekit_finds_linked_batteries(
async def test_homekit_async_get_integration_fails( async def test_homekit_async_get_integration_fails(
hass, hk_driver, debounce_patcher, device_reg, entity_reg hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
): ):
"""Test that we continue if async_get_integration fails.""" """Test that we continue if async_get_integration fails."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -893,7 +852,6 @@ async def test_homekit_async_get_integration_fails(
None, None,
{}, {},
{"light.demo": {}}, {"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -966,7 +924,7 @@ async def test_homekit_async_get_integration_fails(
) )
async def test_setup_imported(hass): async def test_setup_imported(hass, mock_zeroconf):
"""Test async_setup with imported config options.""" """Test async_setup with imported config options."""
legacy_persist_file_path = hass.config.path(HOMEKIT_FILE) legacy_persist_file_path = hass.config.path(HOMEKIT_FILE)
legacy_aid_storage_path = hass.config.path(STORAGE_DIR, "homekit.aids") legacy_aid_storage_path = hass.config.path(STORAGE_DIR, "homekit.aids")
@ -1000,7 +958,6 @@ async def test_setup_imported(hass):
None, None,
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -1030,7 +987,7 @@ async def test_setup_imported(hass):
os.unlink(migrated_aid_file_path) os.unlink(migrated_aid_file_path)
async def test_yaml_updates_update_config_entry_for_name(hass): async def test_yaml_updates_update_config_entry_for_name(hass, mock_zeroconf):
"""Test async_setup with imported config.""" """Test async_setup with imported config."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -1055,7 +1012,6 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
None, None,
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -1070,7 +1026,7 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
mock_homekit().async_start.assert_called() mock_homekit().async_start.assert_called()
async def test_raise_config_entry_not_ready(hass): async def test_raise_config_entry_not_ready(hass, mock_zeroconf):
"""Test async_setup when the port is not available.""" """Test async_setup when the port is not available."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -1116,7 +1072,7 @@ def _write_data(path: str, data: Dict) -> None:
async def test_homekit_ignored_missing_devices( async def test_homekit_ignored_missing_devices(
hass, hk_driver, debounce_patcher, device_reg, entity_reg hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
): ):
"""Test HomeKit handles a device in the entity registry but missing from the device registry.""" """Test HomeKit handles a device in the entity registry but missing from the device registry."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -1128,7 +1084,6 @@ async def test_homekit_ignored_missing_devices(
None, None,
{}, {},
{"light.demo": {}}, {"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -1198,7 +1153,7 @@ async def test_homekit_ignored_missing_devices(
async def test_homekit_finds_linked_motion_sensors( async def test_homekit_finds_linked_motion_sensors(
hass, hk_driver, debounce_patcher, device_reg, entity_reg hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
): ):
"""Test HomeKit start method.""" """Test HomeKit start method."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -1210,7 +1165,6 @@ async def test_homekit_finds_linked_motion_sensors(
None, None,
{}, {},
{"camera.camera_demo": {}}, {"camera.camera_demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -1274,7 +1228,7 @@ async def test_homekit_finds_linked_motion_sensors(
async def test_homekit_finds_linked_humidity_sensors( async def test_homekit_finds_linked_humidity_sensors(
hass, hk_driver, debounce_patcher, device_reg, entity_reg hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
): ):
"""Test HomeKit start method.""" """Test HomeKit start method."""
entry = await async_init_integration(hass) entry = await async_init_integration(hass)
@ -1286,7 +1240,6 @@ async def test_homekit_finds_linked_humidity_sensors(
None, None,
{}, {},
{"humidifier.humidifier": {}}, {"humidifier.humidifier": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,
@ -1351,7 +1304,7 @@ async def test_homekit_finds_linked_humidity_sensors(
) )
async def test_reload(hass): async def test_reload(hass, mock_zeroconf):
"""Test we can reload from yaml.""" """Test we can reload from yaml."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -1376,7 +1329,6 @@ async def test_reload(hass):
None, None,
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -1413,7 +1365,6 @@ async def test_reload(hass):
None, None,
ANY, ANY,
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE, HOMEKIT_MODE_BRIDGE,
None, None,
entry.entry_id, entry.entry_id,
@ -1439,7 +1390,6 @@ async def test_homekit_start_in_accessory_mode(
None, None,
{}, {},
{}, {},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_ACCESSORY, HOMEKIT_MODE_ACCESSORY,
advertise_ip=None, advertise_ip=None,
entry_id=entry.entry_id, entry_id=entry.entry_id,