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

@ -28,9 +28,7 @@ from homeassistant.components.homekit.const import (
BRIDGE_SERIAL_NUMBER,
CONF_AUTO_START,
CONF_ENTRY_INDEX,
CONF_SAFE_MODE,
DEFAULT_PORT,
DEFAULT_SAFE_MODE,
DOMAIN,
HOMEKIT,
HOMEKIT_FILE,
@ -99,7 +97,7 @@ def debounce_patcher_fixture():
patcher.stop()
async def test_setup_min(hass):
async def test_setup_min(hass, mock_zeroconf):
"""Test async_setup with min config options."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -121,7 +119,6 @@ async def test_setup_min(hass):
None,
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -136,12 +133,12 @@ async def test_setup_min(hass):
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."""
entry = MockConfigEntry(
domain=DOMAIN,
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)
@ -158,7 +155,6 @@ async def test_setup_auto_start_disabled(hass):
"172.0.0.0",
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -191,7 +187,7 @@ async def test_setup_auto_start_disabled(hass):
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -205,7 +201,6 @@ async def test_homekit_setup(hass, hk_driver):
None,
{},
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -252,7 +247,6 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
"172.0.0.0",
{},
{},
None,
HOMEKIT_MODE_BRIDGE,
None,
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -291,7 +285,6 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver):
"0.0.0.0",
{},
{},
None,
HOMEKIT_MODE_BRIDGE,
"192.168.1.100",
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):
"""Add accessory if config exists and get_acc returns an accessory."""
entry = await async_init_integration(hass)
@ -352,7 +320,6 @@ async def test_homekit_add_accessory(hass, mock_zeroconf):
None,
lambda entity_id: True,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -394,7 +361,6 @@ async def test_homekit_warn_add_accessory_bridge(
None,
lambda entity_id: True,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -431,7 +397,6 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
None,
lambda entity_id: True,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -445,7 +410,7 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
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."""
entry = await async_init_integration(hass)
@ -457,7 +422,6 @@ async def test_homekit_entity_filter(hass):
None,
entity_filter,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -480,7 +444,7 @@ async def test_homekit_entity_filter(hass):
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."""
entry = await async_init_integration(hass)
@ -494,7 +458,6 @@ async def test_homekit_entity_glob_filter(hass):
None,
entity_filter,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -534,7 +497,6 @@ async def test_homekit_start(hass, hk_driver, device_reg, debounce_patcher):
None,
{},
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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
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."""
pin = b"123-45-678"
entry = MockConfigEntry(
@ -627,7 +591,6 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
None,
entity_filter,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -674,7 +637,6 @@ async def test_homekit_stop(hass):
None,
{},
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -702,7 +664,7 @@ async def test_homekit_stop(hass):
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."""
entry = MockConfigEntry(
domain=DOMAIN, data={CONF_NAME: "mock_name", CONF_PORT: 12345}
@ -715,7 +677,6 @@ async def test_homekit_reset_accessories(hass):
None,
{},
{entity_id: {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -751,7 +712,7 @@ async def test_homekit_reset_accessories(hass):
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."""
entry = await async_init_integration(hass)
@ -764,7 +725,6 @@ async def test_homekit_too_many_accessories(hass, hk_driver, caplog):
None,
entity_filter,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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(
hass, hk_driver, debounce_patcher, device_reg, entity_reg
hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
):
"""Test HomeKit start method."""
entry = await async_init_integration(hass)
@ -806,7 +766,6 @@ async def test_homekit_finds_linked_batteries(
None,
{},
{"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -881,7 +840,7 @@ async def test_homekit_finds_linked_batteries(
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."""
entry = await async_init_integration(hass)
@ -893,7 +852,6 @@ async def test_homekit_async_get_integration_fails(
None,
{},
{"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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."""
legacy_persist_file_path = hass.config.path(HOMEKIT_FILE)
legacy_aid_storage_path = hass.config.path(STORAGE_DIR, "homekit.aids")
@ -1000,7 +958,6 @@ async def test_setup_imported(hass):
None,
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -1030,7 +987,7 @@ async def test_setup_imported(hass):
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -1055,7 +1012,6 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
None,
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -1070,7 +1026,7 @@ async def test_yaml_updates_update_config_entry_for_name(hass):
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -1116,7 +1072,7 @@ def _write_data(path: str, data: Dict) -> None:
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."""
entry = await async_init_integration(hass)
@ -1128,7 +1084,6 @@ async def test_homekit_ignored_missing_devices(
None,
{},
{"light.demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
entry_id=entry.entry_id,
@ -1198,7 +1153,7 @@ async def test_homekit_ignored_missing_devices(
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."""
entry = await async_init_integration(hass)
@ -1210,7 +1165,6 @@ async def test_homekit_finds_linked_motion_sensors(
None,
{},
{"camera.camera_demo": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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(
hass, hk_driver, debounce_patcher, device_reg, entity_reg
hass, hk_driver, debounce_patcher, device_reg, entity_reg, mock_zeroconf
):
"""Test HomeKit start method."""
entry = await async_init_integration(hass)
@ -1286,7 +1240,6 @@ async def test_homekit_finds_linked_humidity_sensors(
None,
{},
{"humidifier.humidifier": {}},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
advertise_ip=None,
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."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -1376,7 +1329,6 @@ async def test_reload(hass):
None,
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -1413,7 +1365,6 @@ async def test_reload(hass):
None,
ANY,
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_BRIDGE,
None,
entry.entry_id,
@ -1439,7 +1390,6 @@ async def test_homekit_start_in_accessory_mode(
None,
{},
{},
DEFAULT_SAFE_MODE,
HOMEKIT_MODE_ACCESSORY,
advertise_ip=None,
entry_id=entry.entry_id,