|
|
|
@ -142,7 +142,7 @@ def _mock_pyhap_bridge():
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_min(hass, mock_zeroconf):
|
|
|
|
|
async def test_setup_min(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test async_setup with min config options."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -181,7 +181,7 @@ async def test_setup_min(hass, mock_zeroconf):
|
|
|
|
|
assert mock_homekit().async_start.called is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_setup(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
async def test_homekit_setup(hass, hk_driver, mock_async_zeroconf):
|
|
|
|
|
"""Test setup of bridge and driver."""
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
@ -226,7 +226,7 @@ async def test_homekit_setup(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
assert homekit.driver.safe_mode is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_setup_ip_address(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
async def test_homekit_setup_ip_address(hass, hk_driver, mock_async_zeroconf):
|
|
|
|
|
"""Test setup with given IP address."""
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
@ -247,11 +247,10 @@ async def test_homekit_setup_ip_address(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
entry_title=entry.title,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mock_zeroconf = MagicMock()
|
|
|
|
|
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
|
|
|
|
|
uuid = await hass.helpers.instance_id.async_get()
|
|
|
|
|
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
|
|
|
|
|
await hass.async_add_executor_job(homekit.setup, mock_zeroconf, uuid)
|
|
|
|
|
await hass.async_add_executor_job(homekit.setup, mock_async_zeroconf, uuid)
|
|
|
|
|
mock_driver.assert_called_with(
|
|
|
|
|
hass,
|
|
|
|
|
entry.entry_id,
|
|
|
|
@ -262,12 +261,12 @@ async def test_homekit_setup_ip_address(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
port=DEFAULT_PORT,
|
|
|
|
|
persist_file=path,
|
|
|
|
|
advertised_address=None,
|
|
|
|
|
async_zeroconf_instance=mock_zeroconf,
|
|
|
|
|
async_zeroconf_instance=mock_async_zeroconf,
|
|
|
|
|
zeroconf_server=f"{uuid}-hap.local.",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_async_zeroconf):
|
|
|
|
|
"""Test setup with given IP address to advertise."""
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
@ -308,7 +307,7 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_add_accessory(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_add_accessory(hass, mock_async_zeroconf):
|
|
|
|
|
"""Add accessory if config exists and get_acc returns an accessory."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -345,7 +344,7 @@ async def test_homekit_add_accessory(hass, mock_zeroconf):
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("acc_category", [CATEGORY_TELEVISION, CATEGORY_CAMERA])
|
|
|
|
|
async def test_homekit_warn_add_accessory_bridge(
|
|
|
|
|
hass, acc_category, mock_zeroconf, caplog
|
|
|
|
|
hass, acc_category, mock_async_zeroconf, caplog
|
|
|
|
|
):
|
|
|
|
|
"""Test we warn when adding cameras or tvs to a bridge."""
|
|
|
|
|
|
|
|
|
@ -373,7 +372,7 @@ async def test_homekit_warn_add_accessory_bridge(
|
|
|
|
|
assert "accessory mode" in caplog.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_remove_accessory(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_remove_accessory(hass, mock_async_zeroconf):
|
|
|
|
|
"""Remove accessory from bridge."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
|
|
|
|
|
@ -391,7 +390,7 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
|
|
|
|
|
assert len(homekit.bridge.accessories) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_entity_filter(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_entity_filter(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test the entity filter."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
|
|
|
|
|
@ -410,7 +409,7 @@ async def test_homekit_entity_filter(hass, mock_zeroconf):
|
|
|
|
|
assert hass.states.get("light.demo") not in filtered_states
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_entity_glob_filter(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_entity_glob_filter(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test the entity filter."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
|
|
|
|
|
@ -434,7 +433,7 @@ async def test_homekit_entity_glob_filter(hass, mock_zeroconf):
|
|
|
|
|
assert hass.states.get("light.included_test") in filtered_states
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start(hass, hk_driver, mock_zeroconf, device_reg):
|
|
|
|
|
async def test_homekit_start(hass, hk_driver, mock_async_zeroconf, device_reg):
|
|
|
|
|
"""Test HomeKit start method."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
|
|
|
|
|
@ -509,7 +508,9 @@ async def test_homekit_start(hass, hk_driver, mock_zeroconf, device_reg):
|
|
|
|
|
assert homekit.driver.state.config_version == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
async def test_homekit_start_with_a_broken_accessory(
|
|
|
|
|
hass, hk_driver, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method."""
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN, data={CONF_NAME: "mock_name", CONF_PORT: 12345}
|
|
|
|
@ -549,7 +550,7 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, mock_zeroc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start_with_a_device(
|
|
|
|
|
hass, hk_driver, mock_zeroconf, demo_cleanup, device_reg, entity_reg
|
|
|
|
|
hass, hk_driver, mock_async_zeroconf, demo_cleanup, device_reg, entity_reg
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method with a device."""
|
|
|
|
|
|
|
|
|
@ -611,7 +612,7 @@ async def test_homekit_stop(hass):
|
|
|
|
|
assert homekit.driver.async_stop.called is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_accessories(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_accessories(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit accessories."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -656,7 +657,7 @@ async def test_homekit_reset_accessories(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_READY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_unpair(hass, device_reg, mock_zeroconf):
|
|
|
|
|
async def test_homekit_unpair(hass, device_reg, mock_async_zeroconf):
|
|
|
|
|
"""Test unpairing HomeKit accessories."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -698,7 +699,7 @@ async def test_homekit_unpair(hass, device_reg, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_unpair_missing_device_id(hass, device_reg, mock_zeroconf):
|
|
|
|
|
async def test_homekit_unpair_missing_device_id(hass, device_reg, mock_async_zeroconf):
|
|
|
|
|
"""Test unpairing HomeKit accessories with invalid device id."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -736,7 +737,7 @@ async def test_homekit_unpair_missing_device_id(hass, device_reg, mock_zeroconf)
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_unpair_not_homekit_device(hass, device_reg, mock_zeroconf):
|
|
|
|
|
async def test_homekit_unpair_not_homekit_device(hass, device_reg, mock_async_zeroconf):
|
|
|
|
|
"""Test unpairing HomeKit accessories with a non-homekit device id."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -784,7 +785,7 @@ async def test_homekit_unpair_not_homekit_device(hass, device_reg, mock_zeroconf
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_accessories_not_supported(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_accessories_not_supported(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit accessories with an unsupported entity."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -828,7 +829,7 @@ async def test_homekit_reset_accessories_not_supported(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_accessories_state_missing(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_accessories_state_missing(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit accessories when the state goes missing."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -870,7 +871,7 @@ async def test_homekit_reset_accessories_state_missing(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_accessories_not_bridged(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_accessories_not_bridged(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit accessories when the state is not bridged."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -912,7 +913,7 @@ async def test_homekit_reset_accessories_not_bridged(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_single_accessory(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_single_accessory(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit single accessory."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -951,7 +952,7 @@ async def test_homekit_reset_single_accessory(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_READY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_single_accessory_unsupported(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_single_accessory_unsupported(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit single accessory with an unsupported entity."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -988,7 +989,7 @@ async def test_homekit_reset_single_accessory_unsupported(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_single_accessory_state_missing(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_single_accessory_state_missing(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit single accessory when the state goes missing."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -1024,7 +1025,7 @@ async def test_homekit_reset_single_accessory_state_missing(hass, mock_zeroconf)
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_reset_single_accessory_no_match(hass, mock_zeroconf):
|
|
|
|
|
async def test_homekit_reset_single_accessory_no_match(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test resetting HomeKit single accessory when the entity id does not match."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -1060,7 +1061,9 @@ async def test_homekit_reset_single_accessory_no_match(hass, mock_zeroconf):
|
|
|
|
|
homekit.status = STATUS_STOPPED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_too_many_accessories(hass, hk_driver, caplog, mock_zeroconf):
|
|
|
|
|
async def test_homekit_too_many_accessories(
|
|
|
|
|
hass, hk_driver, caplog, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test adding too many accessories to HomeKit."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
|
|
|
|
|
@ -1090,7 +1093,7 @@ async def test_homekit_too_many_accessories(hass, hk_driver, caplog, mock_zeroco
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_finds_linked_batteries(
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_zeroconf
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1161,7 +1164,7 @@ async def test_homekit_finds_linked_batteries(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_async_get_integration_fails(
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_zeroconf
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test that we continue if async_get_integration fails."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1230,7 +1233,7 @@ async def test_homekit_async_get_integration_fails(
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_yaml_updates_update_config_entry_for_name(hass, mock_zeroconf):
|
|
|
|
|
async def test_yaml_updates_update_config_entry_for_name(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test async_setup with imported config."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -1274,7 +1277,7 @@ async def test_yaml_updates_update_config_entry_for_name(hass, mock_zeroconf):
|
|
|
|
|
mock_homekit().async_start.assert_called()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_zeroconf):
|
|
|
|
|
async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_async_zeroconf):
|
|
|
|
|
"""Test HomeKit uses system zeroconf."""
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
@ -1306,7 +1309,7 @@ def _write_data(path: str, data: dict) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_ignored_missing_devices(
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_zeroconf
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit handles a device in the entity registry but missing from the device registry."""
|
|
|
|
|
|
|
|
|
@ -1376,7 +1379,7 @@ async def test_homekit_ignored_missing_devices(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_finds_linked_motion_sensors(
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_zeroconf
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1438,7 +1441,7 @@ async def test_homekit_finds_linked_motion_sensors(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_finds_linked_humidity_sensors(
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_zeroconf
|
|
|
|
|
hass, hk_driver, device_reg, entity_reg, mock_async_zeroconf
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1502,7 +1505,7 @@ async def test_homekit_finds_linked_humidity_sensors(
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_reload(hass, mock_zeroconf):
|
|
|
|
|
async def test_reload(hass, mock_async_zeroconf):
|
|
|
|
|
"""Test we can reload from yaml."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
@ -1574,7 +1577,7 @@ async def test_reload(hass, mock_zeroconf):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start_in_accessory_mode(
|
|
|
|
|
hass, hk_driver, mock_zeroconf, device_reg
|
|
|
|
|
hass, hk_driver, mock_async_zeroconf, device_reg
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method in accessory mode."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1605,7 +1608,7 @@ async def test_homekit_start_in_accessory_mode(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start_in_accessory_mode_unsupported_entity(
|
|
|
|
|
hass, hk_driver, mock_zeroconf, device_reg, caplog
|
|
|
|
|
hass, hk_driver, mock_async_zeroconf, device_reg, caplog
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method in accessory mode with an unsupported entity."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1635,7 +1638,7 @@ async def test_homekit_start_in_accessory_mode_unsupported_entity(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_homekit_start_in_accessory_mode_missing_entity(
|
|
|
|
|
hass, hk_driver, mock_zeroconf, device_reg, caplog
|
|
|
|
|
hass, hk_driver, mock_async_zeroconf, device_reg, caplog
|
|
|
|
|
):
|
|
|
|
|
"""Test HomeKit start method in accessory mode when entity is not available."""
|
|
|
|
|
entry = await async_init_integration(hass)
|
|
|
|
@ -1659,7 +1662,7 @@ async def test_homekit_start_in_accessory_mode_missing_entity(
|
|
|
|
|
assert "entity not available" in caplog.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_wait_for_port_to_free(hass, hk_driver, mock_zeroconf, caplog):
|
|
|
|
|
async def test_wait_for_port_to_free(hass, hk_driver, mock_async_zeroconf, caplog):
|
|
|
|
|
"""Test we wait for the port to free before declaring unload success."""
|
|
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
|