mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Update h* tests to use entity & device registry fixtures (#103866)
* Update h* tests to use entity & device registry fixtures * Add missed lines
This commit is contained in:
parent
3a531f5698
commit
eda475fe25
@ -249,6 +249,8 @@ async def test_updates_from_players_changed(
|
|||||||
|
|
||||||
async def test_updates_from_players_changed_new_ids(
|
async def test_updates_from_players_changed_new_ids(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
config_entry,
|
config_entry,
|
||||||
config,
|
config,
|
||||||
controller,
|
controller,
|
||||||
@ -257,8 +259,6 @@ async def test_updates_from_players_changed_new_ids(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test player updates from changes to available players."""
|
"""Test player updates from changes to available players."""
|
||||||
await setup_platform(hass, config_entry, config)
|
await setup_platform(hass, config_entry, config)
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
player = controller.players[1]
|
player = controller.players[1]
|
||||||
event = asyncio.Event()
|
event = asyncio.Event()
|
||||||
|
|
||||||
|
@ -1664,7 +1664,9 @@ async def test_history_stats_handles_floored_timestamps(
|
|||||||
assert last_times == (start_time, start_time + timedelta(hours=2))
|
assert last_times == (start_time, start_time + timedelta(hours=2))
|
||||||
|
|
||||||
|
|
||||||
async def test_unique_id(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
async def test_unique_id(
|
||||||
|
recorder_mock: Recorder, hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test unique_id property."""
|
"""Test unique_id property."""
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@ -1682,5 +1684,7 @@ async def test_unique_id(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||||||
assert await async_setup_component(hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
assert (
|
||||||
assert registry.async_get("sensor.test").unique_id == "some_history_stats_unique_id"
|
entity_registry.async_get("sensor.test").unique_id
|
||||||
|
== "some_history_stats_unique_id"
|
||||||
|
)
|
||||||
|
@ -141,11 +141,10 @@ async def test_if_fires_on_entity_change_below(
|
|||||||
"below", (10, "input_number.value_10", "number.value_10", "sensor.value_10")
|
"below", (10, "input_number.value_10", "number.value_10", "sensor.value_10")
|
||||||
)
|
)
|
||||||
async def test_if_fires_on_entity_change_below_uuid(
|
async def test_if_fires_on_entity_change_below_uuid(
|
||||||
hass: HomeAssistant, calls, below
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, calls, below
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the firing with changed entity specified by registry entry id."""
|
"""Test the firing with changed entity specified by registry entry id."""
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get_or_create(
|
||||||
entry = registry.async_get_or_create(
|
|
||||||
"test", "hue", "1234", suggested_object_id="entity"
|
"test", "hue", "1234", suggested_object_id="entity"
|
||||||
)
|
)
|
||||||
assert entry.entity_id == "test.entity"
|
assert entry.entity_id == "test.entity"
|
||||||
|
@ -89,12 +89,13 @@ async def test_if_fires_on_entity_change(hass: HomeAssistant, calls) -> None:
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_entity_change_uuid(hass: HomeAssistant, calls) -> None:
|
async def test_if_fires_on_entity_change_uuid(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, calls
|
||||||
|
) -> None:
|
||||||
"""Test for firing on entity change."""
|
"""Test for firing on entity change."""
|
||||||
context = Context()
|
context = Context()
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get_or_create(
|
||||||
entry = registry.async_get_or_create(
|
|
||||||
"test", "hue", "1234", suggested_object_id="beer"
|
"test", "hue", "1234", suggested_object_id="beer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -622,9 +622,9 @@ async def test_aid_generation_no_unique_ids_handles_collision(
|
|||||||
|
|
||||||
async def test_handle_unique_id_change(
|
async def test_handle_unique_id_change(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling unique id changes."""
|
"""Test handling unique id changes."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
light = entity_registry.async_get_or_create("light", "demo", "old_unique")
|
light = entity_registry.async_get_or_create("light", "demo", "old_unique")
|
||||||
config_entry = MockConfigEntry(domain="test", data={})
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -607,20 +607,18 @@ async def test_windowcovering_open_close_with_position_and_stop(
|
|||||||
|
|
||||||
|
|
||||||
async def test_windowcovering_basic_restore(
|
async def test_windowcovering_basic_restore(
|
||||||
hass: HomeAssistant, hk_driver, events
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"cover",
|
"cover",
|
||||||
"generic",
|
"generic",
|
||||||
"1234",
|
"1234",
|
||||||
suggested_object_id="simple",
|
suggested_object_id="simple",
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"cover",
|
"cover",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
@ -646,19 +644,19 @@ async def test_windowcovering_basic_restore(
|
|||||||
assert acc.char_position_state is not None
|
assert acc.char_position_state is not None
|
||||||
|
|
||||||
|
|
||||||
async def test_windowcovering_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_windowcovering_restore(
|
||||||
"""Test setting up an entity from state in the event registry."""
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
|
"""Test setting up an entity from state in the event entity_registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"cover",
|
"cover",
|
||||||
"generic",
|
"generic",
|
||||||
"1234",
|
"1234",
|
||||||
suggested_object_id="simple",
|
suggested_object_id="simple",
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"cover",
|
"cover",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
|
@ -553,19 +553,19 @@ async def test_fan_set_all_one_shot(hass: HomeAssistant, hk_driver, events) -> N
|
|||||||
assert len(call_set_direction) == 2
|
assert len(call_set_direction) == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_fan_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_fan_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"fan",
|
"fan",
|
||||||
"generic",
|
"generic",
|
||||||
"1234",
|
"1234",
|
||||||
suggested_object_id="simple",
|
suggested_object_id="simple",
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"fan",
|
"fan",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
|
@ -576,14 +576,16 @@ async def test_light_rgb_color(
|
|||||||
assert events[-1].data[ATTR_VALUE] == "set color at (145, 75)"
|
assert events[-1].data[ATTR_VALUE] == "set color at (145, 75)"
|
||||||
|
|
||||||
|
|
||||||
async def test_light_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_light_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
"light", "hue", "1234", suggested_object_id="simple"
|
||||||
registry.async_get_or_create("light", "hue", "1234", suggested_object_id="simple")
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
"hue",
|
"hue",
|
||||||
"9012",
|
"9012",
|
||||||
|
@ -428,20 +428,20 @@ async def test_media_player_television_supports_source_select_no_sources(
|
|||||||
assert acc.support_select_source is False
|
assert acc.support_select_source is False
|
||||||
|
|
||||||
|
|
||||||
async def test_tv_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_tv_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"media_player",
|
"media_player",
|
||||||
"generic",
|
"generic",
|
||||||
"1234",
|
"1234",
|
||||||
suggested_object_id="simple",
|
suggested_object_id="simple",
|
||||||
original_device_class=MediaPlayerDeviceClass.TV,
|
original_device_class=MediaPlayerDeviceClass.TV,
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"media_player",
|
"media_player",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
|
@ -541,20 +541,20 @@ async def test_binary_device_classes(hass: HomeAssistant, hk_driver) -> None:
|
|||||||
assert acc.char_detected.display_name == char
|
assert acc.char_detected.display_name == char
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_sensor_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"sensor",
|
"sensor",
|
||||||
"generic",
|
"generic",
|
||||||
"1234",
|
"1234",
|
||||||
suggested_object_id="temperature",
|
suggested_object_id="temperature",
|
||||||
original_device_class="temperature",
|
original_device_class="temperature",
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"sensor",
|
"sensor",
|
||||||
"generic",
|
"generic",
|
||||||
"12345",
|
"12345",
|
||||||
|
@ -964,16 +964,16 @@ async def test_thermostat_temperature_step_whole(
|
|||||||
assert acc.char_target_temp.properties[PROP_MIN_STEP] == 0.1
|
assert acc.char_target_temp.properties[PROP_MIN_STEP] == 0.1
|
||||||
|
|
||||||
|
|
||||||
async def test_thermostat_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_thermostat_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"climate", "generic", "1234", suggested_object_id="simple"
|
"climate", "generic", "1234", suggested_object_id="simple"
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"climate",
|
"climate",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
@ -1794,16 +1794,16 @@ async def test_water_heater_get_temperature_range(
|
|||||||
assert acc.get_temperature_range(state) == (15.5, 21.0)
|
assert acc.get_temperature_range(state) == (15.5, 21.0)
|
||||||
|
|
||||||
|
|
||||||
async def test_water_heater_restore(hass: HomeAssistant, hk_driver, events) -> None:
|
async def test_water_heater_restore(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, hk_driver, events
|
||||||
|
) -> None:
|
||||||
"""Test setting up an entity from state in the event registry."""
|
"""Test setting up an entity from state in the event registry."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entity_registry.async_get_or_create(
|
||||||
|
|
||||||
registry.async_get_or_create(
|
|
||||||
"water_heater", "generic", "1234", suggested_object_id="simple"
|
"water_heater", "generic", "1234", suggested_object_id="simple"
|
||||||
)
|
)
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"water_heater",
|
"water_heater",
|
||||||
"generic",
|
"generic",
|
||||||
"9012",
|
"9012",
|
||||||
|
@ -142,7 +142,9 @@ async def test_ecobee3_setup(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_ecobee3_setup_from_cache(
|
async def test_ecobee3_setup_from_cache(
|
||||||
hass: HomeAssistant, hass_storage: dict[str, Any]
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that Ecbobee can be correctly setup from its cached entity map."""
|
"""Test that Ecbobee can be correctly setup from its cached entity map."""
|
||||||
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
||||||
@ -163,8 +165,6 @@ async def test_ecobee3_setup_from_cache(
|
|||||||
|
|
||||||
await setup_test_accessories(hass, accessories)
|
await setup_test_accessories(hass, accessories)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
climate = entity_registry.async_get("climate.homew")
|
climate = entity_registry.async_get("climate.homew")
|
||||||
assert climate.unique_id == "00:00:00:00:00:00_1_16"
|
assert climate.unique_id == "00:00:00:00:00:00_1_16"
|
||||||
|
|
||||||
@ -178,12 +178,12 @@ async def test_ecobee3_setup_from_cache(
|
|||||||
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
||||||
|
|
||||||
|
|
||||||
async def test_ecobee3_setup_connection_failure(hass: HomeAssistant) -> None:
|
async def test_ecobee3_setup_connection_failure(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test that Ecbobee can be correctly setup from its cached entity map."""
|
"""Test that Ecbobee can be correctly setup from its cached entity map."""
|
||||||
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Test that the connection fails during initial setup.
|
# Test that the connection fails during initial setup.
|
||||||
# No entities should be created.
|
# No entities should be created.
|
||||||
with mock.patch.object(FakePairing, "async_populate_accessories_state") as laac:
|
with mock.patch.object(FakePairing, "async_populate_accessories_state") as laac:
|
||||||
@ -218,9 +218,10 @@ async def test_ecobee3_setup_connection_failure(hass: HomeAssistant) -> None:
|
|||||||
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
||||||
|
|
||||||
|
|
||||||
async def test_ecobee3_add_sensors_at_runtime(hass: HomeAssistant) -> None:
|
async def test_ecobee3_add_sensors_at_runtime(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test that new sensors are automatically added."""
|
"""Test that new sensors are automatically added."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a base Ecobee 3 with no additional sensors.
|
# Set up a base Ecobee 3 with no additional sensors.
|
||||||
# There shouldn't be any entities but climate visible.
|
# There shouldn't be any entities but climate visible.
|
||||||
@ -254,9 +255,10 @@ async def test_ecobee3_add_sensors_at_runtime(hass: HomeAssistant) -> None:
|
|||||||
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
assert occ3.unique_id == "00:00:00:00:00:00_4_56"
|
||||||
|
|
||||||
|
|
||||||
async def test_ecobee3_remove_sensors_at_runtime(hass: HomeAssistant) -> None:
|
async def test_ecobee3_remove_sensors_at_runtime(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test that sensors are automatically removed."""
|
"""Test that sensors are automatically removed."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a base Ecobee 3 with additional sensors.
|
# Set up a base Ecobee 3 with additional sensors.
|
||||||
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
||||||
@ -307,10 +309,9 @@ async def test_ecobee3_remove_sensors_at_runtime(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_ecobee3_services_and_chars_removed(
|
async def test_ecobee3_services_and_chars_removed(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling removal of some services and chars."""
|
"""Test handling removal of some services and chars."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a base Ecobee 3 with additional sensors.
|
# Set up a base Ecobee 3 with additional sensors.
|
||||||
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
|
||||||
|
@ -13,9 +13,10 @@ from ..common import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_fan_add_feature_at_runtime(hass: HomeAssistant) -> None:
|
async def test_fan_add_feature_at_runtime(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test that new features can be added at runtime."""
|
"""Test that new features can be added at runtime."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a basic fan that does not support oscillation
|
# Set up a basic fan that does not support oscillation
|
||||||
accessories = await setup_accessories_from_file(
|
accessories = await setup_accessories_from_file(
|
||||||
@ -55,9 +56,10 @@ async def test_fan_add_feature_at_runtime(hass: HomeAssistant) -> None:
|
|||||||
assert fan_state.attributes[ATTR_SUPPORTED_FEATURES] is FanEntityFeature.SET_SPEED
|
assert fan_state.attributes[ATTR_SUPPORTED_FEATURES] is FanEntityFeature.SET_SPEED
|
||||||
|
|
||||||
|
|
||||||
async def test_fan_remove_feature_at_runtime(hass: HomeAssistant) -> None:
|
async def test_fan_remove_feature_at_runtime(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test that features can be removed at runtime."""
|
"""Test that features can be removed at runtime."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a basic fan that does not support oscillation
|
# Set up a basic fan that does not support oscillation
|
||||||
accessories = await setup_accessories_from_file(
|
accessories = await setup_accessories_from_file(
|
||||||
@ -97,9 +99,11 @@ async def test_fan_remove_feature_at_runtime(hass: HomeAssistant) -> None:
|
|||||||
assert fan_state.attributes[ATTR_SUPPORTED_FEATURES] is FanEntityFeature.SET_SPEED
|
assert fan_state.attributes[ATTR_SUPPORTED_FEATURES] is FanEntityFeature.SET_SPEED
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_with_two_fans_one_removed(hass: HomeAssistant) -> None:
|
async def test_bridge_with_two_fans_one_removed(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test a bridge with two fans and one gets removed."""
|
"""Test a bridge with two fans and one gets removed."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Set up a basic fan that does not support oscillation
|
# Set up a basic fan that does not support oscillation
|
||||||
accessories = await setup_accessories_from_file(
|
accessories = await setup_accessories_from_file(
|
||||||
|
@ -14,10 +14,12 @@ from ..common import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_vocolinc_vp3_setup(hass: HomeAssistant) -> None:
|
async def test_vocolinc_vp3_setup(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test that a VOCOlinc VP3 can be correctly setup in HA."""
|
"""Test that a VOCOlinc VP3 can be correctly setup in HA."""
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
outlet = entity_registry.async_get_or_create(
|
outlet = entity_registry.async_get_or_create(
|
||||||
"switch",
|
"switch",
|
||||||
"homekit_controller",
|
"homekit_controller",
|
||||||
|
@ -124,9 +124,10 @@ async def test_switch_read_alarm_state(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.state == "triggered"
|
assert state.state == "triggered"
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a alarm_control_panel unique id."""
|
"""Test a we can migrate a alarm_control_panel unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
alarm_control_panel_entry = entity_registry.async_get_or_create(
|
alarm_control_panel_entry = entity_registry.async_get_or_create(
|
||||||
"alarm_control_panel",
|
"alarm_control_panel",
|
||||||
|
@ -173,9 +173,10 @@ async def test_leak_sensor_read_state(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["device_class"] == BinarySensorDeviceClass.MOISTURE
|
assert state.attributes["device_class"] == BinarySensorDeviceClass.MOISTURE
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a binary_sensor unique id."""
|
"""Test a we can migrate a binary_sensor unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
binary_sensor_entry = entity_registry.async_get_or_create(
|
binary_sensor_entry = entity_registry.async_get_or_create(
|
||||||
"binary_sensor",
|
"binary_sensor",
|
||||||
|
@ -94,9 +94,10 @@ async def test_ecobee_clear_hold_press_button(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a button unique id."""
|
"""Test a we can migrate a button unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
button_entry = entity_registry.async_get_or_create(
|
button_entry = entity_registry.async_get_or_create(
|
||||||
"button",
|
"button",
|
||||||
|
@ -16,9 +16,10 @@ def create_camera(accessory):
|
|||||||
accessory.add_service(ServicesTypes.CAMERA_RTP_STREAM_MANAGEMENT)
|
accessory.add_service(ServicesTypes.CAMERA_RTP_STREAM_MANAGEMENT)
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_ids(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_ids(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test migrating entity unique ids."""
|
"""Test migrating entity unique ids."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
camera = entity_registry.async_get_or_create(
|
camera = entity_registry.async_get_or_create(
|
||||||
"camera",
|
"camera",
|
||||||
|
@ -1112,9 +1112,10 @@ async def test_heater_cooler_turn_off(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["hvac_action"] == "off"
|
assert state.attributes["hvac_action"] == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a switch unique id."""
|
"""Test a we can migrate a switch unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
climate_entry = entity_registry.async_get_or_create(
|
climate_entry = entity_registry.async_get_or_create(
|
||||||
"climate",
|
"climate",
|
||||||
|
@ -90,7 +90,9 @@ DEVICE_MIGRATION_TESTS = [
|
|||||||
|
|
||||||
@pytest.mark.parametrize("variant", DEVICE_MIGRATION_TESTS)
|
@pytest.mark.parametrize("variant", DEVICE_MIGRATION_TESTS)
|
||||||
async def test_migrate_device_id_no_serial_skip_if_other_owner(
|
async def test_migrate_device_id_no_serial_skip_if_other_owner(
|
||||||
hass: HomeAssistant, variant: DeviceMigrationTest
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
variant: DeviceMigrationTest,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Don't migrate unrelated devices.
|
"""Don't migrate unrelated devices.
|
||||||
|
|
||||||
@ -99,7 +101,6 @@ async def test_migrate_device_id_no_serial_skip_if_other_owner(
|
|||||||
"""
|
"""
|
||||||
entry = MockConfigEntry()
|
entry = MockConfigEntry()
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
bridge = device_registry.async_get_or_create(
|
bridge = device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
@ -122,11 +123,11 @@ async def test_migrate_device_id_no_serial_skip_if_other_owner(
|
|||||||
|
|
||||||
@pytest.mark.parametrize("variant", DEVICE_MIGRATION_TESTS)
|
@pytest.mark.parametrize("variant", DEVICE_MIGRATION_TESTS)
|
||||||
async def test_migrate_device_id_no_serial(
|
async def test_migrate_device_id_no_serial(
|
||||||
hass: HomeAssistant, variant: DeviceMigrationTest
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
variant: DeviceMigrationTest,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that a Ryse smart bridge with four shades can be migrated correctly in HA."""
|
"""Test that a Ryse smart bridge with four shades can be migrated correctly in HA."""
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
accessories = await setup_accessories_from_file(hass, variant.fixture)
|
accessories = await setup_accessories_from_file(hass, variant.fixture)
|
||||||
|
|
||||||
fake_controller = await setup_platform(hass)
|
fake_controller = await setup_platform(hass)
|
||||||
|
@ -398,9 +398,10 @@ async def test_read_door_state(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["obstruction-detected"] is True
|
assert state.attributes["obstruction-detected"] is True
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a cover unique id."""
|
"""Test a we can migrate a cover unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
cover_entry = entity_registry.async_get_or_create(
|
cover_entry = entity_registry.async_get_or_create(
|
||||||
"cover",
|
"cover",
|
||||||
|
@ -83,15 +83,18 @@ def create_doorbell(accessory):
|
|||||||
battery.add_char(CharacteristicsTypes.BATTERY_LEVEL)
|
battery.add_char(CharacteristicsTypes.BATTERY_LEVEL)
|
||||||
|
|
||||||
|
|
||||||
async def test_enumerate_remote(hass: HomeAssistant, utcnow) -> None:
|
async def test_enumerate_remote(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
utcnow,
|
||||||
|
) -> None:
|
||||||
"""Test that remote is correctly enumerated."""
|
"""Test that remote is correctly enumerated."""
|
||||||
await setup_test_component(hass, create_remote)
|
await setup_test_component(hass, create_remote)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
||||||
identify_button = entity_registry.async_get("button.testdevice_identify")
|
identify_button = entity_registry.async_get("button.testdevice_identify")
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(bat_sensor.device_id)
|
device = device_registry.async_get(bat_sensor.device_id)
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
@ -132,15 +135,18 @@ async def test_enumerate_remote(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert triggers == unordered(expected)
|
assert triggers == unordered(expected)
|
||||||
|
|
||||||
|
|
||||||
async def test_enumerate_button(hass: HomeAssistant, utcnow) -> None:
|
async def test_enumerate_button(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
utcnow,
|
||||||
|
) -> None:
|
||||||
"""Test that a button is correctly enumerated."""
|
"""Test that a button is correctly enumerated."""
|
||||||
await setup_test_component(hass, create_button)
|
await setup_test_component(hass, create_button)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
||||||
identify_button = entity_registry.async_get("button.testdevice_identify")
|
identify_button = entity_registry.async_get("button.testdevice_identify")
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(bat_sensor.device_id)
|
device = device_registry.async_get(bat_sensor.device_id)
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
@ -180,15 +186,18 @@ async def test_enumerate_button(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert triggers == unordered(expected)
|
assert triggers == unordered(expected)
|
||||||
|
|
||||||
|
|
||||||
async def test_enumerate_doorbell(hass: HomeAssistant, utcnow) -> None:
|
async def test_enumerate_doorbell(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
utcnow,
|
||||||
|
) -> None:
|
||||||
"""Test that a button is correctly enumerated."""
|
"""Test that a button is correctly enumerated."""
|
||||||
await setup_test_component(hass, create_doorbell)
|
await setup_test_component(hass, create_doorbell)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
bat_sensor = entity_registry.async_get("sensor.testdevice_battery")
|
||||||
identify_button = entity_registry.async_get("button.testdevice_identify")
|
identify_button = entity_registry.async_get("button.testdevice_identify")
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(bat_sensor.device_id)
|
device = device_registry.async_get(bat_sensor.device_id)
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
@ -228,14 +237,18 @@ async def test_enumerate_doorbell(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert triggers == unordered(expected)
|
assert triggers == unordered(expected)
|
||||||
|
|
||||||
|
|
||||||
async def test_handle_events(hass: HomeAssistant, utcnow, calls) -> None:
|
async def test_handle_events(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
utcnow,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test that events are handled."""
|
"""Test that events are handled."""
|
||||||
helper = await setup_test_component(hass, create_remote)
|
helper = await setup_test_component(hass, create_remote)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entry = entity_registry.async_get("sensor.testdevice_battery")
|
entry = entity_registry.async_get("sensor.testdevice_battery")
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(entry.device_id)
|
device = device_registry.async_get(entry.device_id)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
@ -345,14 +358,18 @@ async def test_handle_events(hass: HomeAssistant, utcnow, calls) -> None:
|
|||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_handle_events_late_setup(hass: HomeAssistant, utcnow, calls) -> None:
|
async def test_handle_events_late_setup(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
utcnow,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test that events are handled when setup happens after startup."""
|
"""Test that events are handled when setup happens after startup."""
|
||||||
helper = await setup_test_component(hass, create_remote)
|
helper = await setup_test_component(hass, create_remote)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entry = entity_registry.async_get("sensor.testdevice_battery")
|
entry = entity_registry.async_get("sensor.testdevice_battery")
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(entry.device_id)
|
device = device_registry.async_get(entry.device_id)
|
||||||
|
|
||||||
await hass.config_entries.async_unload(helper.config_entry.entry_id)
|
await hass.config_entries.async_unload(helper.config_entry.entry_id)
|
||||||
|
@ -290,14 +290,16 @@ async def test_config_entry(
|
|||||||
|
|
||||||
|
|
||||||
async def test_device(
|
async def test_device(
|
||||||
hass: HomeAssistant, hass_client: ClientSessionGenerator, utcnow
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
utcnow,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test generating diagnostics for a device entry."""
|
"""Test generating diagnostics for a device entry."""
|
||||||
accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json")
|
accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json")
|
||||||
config_entry, _ = await setup_test_accessories(hass, accessories)
|
config_entry, _ = await setup_test_accessories(hass, accessories)
|
||||||
|
|
||||||
connection = hass.data[KNOWN_DEVICES]["00:00:00:00:00:00"]
|
connection = hass.data[KNOWN_DEVICES]["00:00:00:00:00:00"]
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(connection.devices[1])
|
device = device_registry.async_get(connection.devices[1])
|
||||||
|
|
||||||
diag = await get_diagnostics_for_device(hass, hass_client, config_entry, device)
|
diag = await get_diagnostics_for_device(hass, hass_client, config_entry, device)
|
||||||
|
@ -64,7 +64,9 @@ def create_doorbell(accessory):
|
|||||||
battery.add_char(CharacteristicsTypes.BATTERY_LEVEL)
|
battery.add_char(CharacteristicsTypes.BATTERY_LEVEL)
|
||||||
|
|
||||||
|
|
||||||
async def test_remote(hass: HomeAssistant, utcnow) -> None:
|
async def test_remote(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test that remote is supported."""
|
"""Test that remote is supported."""
|
||||||
helper = await setup_test_component(hass, create_remote)
|
helper = await setup_test_component(hass, create_remote)
|
||||||
|
|
||||||
@ -75,8 +77,6 @@ async def test_remote(hass: HomeAssistant, utcnow) -> None:
|
|||||||
("event.testdevice_button_4", "Button 4"),
|
("event.testdevice_button_4", "Button 4"),
|
||||||
]
|
]
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
for entity_id, service in entities:
|
for entity_id, service in entities:
|
||||||
button = entity_registry.async_get(entity_id)
|
button = entity_registry.async_get(entity_id)
|
||||||
|
|
||||||
@ -109,12 +109,13 @@ async def test_remote(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["event_type"] == "long_press"
|
assert state.attributes["event_type"] == "long_press"
|
||||||
|
|
||||||
|
|
||||||
async def test_button(hass: HomeAssistant, utcnow) -> None:
|
async def test_button(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test that a button is correctly enumerated."""
|
"""Test that a button is correctly enumerated."""
|
||||||
helper = await setup_test_component(hass, create_button)
|
helper = await setup_test_component(hass, create_button)
|
||||||
entity_id = "event.testdevice_button_1"
|
entity_id = "event.testdevice_button_1"
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
button = entity_registry.async_get(entity_id)
|
button = entity_registry.async_get(entity_id)
|
||||||
|
|
||||||
assert button.original_device_class == EventDeviceClass.BUTTON
|
assert button.original_device_class == EventDeviceClass.BUTTON
|
||||||
@ -146,12 +147,13 @@ async def test_button(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["event_type"] == "long_press"
|
assert state.attributes["event_type"] == "long_press"
|
||||||
|
|
||||||
|
|
||||||
async def test_doorbell(hass: HomeAssistant, utcnow) -> None:
|
async def test_doorbell(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test that doorbell service is handled."""
|
"""Test that doorbell service is handled."""
|
||||||
helper = await setup_test_component(hass, create_doorbell)
|
helper = await setup_test_component(hass, create_doorbell)
|
||||||
entity_id = "event.testdevice_doorbell"
|
entity_id = "event.testdevice_doorbell"
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
doorbell = entity_registry.async_get(entity_id)
|
doorbell = entity_registry.async_get(entity_id)
|
||||||
|
|
||||||
assert doorbell.original_device_class == EventDeviceClass.DOORBELL
|
assert doorbell.original_device_class == EventDeviceClass.DOORBELL
|
||||||
|
@ -811,9 +811,10 @@ async def test_v2_set_percentage_non_standard_rotation_range(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a fan unique id."""
|
"""Test a we can migrate a fan unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
fan_entry = entity_registry.async_get_or_create(
|
fan_entry = entity_registry.async_get_or_create(
|
||||||
"fan",
|
"fan",
|
||||||
|
@ -455,11 +455,12 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant, utcnow) -
|
|||||||
assert state.attributes["current_humidity"] == 51
|
assert state.attributes["current_humidity"] == 51
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_entity_ids(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_entity_ids(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test that we can migrate humidifier entity ids."""
|
"""Test that we can migrate humidifier entity ids."""
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
humidifier_entry = entity_registry.async_get_or_create(
|
humidifier_entry = entity_registry.async_get_or_create(
|
||||||
"humidifier",
|
"humidifier",
|
||||||
"homekit_controller",
|
"homekit_controller",
|
||||||
|
@ -17,7 +17,6 @@ from homeassistant.config_entries import ConfigEntryState
|
|||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_OFF, STATE_UNAVAILABLE
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_OFF, STATE_UNAVAILABLE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
@ -85,7 +84,10 @@ def create_alive_service(accessory):
|
|||||||
|
|
||||||
|
|
||||||
async def test_device_remove_devices(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can only remove a device that no longer exists."""
|
"""Test we can only remove a device that no longer exists."""
|
||||||
assert await async_setup_component(hass, "config", {})
|
assert await async_setup_component(hass, "config", {})
|
||||||
@ -93,9 +95,7 @@ async def test_device_remove_devices(
|
|||||||
config_entry = helper.config_entry
|
config_entry = helper.config_entry
|
||||||
entry_id = config_entry.entry_id
|
entry_id = config_entry.entry_id
|
||||||
|
|
||||||
registry: EntityRegistry = er.async_get(hass)
|
entity = entity_registry.entities[ALIVE_DEVICE_ENTITY_ID]
|
||||||
entity = registry.entities[ALIVE_DEVICE_ENTITY_ID]
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
live_device_entry = device_registry.async_get(entity.device_id)
|
live_device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
assert (
|
||||||
@ -231,15 +231,16 @@ async def test_ble_device_only_checks_is_available(
|
|||||||
|
|
||||||
@pytest.mark.parametrize("example", FIXTURES, ids=lambda val: str(val.stem))
|
@pytest.mark.parametrize("example", FIXTURES, ids=lambda val: str(val.stem))
|
||||||
async def test_snapshots(
|
async def test_snapshots(
|
||||||
hass: HomeAssistant, snapshot: SnapshotAssertion, example: str
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
example: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Detect regressions in enumerating a homekit accessory database and building entities."""
|
"""Detect regressions in enumerating a homekit accessory database and building entities."""
|
||||||
accessories = await setup_accessories_from_file(hass, example)
|
accessories = await setup_accessories_from_file(hass, example)
|
||||||
config_entry, _ = await setup_test_accessories(hass, accessories)
|
config_entry, _ = await setup_test_accessories(hass, accessories)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
registry_devices = dr.async_entries_for_config_entry(
|
registry_devices = dr.async_entries_for_config_entry(
|
||||||
device_registry, config_entry.entry_id
|
device_registry, config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
@ -343,9 +343,10 @@ async def test_light_unloaded_removed(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert hass.states.get(helper.entity_id).state == STATE_UNAVAILABLE
|
assert hass.states.get(helper.entity_id).state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a light unique id."""
|
"""Test a we can migrate a light unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
light_entry = entity_registry.async_get_or_create(
|
light_entry = entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
@ -360,9 +361,10 @@ async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_only_migrate_once(hass: HomeAssistant, utcnow) -> None:
|
async def test_only_migrate_once(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we handle migration happening after an upgrade and than a downgrade and then an upgrade."""
|
"""Test a we handle migration happening after an upgrade and than a downgrade and then an upgrade."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
old_light_entry = entity_registry.async_get_or_create(
|
old_light_entry = entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
|
@ -117,9 +117,10 @@ async def test_switch_read_lock_state(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.state == "unlocking"
|
assert state.state == "unlocking"
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a lock unique id."""
|
"""Test a we can migrate a lock unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
lock_entry = entity_registry.async_get_or_create(
|
lock_entry = entity_registry.async_get_or_create(
|
||||||
"lock",
|
"lock",
|
||||||
|
@ -368,9 +368,10 @@ async def test_tv_set_source_fail(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert state.attributes["source"] == "HDMI 1"
|
assert state.attributes["source"] == "HDMI 1"
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a media_player unique id."""
|
"""Test a we can migrate a media_player unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
media_player_entry = entity_registry.async_get_or_create(
|
media_player_entry = entity_registry.async_get_or_create(
|
||||||
"media_player",
|
"media_player",
|
||||||
|
@ -29,9 +29,10 @@ def create_switch_with_spray_level(accessory):
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a number unique id."""
|
"""Test a we can migrate a number unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
number = entity_registry.async_get_or_create(
|
number = entity_registry.async_get_or_create(
|
||||||
"number",
|
"number",
|
||||||
|
@ -33,9 +33,10 @@ def create_service_with_temperature_units(accessory: Accessory):
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test we can migrate a select unique id."""
|
"""Test we can migrate a select unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
select = entity_registry.async_get_or_create(
|
select = entity_registry.async_get_or_create(
|
||||||
"select",
|
"select",
|
||||||
|
@ -409,12 +409,12 @@ async def test_rssi_sensor(
|
|||||||
|
|
||||||
async def test_migrate_rssi_sensor_unique_id(
|
async def test_migrate_rssi_sensor_unique_id(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
utcnow,
|
utcnow,
|
||||||
entity_registry_enabled_by_default: None,
|
entity_registry_enabled_by_default: None,
|
||||||
enable_bluetooth: None,
|
enable_bluetooth: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test an rssi sensor unique id migration."""
|
"""Test an rssi sensor unique id migration."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
rssi_sensor = entity_registry.async_get_or_create(
|
rssi_sensor = entity_registry.async_get_or_create(
|
||||||
"sensor",
|
"sensor",
|
||||||
"homekit_controller",
|
"homekit_controller",
|
||||||
|
@ -219,9 +219,10 @@ async def test_char_switch_read_state(hass: HomeAssistant, utcnow) -> None:
|
|||||||
assert switch_1.state == "off"
|
assert switch_1.state == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_unique_id(hass: HomeAssistant, utcnow) -> None:
|
async def test_migrate_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, utcnow
|
||||||
|
) -> None:
|
||||||
"""Test a we can migrate a switch unique id."""
|
"""Test a we can migrate a switch unique id."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
aid = get_next_aid()
|
aid = get_next_aid()
|
||||||
switch_entry = entity_registry.async_get_or_create(
|
switch_entry = entity_registry.async_get_or_create(
|
||||||
"switch",
|
"switch",
|
||||||
|
@ -29,7 +29,10 @@ async def test_hmip_load_all_supported_devices(
|
|||||||
|
|
||||||
|
|
||||||
async def test_hmip_remove_device(
|
async def test_hmip_remove_device(
|
||||||
hass: HomeAssistant, default_mock_hap_factory
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
default_mock_hap_factory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Remove of hmip device."""
|
"""Test Remove of hmip device."""
|
||||||
entity_id = "light.treppe_ch"
|
entity_id = "light.treppe_ch"
|
||||||
@ -46,9 +49,6 @@ async def test_hmip_remove_device(
|
|||||||
assert ha_state.state == STATE_ON
|
assert ha_state.state == STATE_ON
|
||||||
assert hmip_device
|
assert hmip_device
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
pre_device_count = len(device_registry.devices)
|
pre_device_count = len(device_registry.devices)
|
||||||
pre_entity_count = len(entity_registry.entities)
|
pre_entity_count = len(entity_registry.entities)
|
||||||
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
||||||
@ -63,7 +63,11 @@ async def test_hmip_remove_device(
|
|||||||
|
|
||||||
|
|
||||||
async def test_hmip_add_device(
|
async def test_hmip_add_device(
|
||||||
hass: HomeAssistant, default_mock_hap_factory, hmip_config_entry
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
default_mock_hap_factory,
|
||||||
|
hmip_config_entry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Remove of hmip device."""
|
"""Test Remove of hmip device."""
|
||||||
entity_id = "light.treppe_ch"
|
entity_id = "light.treppe_ch"
|
||||||
@ -80,9 +84,6 @@ async def test_hmip_add_device(
|
|||||||
assert ha_state.state == STATE_ON
|
assert ha_state.state == STATE_ON
|
||||||
assert hmip_device
|
assert hmip_device
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
pre_device_count = len(device_registry.devices)
|
pre_device_count = len(device_registry.devices)
|
||||||
pre_entity_count = len(entity_registry.entities)
|
pre_entity_count = len(entity_registry.entities)
|
||||||
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
||||||
@ -112,7 +113,12 @@ async def test_hmip_add_device(
|
|||||||
assert len(new_hap.hmip_device_by_entity_id) == pre_mapping_count
|
assert len(new_hap.hmip_device_by_entity_id) == pre_mapping_count
|
||||||
|
|
||||||
|
|
||||||
async def test_hmip_remove_group(hass: HomeAssistant, default_mock_hap_factory) -> None:
|
async def test_hmip_remove_group(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
default_mock_hap_factory,
|
||||||
|
) -> None:
|
||||||
"""Test Remove of hmip group."""
|
"""Test Remove of hmip group."""
|
||||||
entity_id = "switch.strom_group"
|
entity_id = "switch.strom_group"
|
||||||
entity_name = "Strom Group"
|
entity_name = "Strom Group"
|
||||||
@ -126,9 +132,6 @@ async def test_hmip_remove_group(hass: HomeAssistant, default_mock_hap_factory)
|
|||||||
assert ha_state.state == STATE_ON
|
assert ha_state.state == STATE_ON
|
||||||
assert hmip_device
|
assert hmip_device
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
pre_device_count = len(device_registry.devices)
|
pre_device_count = len(device_registry.devices)
|
||||||
pre_entity_count = len(entity_registry.entities)
|
pre_entity_count = len(entity_registry.entities)
|
||||||
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
pre_mapping_count = len(mock_hap.hmip_device_by_entity_id)
|
||||||
@ -254,7 +257,10 @@ async def test_hmip_reset_energy_counter_services(
|
|||||||
|
|
||||||
|
|
||||||
async def test_hmip_multi_area_device(
|
async def test_hmip_multi_area_device(
|
||||||
hass: HomeAssistant, default_mock_hap_factory
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
default_mock_hap_factory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test multi area device. Check if devices are created and referenced."""
|
"""Test multi area device. Check if devices are created and referenced."""
|
||||||
entity_id = "binary_sensor.wired_eingangsmodul_32_fach_channel5"
|
entity_id = "binary_sensor.wired_eingangsmodul_32_fach_channel5"
|
||||||
@ -270,12 +276,10 @@ async def test_hmip_multi_area_device(
|
|||||||
assert ha_state
|
assert ha_state
|
||||||
|
|
||||||
# get the entity
|
# get the entity
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entity = entity_registry.async_get(ha_state.entity_id)
|
entity = entity_registry.async_get(ha_state.entity_id)
|
||||||
assert entity
|
assert entity
|
||||||
|
|
||||||
# get the device
|
# get the device
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get(entity.device_id)
|
device = device_registry.async_get(entity.device_id)
|
||||||
assert device.name == "Wired Eingangsmodul – 32-fach"
|
assert device.name == "Wired Eingangsmodul – 32-fach"
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ async def test_no_thermostat_options(
|
|||||||
|
|
||||||
async def test_static_attributes(
|
async def test_static_attributes(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
device: MagicMock,
|
device: MagicMock,
|
||||||
config_entry: MagicMock,
|
config_entry: MagicMock,
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
@ -70,7 +71,7 @@ async def test_static_attributes(
|
|||||||
await init_integration(hass, config_entry)
|
await init_integration(hass, config_entry)
|
||||||
|
|
||||||
entity_id = f"climate.{device.name}"
|
entity_id = f"climate.{device.name}"
|
||||||
entry = er.async_get(hass).async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -1200,7 +1201,10 @@ async def test_async_update_errors(
|
|||||||
|
|
||||||
|
|
||||||
async def test_aux_heat_off_service_call(
|
async def test_aux_heat_off_service_call(
|
||||||
hass: HomeAssistant, device: MagicMock, config_entry: MagicMock
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device: MagicMock,
|
||||||
|
config_entry: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test aux heat off turns of system when no heat configured."""
|
"""Test aux heat off turns of system when no heat configured."""
|
||||||
device.raw_ui_data["SwitchHeatAllowed"] = False
|
device.raw_ui_data["SwitchHeatAllowed"] = False
|
||||||
@ -1210,7 +1214,7 @@ async def test_aux_heat_off_service_call(
|
|||||||
await init_integration(hass, config_entry)
|
await init_integration(hass, config_entry)
|
||||||
|
|
||||||
entity_id = f"climate.{device.name}"
|
entity_id = f"climate.{device.name}"
|
||||||
entry = er.async_get(hass).async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
|
@ -124,6 +124,7 @@ async def test_no_devices(
|
|||||||
async def test_remove_stale_device(
|
async def test_remove_stale_device(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
location: MagicMock,
|
location: MagicMock,
|
||||||
another_device: MagicMock,
|
another_device: MagicMock,
|
||||||
client: MagicMock,
|
client: MagicMock,
|
||||||
@ -133,7 +134,6 @@ async def test_remove_stale_device(
|
|||||||
|
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={("OtherDomain", 7654321)},
|
identifiers={("OtherDomain", 7654321)},
|
||||||
@ -146,7 +146,6 @@ async def test_remove_stale_device(
|
|||||||
hass.states.async_entity_ids_count() == 6
|
hass.states.async_entity_ids_count() == 6
|
||||||
) # 2 climate entities; 4 sensor entities
|
) # 2 climate entities; 4 sensor entities
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device_entry = dr.async_entries_for_config_entry(
|
device_entry = dr.async_entries_for_config_entry(
|
||||||
device_registry, config_entry.entry_id
|
device_registry, config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,6 @@ from homeassistant.components.switch import (
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_URL, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_ENTITY_ID, CONF_URL, STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -42,13 +41,13 @@ def magic_client(multi_basic_settings_value: dict) -> MagicMock:
|
|||||||
async def test_huawei_lte_wifi_guest_network_config_entry_when_network_is_not_present(
|
async def test_huawei_lte_wifi_guest_network_config_entry_when_network_is_not_present(
|
||||||
client,
|
client,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test switch wifi guest network config entry when network is not present."""
|
"""Test switch wifi guest network config entry when network is not present."""
|
||||||
huawei_lte = MockConfigEntry(domain=DOMAIN, data={CONF_URL: "http://huawei-lte"})
|
huawei_lte = MockConfigEntry(domain=DOMAIN, data={CONF_URL: "http://huawei-lte"})
|
||||||
huawei_lte.add_to_hass(hass)
|
huawei_lte.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entity_registry: EntityRegistry = er.async_get(hass)
|
|
||||||
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
||||||
|
|
||||||
|
|
||||||
@ -62,13 +61,13 @@ async def test_huawei_lte_wifi_guest_network_config_entry_when_network_is_not_pr
|
|||||||
async def test_huawei_lte_wifi_guest_network_config_entry_when_network_is_present(
|
async def test_huawei_lte_wifi_guest_network_config_entry_when_network_is_present(
|
||||||
client,
|
client,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test switch wifi guest network config entry when network is present."""
|
"""Test switch wifi guest network config entry when network is present."""
|
||||||
huawei_lte = MockConfigEntry(domain=DOMAIN, data={CONF_URL: "http://huawei-lte"})
|
huawei_lte = MockConfigEntry(domain=DOMAIN, data={CONF_URL: "http://huawei-lte"})
|
||||||
huawei_lte.add_to_hass(hass)
|
huawei_lte.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entity_registry: EntityRegistry = er.async_get(hass)
|
|
||||||
assert entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
assert entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
||||||
|
|
||||||
|
|
||||||
@ -122,7 +121,9 @@ async def test_turn_off_switch_wifi_guest_network(client, hass: HomeAssistant) -
|
|||||||
return_value=magic_client({"Ssids": {"Ssid": "str"}}),
|
return_value=magic_client({"Ssids": {"Ssid": "str"}}),
|
||||||
)
|
)
|
||||||
async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_str(
|
async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_str(
|
||||||
client, hass: HomeAssistant
|
client,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test switch wifi guest network config entry when ssid is a str.
|
"""Test switch wifi guest network config entry when ssid is a str.
|
||||||
|
|
||||||
@ -132,7 +133,6 @@ async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_str(
|
|||||||
huawei_lte.add_to_hass(hass)
|
huawei_lte.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entity_registry: EntityRegistry = er.async_get(hass)
|
|
||||||
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
||||||
|
|
||||||
|
|
||||||
@ -142,7 +142,9 @@ async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_str(
|
|||||||
return_value=magic_client({"Ssids": {"Ssid": None}}),
|
return_value=magic_client({"Ssids": {"Ssid": None}}),
|
||||||
)
|
)
|
||||||
async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_none(
|
async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_none(
|
||||||
client, hass: HomeAssistant
|
client,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test switch wifi guest network config entry when ssid is a None.
|
"""Test switch wifi guest network config entry when ssid is a None.
|
||||||
|
|
||||||
@ -152,5 +154,4 @@ async def test_huawei_lte_wifi_guest_network_config_entry_when_ssid_is_none(
|
|||||||
huawei_lte.add_to_hass(hass)
|
huawei_lte.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entity_registry: EntityRegistry = er.async_get(hass)
|
|
||||||
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
assert not entity_registry.async_is_registered(SWITCH_WIFI_GUEST_NETWORK)
|
||||||
|
@ -527,7 +527,10 @@ def _get_schema_default(schema, key_name):
|
|||||||
raise KeyError(f"{key_name} not found in schema")
|
raise KeyError(f"{key_name} not found in schema")
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_v2(hass: HomeAssistant) -> None:
|
async def test_options_flow_v2(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test options config flow for a V2 bridge."""
|
"""Test options config flow for a V2 bridge."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain="hue",
|
domain="hue",
|
||||||
@ -536,9 +539,8 @@ async def test_options_flow_v2(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
mock_dev_id = "aabbccddee"
|
mock_dev_id = "aabbccddee"
|
||||||
dev_reg.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id, identifiers={(const.DOMAIN, mock_dev_id)}
|
config_entry_id=entry.entry_id, identifiers={(const.DOMAIN, mock_dev_id)}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -275,7 +275,9 @@ async def test_lights_color_mode(hass: HomeAssistant, mock_bridge_v1) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_groups(hass: HomeAssistant, mock_bridge_v1) -> None:
|
async def test_groups(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_bridge_v1
|
||||||
|
) -> None:
|
||||||
"""Test the update_lights function with some lights."""
|
"""Test the update_lights function with some lights."""
|
||||||
mock_bridge_v1.mock_light_responses.append({})
|
mock_bridge_v1.mock_light_responses.append({})
|
||||||
mock_bridge_v1.mock_group_responses.append(GROUP_RESPONSE)
|
mock_bridge_v1.mock_group_responses.append(GROUP_RESPONSE)
|
||||||
@ -295,9 +297,8 @@ async def test_groups(hass: HomeAssistant, mock_bridge_v1) -> None:
|
|||||||
assert lamp_2 is not None
|
assert lamp_2 is not None
|
||||||
assert lamp_2.state == "on"
|
assert lamp_2.state == "on"
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
assert entity_registry.async_get("light.group_1").unique_id == "1"
|
||||||
assert ent_reg.async_get("light.group_1").unique_id == "1"
|
assert entity_registry.async_get("light.group_2").unique_id == "2"
|
||||||
assert ent_reg.async_get("light.group_2").unique_id == "2"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_new_group_discovered(hass: HomeAssistant, mock_bridge_v1) -> None:
|
async def test_new_group_discovered(hass: HomeAssistant, mock_bridge_v1) -> None:
|
||||||
@ -764,7 +765,12 @@ def test_hs_color() -> None:
|
|||||||
assert light.hs_color == color.color_xy_to_hs(0.4, 0.5, LIGHT_GAMUT)
|
assert light.hs_color == color.color_xy_to_hs(0.4, 0.5, LIGHT_GAMUT)
|
||||||
|
|
||||||
|
|
||||||
async def test_group_features(hass: HomeAssistant, mock_bridge_v1) -> None:
|
async def test_group_features(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_bridge_v1,
|
||||||
|
) -> None:
|
||||||
"""Test group features."""
|
"""Test group features."""
|
||||||
color_temp_type = "Color temperature light"
|
color_temp_type = "Color temperature light"
|
||||||
extended_color_type = "Extended color light"
|
extended_color_type = "Extended color light"
|
||||||
@ -949,9 +955,6 @@ async def test_group_features(hass: HomeAssistant, mock_bridge_v1) -> None:
|
|||||||
assert group_3.attributes["supported_color_modes"] == extended_color_mode
|
assert group_3.attributes["supported_color_modes"] == extended_color_mode
|
||||||
assert group_3.attributes["supported_features"] == extended_color_feature
|
assert group_3.attributes["supported_features"] == extended_color_feature
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get("light.hue_lamp_1")
|
entry = entity_registry.async_get("light.hue_lamp_1")
|
||||||
device_entry = device_registry.async_get(entry.device_id)
|
device_entry = device_registry.async_get(entry.device_id)
|
||||||
assert device_entry.suggested_area is None
|
assert device_entry.suggested_area is None
|
||||||
|
@ -350,7 +350,10 @@ async def test_light_availability(
|
|||||||
|
|
||||||
|
|
||||||
async def test_grouped_lights(
|
async def test_grouped_lights(
|
||||||
hass: HomeAssistant, mock_bridge_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if all v2 grouped lights get created with correct features."""
|
"""Test if all v2 grouped lights get created with correct features."""
|
||||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||||
@ -359,8 +362,7 @@ async def test_grouped_lights(
|
|||||||
|
|
||||||
# test if entities for hue groups are created and enabled by default
|
# test if entities for hue groups are created and enabled by default
|
||||||
for entity_id in ("light.test_zone", "light.test_room"):
|
for entity_id in ("light.test_zone", "light.test_room"):
|
||||||
ent_reg = er.async_get(hass)
|
entity_entry = entity_registry.async_get(entity_id)
|
||||||
entity_entry = ent_reg.async_get(entity_id)
|
|
||||||
|
|
||||||
assert entity_entry
|
assert entity_entry
|
||||||
# scene entities should have be assigned to the room/zone device/service
|
# scene entities should have be assigned to the room/zone device/service
|
||||||
|
@ -44,21 +44,23 @@ async def test_auto_switchover(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def test_light_entity_migration(
|
async def test_light_entity_migration(
|
||||||
hass: HomeAssistant, mock_bridge_v2, mock_config_entry_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
mock_config_entry_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if entity schema for lights migrates from v1 to v2."""
|
"""Test if entity schema for lights migrates from v1 to v2."""
|
||||||
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
# create device/entity with V1 schema in registry
|
# create device/entity with V1 schema in registry
|
||||||
device = dev_reg.async_get_or_create(
|
device = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(hue.DOMAIN, "00:17:88:01:09:aa:bb:65-0b")},
|
identifiers={(hue.DOMAIN, "00:17:88:01:09:aa:bb:65-0b")},
|
||||||
)
|
)
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
hue.DOMAIN,
|
hue.DOMAIN,
|
||||||
"00:17:88:01:09:aa:bb:65-0b",
|
"00:17:88:01:09:aa:bb:65-0b",
|
||||||
@ -77,30 +79,32 @@ async def test_light_entity_migration(
|
|||||||
await hue.migration.handle_v2_migration(hass, config_entry)
|
await hue.migration.handle_v2_migration(hass, config_entry)
|
||||||
|
|
||||||
# migrated device should now have the new identifier (guid) instead of old style (mac)
|
# migrated device should now have the new identifier (guid) instead of old style (mac)
|
||||||
migrated_device = dev_reg.async_get(device.id)
|
migrated_device = device_registry.async_get(device.id)
|
||||||
assert migrated_device is not None
|
assert migrated_device is not None
|
||||||
assert migrated_device.identifiers == {
|
assert migrated_device.identifiers == {
|
||||||
(hue.DOMAIN, "0b216218-d811-4c95-8c55-bbcda50f9d50")
|
(hue.DOMAIN, "0b216218-d811-4c95-8c55-bbcda50f9d50")
|
||||||
}
|
}
|
||||||
# the entity should have the new unique_id (guid)
|
# the entity should have the new unique_id (guid)
|
||||||
migrated_entity = ent_reg.async_get("light.migrated_light_1")
|
migrated_entity = entity_registry.async_get("light.migrated_light_1")
|
||||||
assert migrated_entity is not None
|
assert migrated_entity is not None
|
||||||
assert migrated_entity.unique_id == "02cba059-9c2c-4d45-97e4-4f79b1bfbaa1"
|
assert migrated_entity.unique_id == "02cba059-9c2c-4d45-97e4-4f79b1bfbaa1"
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_entity_migration(
|
async def test_sensor_entity_migration(
|
||||||
hass: HomeAssistant, mock_bridge_v2, mock_config_entry_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
mock_config_entry_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if entity schema for sensors migrates from v1 to v2."""
|
"""Test if entity schema for sensors migrates from v1 to v2."""
|
||||||
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
# create device with V1 schema in registry for Hue motion sensor
|
# create device with V1 schema in registry for Hue motion sensor
|
||||||
device_mac = "00:17:aa:bb:cc:09:ac:c3"
|
device_mac = "00:17:aa:bb:cc:09:ac:c3"
|
||||||
device = dev_reg.async_get_or_create(
|
device = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id, identifiers={(hue.DOMAIN, device_mac)}
|
config_entry_id=config_entry.entry_id, identifiers={(hue.DOMAIN, device_mac)}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -114,7 +118,7 @@ async def test_sensor_entity_migration(
|
|||||||
|
|
||||||
# create entities with V1 schema in registry for Hue motion sensor
|
# create entities with V1 schema in registry for Hue motion sensor
|
||||||
for dev_class, platform, _ in sensor_mappings:
|
for dev_class, platform, _ in sensor_mappings:
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
platform,
|
platform,
|
||||||
hue.DOMAIN,
|
hue.DOMAIN,
|
||||||
f"{device_mac}-{dev_class}",
|
f"{device_mac}-{dev_class}",
|
||||||
@ -134,14 +138,14 @@ async def test_sensor_entity_migration(
|
|||||||
await hue.migration.handle_v2_migration(hass, config_entry)
|
await hue.migration.handle_v2_migration(hass, config_entry)
|
||||||
|
|
||||||
# migrated device should now have the new identifier (guid) instead of old style (mac)
|
# migrated device should now have the new identifier (guid) instead of old style (mac)
|
||||||
migrated_device = dev_reg.async_get(device.id)
|
migrated_device = device_registry.async_get(device.id)
|
||||||
assert migrated_device is not None
|
assert migrated_device is not None
|
||||||
assert migrated_device.identifiers == {
|
assert migrated_device.identifiers == {
|
||||||
(hue.DOMAIN, "2330b45d-6079-4c6e-bba6-1b68afb1a0d6")
|
(hue.DOMAIN, "2330b45d-6079-4c6e-bba6-1b68afb1a0d6")
|
||||||
}
|
}
|
||||||
# the entities should have the correct V2 unique_id (guid)
|
# the entities should have the correct V2 unique_id (guid)
|
||||||
for dev_class, platform, new_id in sensor_mappings:
|
for dev_class, platform, new_id in sensor_mappings:
|
||||||
migrated_entity = ent_reg.async_get(
|
migrated_entity = entity_registry.async_get(
|
||||||
f"{platform}.hue_migrated_{dev_class}_sensor"
|
f"{platform}.hue_migrated_{dev_class}_sensor"
|
||||||
)
|
)
|
||||||
assert migrated_entity is not None
|
assert migrated_entity is not None
|
||||||
@ -149,16 +153,18 @@ async def test_sensor_entity_migration(
|
|||||||
|
|
||||||
|
|
||||||
async def test_group_entity_migration_with_v1_id(
|
async def test_group_entity_migration_with_v1_id(
|
||||||
hass: HomeAssistant, mock_bridge_v2, mock_config_entry_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
mock_config_entry_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if entity schema for grouped_lights migrates from v1 to v2."""
|
"""Test if entity schema for grouped_lights migrates from v1 to v2."""
|
||||||
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
|
|
||||||
# create (deviceless) entity with V1 schema in registry
|
# create (deviceless) entity with V1 schema in registry
|
||||||
# using the legacy style group id as unique id
|
# using the legacy style group id as unique id
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
hue.DOMAIN,
|
hue.DOMAIN,
|
||||||
"3",
|
"3",
|
||||||
@ -176,22 +182,24 @@ async def test_group_entity_migration_with_v1_id(
|
|||||||
await hue.migration.handle_v2_migration(hass, config_entry)
|
await hue.migration.handle_v2_migration(hass, config_entry)
|
||||||
|
|
||||||
# the entity should have the new identifier (guid)
|
# the entity should have the new identifier (guid)
|
||||||
migrated_entity = ent_reg.async_get("light.hue_migrated_grouped_light")
|
migrated_entity = entity_registry.async_get("light.hue_migrated_grouped_light")
|
||||||
assert migrated_entity is not None
|
assert migrated_entity is not None
|
||||||
assert migrated_entity.unique_id == "e937f8db-2f0e-49a0-936e-027e60e15b34"
|
assert migrated_entity.unique_id == "e937f8db-2f0e-49a0-936e-027e60e15b34"
|
||||||
|
|
||||||
|
|
||||||
async def test_group_entity_migration_with_v2_group_id(
|
async def test_group_entity_migration_with_v2_group_id(
|
||||||
hass: HomeAssistant, mock_bridge_v2, mock_config_entry_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
mock_config_entry_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if entity schema for grouped_lights migrates from v1 to v2."""
|
"""Test if entity schema for grouped_lights migrates from v1 to v2."""
|
||||||
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
config_entry = mock_bridge_v2.config_entry = mock_config_entry_v2
|
||||||
|
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
|
|
||||||
# create (deviceless) entity with V1 schema in registry
|
# create (deviceless) entity with V1 schema in registry
|
||||||
# using the V2 group id as unique id
|
# using the V2 group id as unique id
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
hue.DOMAIN,
|
hue.DOMAIN,
|
||||||
"6ddc9066-7e7d-4a03-a773-c73937968296",
|
"6ddc9066-7e7d-4a03-a773-c73937968296",
|
||||||
@ -209,6 +217,6 @@ async def test_group_entity_migration_with_v2_group_id(
|
|||||||
await hue.migration.handle_v2_migration(hass, config_entry)
|
await hue.migration.handle_v2_migration(hass, config_entry)
|
||||||
|
|
||||||
# the entity should have the new identifier (guid)
|
# the entity should have the new identifier (guid)
|
||||||
migrated_entity = ent_reg.async_get("light.hue_migrated_grouped_light")
|
migrated_entity = entity_registry.async_get("light.hue_migrated_grouped_light")
|
||||||
assert migrated_entity is not None
|
assert migrated_entity is not None
|
||||||
assert migrated_entity.unique_id == "e937f8db-2f0e-49a0-936e-027e60e15b34"
|
assert migrated_entity.unique_id == "e937f8db-2f0e-49a0-936e-027e60e15b34"
|
||||||
|
@ -8,7 +8,10 @@ from .const import FAKE_SCENE
|
|||||||
|
|
||||||
|
|
||||||
async def test_scene(
|
async def test_scene(
|
||||||
hass: HomeAssistant, mock_bridge_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if (config) scenes get created."""
|
"""Test if (config) scenes get created."""
|
||||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||||
@ -57,13 +60,12 @@ async def test_scene(
|
|||||||
assert test_entity.attributes["is_active"] is True
|
assert test_entity.attributes["is_active"] is True
|
||||||
|
|
||||||
# scene entities should have be assigned to the room/zone device/service
|
# scene entities should have be assigned to the room/zone device/service
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
for entity_id in (
|
for entity_id in (
|
||||||
"scene.test_zone_dynamic_test_scene",
|
"scene.test_zone_dynamic_test_scene",
|
||||||
"scene.test_room_regular_test_scene",
|
"scene.test_room_regular_test_scene",
|
||||||
"scene.test_room_smart_test_scene",
|
"scene.test_room_smart_test_scene",
|
||||||
):
|
):
|
||||||
entity_entry = ent_reg.async_get(entity_id)
|
entity_entry = entity_registry.async_get(entity_id)
|
||||||
assert entity_entry
|
assert entity_entry
|
||||||
assert entity_entry.device_id is not None
|
assert entity_entry.device_id is not None
|
||||||
|
|
||||||
|
@ -9,7 +9,10 @@ from .const import FAKE_DEVICE, FAKE_SENSOR, FAKE_ZIGBEE_CONNECTIVITY
|
|||||||
|
|
||||||
|
|
||||||
async def test_sensors(
|
async def test_sensors(
|
||||||
hass: HomeAssistant, mock_bridge_v2, v2_resources_test_data
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if all v2 sensors get created with correct features."""
|
"""Test if all v2 sensors get created with correct features."""
|
||||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||||
@ -51,8 +54,7 @@ async def test_sensors(
|
|||||||
|
|
||||||
# test disabled zigbee_connectivity sensor
|
# test disabled zigbee_connectivity sensor
|
||||||
entity_id = "sensor.wall_switch_with_2_controls_zigbee_connectivity"
|
entity_id = "sensor.wall_switch_with_2_controls_zigbee_connectivity"
|
||||||
ent_reg = er.async_get(hass)
|
entity_entry = entity_registry.async_get(entity_id)
|
||||||
entity_entry = ent_reg.async_get(entity_id)
|
|
||||||
|
|
||||||
assert entity_entry
|
assert entity_entry
|
||||||
assert entity_entry.disabled
|
assert entity_entry.disabled
|
||||||
@ -60,7 +62,11 @@ async def test_sensors(
|
|||||||
|
|
||||||
|
|
||||||
async def test_enable_sensor(
|
async def test_enable_sensor(
|
||||||
hass: HomeAssistant, mock_bridge_v2, v2_resources_test_data, mock_config_entry_v2
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_bridge_v2,
|
||||||
|
v2_resources_test_data,
|
||||||
|
mock_config_entry_v2,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test enabling of the by default disabled zigbee_connectivity sensor."""
|
"""Test enabling of the by default disabled zigbee_connectivity sensor."""
|
||||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||||
@ -71,15 +77,14 @@ async def test_enable_sensor(
|
|||||||
await hass.config_entries.async_forward_entry_setup(mock_config_entry_v2, "sensor")
|
await hass.config_entries.async_forward_entry_setup(mock_config_entry_v2, "sensor")
|
||||||
|
|
||||||
entity_id = "sensor.wall_switch_with_2_controls_zigbee_connectivity"
|
entity_id = "sensor.wall_switch_with_2_controls_zigbee_connectivity"
|
||||||
ent_reg = er.async_get(hass)
|
entity_entry = entity_registry.async_get(entity_id)
|
||||||
entity_entry = ent_reg.async_get(entity_id)
|
|
||||||
|
|
||||||
assert entity_entry
|
assert entity_entry
|
||||||
assert entity_entry.disabled
|
assert entity_entry.disabled
|
||||||
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||||
|
|
||||||
# enable the entity
|
# enable the entity
|
||||||
updated_entry = ent_reg.async_update_entity(
|
updated_entry = entity_registry.async_update_entity(
|
||||||
entity_entry.entity_id, **{"disabled_by": None}
|
entity_entry.entity_id, **{"disabled_by": None}
|
||||||
)
|
)
|
||||||
assert updated_entry != entity_entry
|
assert updated_entry != entity_entry
|
||||||
|
@ -9,10 +9,12 @@ from homeassistant.helpers import device_registry as dr
|
|||||||
|
|
||||||
|
|
||||||
def test_zones_in_device_registry(
|
def test_zones_in_device_registry(
|
||||||
hass: HomeAssistant, mock_added_config_entry: ConfigEntry, mock_pydrawise: Mock
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_added_config_entry: ConfigEntry,
|
||||||
|
mock_pydrawise: Mock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that devices are added to the device registry."""
|
"""Test that devices are added to the device registry."""
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
device1 = device_registry.async_get_device(identifiers={(DOMAIN, "5965394")})
|
device1 = device_registry.async_get_device(identifiers={(DOMAIN, "5965394")})
|
||||||
assert device1 is not None
|
assert device1 is not None
|
||||||
@ -26,10 +28,12 @@ def test_zones_in_device_registry(
|
|||||||
|
|
||||||
|
|
||||||
def test_controller_in_device_registry(
|
def test_controller_in_device_registry(
|
||||||
hass: HomeAssistant, mock_added_config_entry: ConfigEntry, mock_pydrawise: Mock
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_added_config_entry: ConfigEntry,
|
||||||
|
mock_pydrawise: Mock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that devices are added to the device registry."""
|
"""Test that devices are added to the device registry."""
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, "52496")})
|
device = device_registry.async_get_device(identifiers={(DOMAIN, "52496")})
|
||||||
assert device is not None
|
assert device is not None
|
||||||
assert device.name == "Home Controller"
|
assert device.name == "Home Controller"
|
||||||
|
@ -177,7 +177,11 @@ async def test_camera_stream_failed_start_stream_call(hass: HomeAssistant) -> No
|
|||||||
assert not client.async_send_image_stream_stop.called
|
assert not client.async_send_image_stream_stop.called
|
||||||
|
|
||||||
|
|
||||||
async def test_device_info(hass: HomeAssistant) -> None:
|
async def test_device_info(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Verify device information includes expected details."""
|
"""Verify device information includes expected details."""
|
||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
|
|
||||||
@ -190,7 +194,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
await setup_test_config_entry(hass, hyperion_client=client)
|
await setup_test_config_entry(hass, hyperion_client=client)
|
||||||
|
|
||||||
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
|
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
|
||||||
assert device
|
assert device
|
||||||
@ -200,7 +203,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
assert device.model == HYPERION_MODEL_NAME
|
assert device.model == HYPERION_MODEL_NAME
|
||||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entities_from_device = [
|
entities_from_device = [
|
||||||
entry.entity_id
|
entry.entity_id
|
||||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||||
|
@ -114,10 +114,11 @@ async def test_setup_config_entry_not_ready_load_state_fail(
|
|||||||
assert hass.states.get(TEST_ENTITY_ID_1) is None
|
assert hass.states.get(TEST_ENTITY_ID_1) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_config_entry_dynamic_instances(hass: HomeAssistant) -> None:
|
async def test_setup_config_entry_dynamic_instances(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test dynamic changes in the instance configuration."""
|
"""Test dynamic changes in the instance configuration."""
|
||||||
registry = er.async_get(hass)
|
|
||||||
|
|
||||||
config_entry = add_test_config_entry(hass)
|
config_entry = add_test_config_entry(hass)
|
||||||
|
|
||||||
master_client = create_mock_client()
|
master_client = create_mock_client()
|
||||||
@ -164,7 +165,7 @@ async def test_setup_config_entry_dynamic_instances(hass: HomeAssistant) -> None
|
|||||||
assert hass.states.get(TEST_ENTITY_ID_3) is not None
|
assert hass.states.get(TEST_ENTITY_ID_3) is not None
|
||||||
|
|
||||||
# Instance 1 is stopped, it should still be registered.
|
# Instance 1 is stopped, it should still be registered.
|
||||||
assert registry.async_is_registered(TEST_ENTITY_ID_1)
|
assert entity_registry.async_is_registered(TEST_ENTITY_ID_1)
|
||||||
|
|
||||||
# == Inject a new instances update (remove instance 1)
|
# == Inject a new instances update (remove instance 1)
|
||||||
assert master_client.set_callbacks.called
|
assert master_client.set_callbacks.called
|
||||||
@ -188,7 +189,7 @@ async def test_setup_config_entry_dynamic_instances(hass: HomeAssistant) -> None
|
|||||||
assert hass.states.get(TEST_ENTITY_ID_3) is not None
|
assert hass.states.get(TEST_ENTITY_ID_3) is not None
|
||||||
|
|
||||||
# Instance 1 is removed, it should not still be registered.
|
# Instance 1 is removed, it should not still be registered.
|
||||||
assert not registry.async_is_registered(TEST_ENTITY_ID_1)
|
assert not entity_registry.async_is_registered(TEST_ENTITY_ID_1)
|
||||||
|
|
||||||
# == Inject a new instances update (re-add instance 1, but not running)
|
# == Inject a new instances update (re-add instance 1, but not running)
|
||||||
with patch(
|
with patch(
|
||||||
@ -766,14 +767,17 @@ async def test_light_option_effect_hide_list(hass: HomeAssistant) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_device_info(hass: HomeAssistant) -> None:
|
async def test_device_info(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Verify device information includes expected details."""
|
"""Verify device information includes expected details."""
|
||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
|
|
||||||
await setup_test_config_entry(hass, hyperion_client=client)
|
await setup_test_config_entry(hass, hyperion_client=client)
|
||||||
|
|
||||||
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
device_id = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
|
device = device_registry.async_get_device(identifiers={(DOMAIN, device_id)})
|
||||||
assert device
|
assert device
|
||||||
@ -783,7 +787,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
assert device.model == HYPERION_MODEL_NAME
|
assert device.model == HYPERION_MODEL_NAME
|
||||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entities_from_device = [
|
entities_from_device = [
|
||||||
entry.entity_id
|
entry.entity_id
|
||||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||||
|
@ -144,7 +144,11 @@ async def test_switch_has_correct_entities(hass: HomeAssistant) -> None:
|
|||||||
assert entity_state, f"Couldn't find entity: {entity_id}"
|
assert entity_state, f"Couldn't find entity: {entity_id}"
|
||||||
|
|
||||||
|
|
||||||
async def test_device_info(hass: HomeAssistant) -> None:
|
async def test_device_info(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Verify device information includes expected details."""
|
"""Verify device information includes expected details."""
|
||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
client.components = TEST_COMPONENTS
|
client.components = TEST_COMPONENTS
|
||||||
@ -162,7 +166,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
assert hass.states.get(TEST_SWITCH_COMPONENT_ALL_ENTITY_ID) is not None
|
assert hass.states.get(TEST_SWITCH_COMPONENT_ALL_ENTITY_ID) is not None
|
||||||
|
|
||||||
device_identifer = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
device_identifer = get_hyperion_device_id(TEST_SYSINFO_ID, TEST_INSTANCE)
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, device_identifer)})
|
device = device_registry.async_get_device(identifiers={(DOMAIN, device_identifer)})
|
||||||
assert device
|
assert device
|
||||||
@ -172,7 +175,6 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
assert device.model == HYPERION_MODEL_NAME
|
assert device.model == HYPERION_MODEL_NAME
|
||||||
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
assert device.name == TEST_INSTANCE_1["friendly_name"]
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entities_from_device = [
|
entities_from_device = [
|
||||||
entry.entity_id
|
entry.entity_id
|
||||||
for entry in er.async_entries_for_device(entity_registry, device.id)
|
for entry in er.async_entries_for_device(entity_registry, device.id)
|
||||||
@ -184,14 +186,14 @@ async def test_device_info(hass: HomeAssistant) -> None:
|
|||||||
assert entity_id in entities_from_device
|
assert entity_id in entities_from_device
|
||||||
|
|
||||||
|
|
||||||
async def test_switches_can_be_enabled(hass: HomeAssistant) -> None:
|
async def test_switches_can_be_enabled(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Verify switches can be enabled."""
|
"""Verify switches can be enabled."""
|
||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
client.components = TEST_COMPONENTS
|
client.components = TEST_COMPONENTS
|
||||||
await setup_test_config_entry(hass, hyperion_client=client)
|
await setup_test_config_entry(hass, hyperion_client=client)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
for component in TEST_COMPONENTS:
|
for component in TEST_COMPONENTS:
|
||||||
name = slugify(KEY_COMPONENTID_TO_NAME[str(component["name"])])
|
name = slugify(KEY_COMPONENTID_TO_NAME[str(component["name"])])
|
||||||
entity_id = TEST_SWITCH_COMPONENT_BASE_ENTITY_ID + "_" + name
|
entity_id = TEST_SWITCH_COMPONENT_BASE_ENTITY_ID + "_" + name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user