mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Update deconz tests to use device & entity registry fixtures (#103703)
This commit is contained in:
parent
d1f1bbe304
commit
81909f7ddf
@ -480,17 +480,17 @@ TEST_DATA = [
|
|||||||
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
|
||||||
async def test_binary_sensors(
|
async def test_binary_sensors(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
mock_deconz_websocket,
|
mock_deconz_websocket,
|
||||||
sensor_data,
|
sensor_data,
|
||||||
expected,
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of binary sensor entities."""
|
"""Test successful creation of binary sensor entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
# Create entity entry to migrate to new unique ID
|
# Create entity entry to migrate to new unique ID
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
expected["old_unique_id"],
|
expected["old_unique_id"],
|
||||||
@ -513,14 +513,14 @@ async def test_binary_sensors(
|
|||||||
|
|
||||||
# Verify entity registry data
|
# Verify entity registry data
|
||||||
|
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -670,7 +670,10 @@ async def test_add_new_binary_sensor(
|
|||||||
|
|
||||||
|
|
||||||
async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
|
async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that adding a new binary sensor is not allowed."""
|
"""Test that adding a new binary sensor is not allowed."""
|
||||||
sensor = {
|
sensor = {
|
||||||
@ -702,7 +705,6 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
|
|||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
assert not hass.states.get("binary_sensor.presence_sensor")
|
assert not hass.states.get("binary_sensor.presence_sensor")
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
assert (
|
assert (
|
||||||
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
||||||
)
|
)
|
||||||
@ -719,7 +721,10 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_service_call(
|
|||||||
|
|
||||||
|
|
||||||
async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
|
async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that adding a new binary sensor is not allowed."""
|
"""Test that adding a new binary sensor is not allowed."""
|
||||||
sensor = {
|
sensor = {
|
||||||
@ -751,7 +756,6 @@ async def test_add_new_binary_sensor_ignored_load_entities_on_options_change(
|
|||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
assert not hass.states.get("binary_sensor.presence_sensor")
|
assert not hass.states.get("binary_sensor.presence_sensor")
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
assert (
|
assert (
|
||||||
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
len(async_entries_for_config_entry(entity_registry, config_entry.entry_id)) == 0
|
||||||
)
|
)
|
||||||
|
@ -101,12 +101,14 @@ TEST_DATA = [
|
|||||||
|
|
||||||
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
||||||
async def test_button(
|
async def test_button(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
raw_data,
|
||||||
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of button entities."""
|
"""Test successful creation of button entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
@ -119,14 +121,14 @@ async def test_button(
|
|||||||
|
|
||||||
# Verify entity registry data
|
# Verify entity registry data
|
||||||
|
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +34,10 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
|||||||
|
|
||||||
|
|
||||||
async def test_deconz_events(
|
async def test_deconz_events(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of deconz events."""
|
"""Test successful creation of deconz events."""
|
||||||
data = {
|
data = {
|
||||||
@ -79,8 +82,6 @@ async def test_deconz_events(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 3
|
assert len(hass.states.async_all()) == 3
|
||||||
# 5 switches + 2 additional devices for deconz service and host
|
# 5 switches + 2 additional devices for deconz service and host
|
||||||
assert (
|
assert (
|
||||||
@ -212,7 +213,10 @@ async def test_deconz_events(
|
|||||||
|
|
||||||
|
|
||||||
async def test_deconz_alarm_events(
|
async def test_deconz_alarm_events(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of deconz alarm events."""
|
"""Test successful creation of deconz alarm events."""
|
||||||
data = {
|
data = {
|
||||||
@ -276,8 +280,6 @@ async def test_deconz_alarm_events(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 4
|
assert len(hass.states.async_all()) == 4
|
||||||
# 1 alarm control device + 2 additional devices for deconz service and host
|
# 1 alarm control device + 2 additional devices for deconz service and host
|
||||||
assert (
|
assert (
|
||||||
@ -424,7 +426,10 @@ async def test_deconz_alarm_events(
|
|||||||
|
|
||||||
|
|
||||||
async def test_deconz_presence_events(
|
async def test_deconz_presence_events(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of deconz presence events."""
|
"""Test successful creation of deconz presence events."""
|
||||||
data = {
|
data = {
|
||||||
@ -457,8 +462,6 @@ async def test_deconz_presence_events(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 5
|
assert len(hass.states.async_all()) == 5
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
@ -527,7 +530,10 @@ async def test_deconz_presence_events(
|
|||||||
|
|
||||||
|
|
||||||
async def test_deconz_relative_rotary_events(
|
async def test_deconz_relative_rotary_events(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
mock_deconz_websocket,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of deconz relative rotary events."""
|
"""Test successful creation of deconz relative rotary events."""
|
||||||
data = {
|
data = {
|
||||||
@ -559,8 +565,6 @@ async def test_deconz_relative_rotary_events(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 1
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
@ -626,7 +630,9 @@ async def test_deconz_relative_rotary_events(
|
|||||||
|
|
||||||
|
|
||||||
async def test_deconz_events_bad_unique_id(
|
async def test_deconz_events_bad_unique_id(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Verify no devices are created if unique id is bad or missing."""
|
"""Verify no devices are created if unique id is bad or missing."""
|
||||||
data = {
|
data = {
|
||||||
@ -649,8 +655,6 @@ async def test_deconz_events_bad_unique_id(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 1
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
|
@ -49,7 +49,10 @@ def automation_calls(hass):
|
|||||||
|
|
||||||
|
|
||||||
async def test_get_triggers(
|
async def test_get_triggers(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test triggers work."""
|
"""Test triggers work."""
|
||||||
data = {
|
data = {
|
||||||
@ -78,11 +81,9 @@ async def test_get_triggers(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
||||||
)
|
)
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
battery_sensor_entry = entity_registry.async_get(
|
battery_sensor_entry = entity_registry.async_get(
|
||||||
"sensor.tradfri_on_off_switch_battery"
|
"sensor.tradfri_on_off_switch_battery"
|
||||||
)
|
)
|
||||||
@ -154,7 +155,10 @@ async def test_get_triggers(
|
|||||||
|
|
||||||
|
|
||||||
async def test_get_triggers_for_alarm_event(
|
async def test_get_triggers_for_alarm_event(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test triggers work."""
|
"""Test triggers work."""
|
||||||
data = {
|
data = {
|
||||||
@ -190,11 +194,9 @@ async def test_get_triggers_for_alarm_event(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, "00:00:00:00:00:00:00:00")}
|
identifiers={(DECONZ_DOMAIN, "00:00:00:00:00:00:00:00")}
|
||||||
)
|
)
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
bat_entity = entity_registry.async_get("sensor.keypad_battery")
|
bat_entity = entity_registry.async_get("sensor.keypad_battery")
|
||||||
low_bat_entity = entity_registry.async_get("binary_sensor.keypad_low_battery")
|
low_bat_entity = entity_registry.async_get("binary_sensor.keypad_low_battery")
|
||||||
tamper_entity = entity_registry.async_get("binary_sensor.keypad_tampered")
|
tamper_entity = entity_registry.async_get("binary_sensor.keypad_tampered")
|
||||||
@ -250,7 +252,9 @@ async def test_get_triggers_for_alarm_event(
|
|||||||
|
|
||||||
|
|
||||||
async def test_get_triggers_manage_unsupported_remotes(
|
async def test_get_triggers_manage_unsupported_remotes(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Verify no triggers for an unsupported remote."""
|
"""Verify no triggers for an unsupported remote."""
|
||||||
data = {
|
data = {
|
||||||
@ -278,7 +282,6 @@ async def test_get_triggers_manage_unsupported_remotes(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
||||||
)
|
)
|
||||||
@ -297,6 +300,7 @@ async def test_functional_device_trigger(
|
|||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
mock_deconz_websocket,
|
mock_deconz_websocket,
|
||||||
automation_calls,
|
automation_calls,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test proper matching and attachment of device trigger automation."""
|
"""Test proper matching and attachment of device trigger automation."""
|
||||||
|
|
||||||
@ -326,7 +330,6 @@ async def test_functional_device_trigger(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")}
|
||||||
)
|
)
|
||||||
@ -403,12 +406,13 @@ async def test_validate_trigger_unknown_device(
|
|||||||
|
|
||||||
|
|
||||||
async def test_validate_trigger_unsupported_device(
|
async def test_validate_trigger_unsupported_device(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unsupported device doesn't return a trigger config."""
|
"""Test unsupported device doesn't return a trigger config."""
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.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={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
||||||
@ -444,12 +448,13 @@ async def test_validate_trigger_unsupported_device(
|
|||||||
|
|
||||||
|
|
||||||
async def test_validate_trigger_unsupported_trigger(
|
async def test_validate_trigger_unsupported_trigger(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unsupported trigger does not return a trigger config."""
|
"""Test unsupported trigger does not return a trigger config."""
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.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={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
||||||
@ -487,12 +492,13 @@ async def test_validate_trigger_unsupported_trigger(
|
|||||||
|
|
||||||
|
|
||||||
async def test_attach_trigger_no_matching_event(
|
async def test_attach_trigger_no_matching_event(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test no matching event for device doesn't return a trigger config."""
|
"""Test no matching event for device doesn't return a trigger config."""
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.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={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
identifiers={(DECONZ_DOMAIN, "d0:cf:5e:ff:fe:71:a4:3a")},
|
||||||
|
@ -139,7 +139,9 @@ async def setup_deconz_integration(
|
|||||||
|
|
||||||
|
|
||||||
async def test_gateway_setup(
|
async def test_gateway_setup(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Successful setup."""
|
"""Successful setup."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -178,7 +180,6 @@ async def test_gateway_setup(
|
|||||||
assert forward_entry_setup.mock_calls[12][1] == (config_entry, SIREN_DOMAIN)
|
assert forward_entry_setup.mock_calls[12][1] == (config_entry, SIREN_DOMAIN)
|
||||||
assert forward_entry_setup.mock_calls[13][1] == (config_entry, SWITCH_DOMAIN)
|
assert forward_entry_setup.mock_calls[13][1] == (config_entry, SWITCH_DOMAIN)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
gateway_entry = device_registry.async_get_device(
|
gateway_entry = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
|
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
|
||||||
)
|
)
|
||||||
@ -188,7 +189,9 @@ async def test_gateway_setup(
|
|||||||
|
|
||||||
|
|
||||||
async def test_gateway_device_configuration_url_when_addon(
|
async def test_gateway_device_configuration_url_when_addon(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Successful setup."""
|
"""Successful setup."""
|
||||||
with patch(
|
with patch(
|
||||||
@ -200,7 +203,6 @@ async def test_gateway_device_configuration_url_when_addon(
|
|||||||
)
|
)
|
||||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
gateway_entry = device_registry.async_get_device(
|
gateway_entry = device_registry.async_get_device(
|
||||||
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
|
identifiers={(DECONZ_DOMAIN, gateway.bridgeid)}
|
||||||
)
|
)
|
||||||
|
@ -159,7 +159,9 @@ async def test_unload_entry_multiple_gateways_parallel(
|
|||||||
assert len(hass.data[DECONZ_DOMAIN]) == 0
|
assert len(hass.data[DECONZ_DOMAIN]) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_update_group_unique_id(hass: HomeAssistant) -> None:
|
async def test_update_group_unique_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test successful migration of entry data."""
|
"""Test successful migration of entry data."""
|
||||||
old_unique_id = "123"
|
old_unique_id = "123"
|
||||||
new_unique_id = "1234"
|
new_unique_id = "1234"
|
||||||
@ -174,9 +176,8 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
|
||||||
# Create entity entry to migrate to new unique ID
|
# Create entity entry to migrate to new unique ID
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
f"{old_unique_id}-OLD",
|
f"{old_unique_id}-OLD",
|
||||||
@ -184,7 +185,7 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
|
|||||||
config_entry=entry,
|
config_entry=entry,
|
||||||
)
|
)
|
||||||
# Create entity entry with new unique ID
|
# Create entity entry with new unique ID
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
f"{new_unique_id}-NEW",
|
f"{new_unique_id}-NEW",
|
||||||
@ -195,11 +196,19 @@ async def test_update_group_unique_id(hass: HomeAssistant) -> None:
|
|||||||
await async_update_group_unique_id(hass, entry)
|
await async_update_group_unique_id(hass, entry)
|
||||||
|
|
||||||
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
|
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
|
||||||
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{new_unique_id}-OLD"
|
assert (
|
||||||
assert registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id == f"{new_unique_id}-NEW"
|
entity_registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id
|
||||||
|
== f"{new_unique_id}-OLD"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
entity_registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id
|
||||||
|
== f"{new_unique_id}-NEW"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) -> None:
|
async def test_update_group_unique_id_no_legacy_group_id(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
|
) -> None:
|
||||||
"""Test migration doesn't trigger without old legacy group id in entry data."""
|
"""Test migration doesn't trigger without old legacy group id in entry data."""
|
||||||
old_unique_id = "123"
|
old_unique_id = "123"
|
||||||
new_unique_id = "1234"
|
new_unique_id = "1234"
|
||||||
@ -209,9 +218,8 @@ async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) ->
|
|||||||
data={},
|
data={},
|
||||||
)
|
)
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
|
||||||
# Create entity entry to migrate to new unique ID
|
# Create entity entry to migrate to new unique ID
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
f"{old_unique_id}-OLD",
|
f"{old_unique_id}-OLD",
|
||||||
@ -221,4 +229,7 @@ async def test_update_group_unique_id_no_legacy_group_id(hass: HomeAssistant) ->
|
|||||||
|
|
||||||
await async_update_group_unique_id(hass, entry)
|
await async_update_group_unique_id(hass, entry)
|
||||||
|
|
||||||
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{old_unique_id}-OLD"
|
assert (
|
||||||
|
entity_registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id
|
||||||
|
== f"{old_unique_id}-OLD"
|
||||||
|
)
|
||||||
|
@ -27,7 +27,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
|||||||
|
|
||||||
|
|
||||||
async def test_humanifying_deconz_alarm_event(
|
async def test_humanifying_deconz_alarm_event(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test humanifying deCONZ event."""
|
"""Test humanifying deCONZ event."""
|
||||||
data = {
|
data = {
|
||||||
@ -61,8 +63,6 @@ async def test_humanifying_deconz_alarm_event(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
keypad_event_id = slugify(data["sensors"]["1"]["name"])
|
keypad_event_id = slugify(data["sensors"]["1"]["name"])
|
||||||
keypad_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
|
keypad_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
|
||||||
keypad_entry = device_registry.async_get_device(
|
keypad_entry = device_registry.async_get_device(
|
||||||
@ -112,7 +112,9 @@ async def test_humanifying_deconz_alarm_event(
|
|||||||
|
|
||||||
|
|
||||||
async def test_humanifying_deconz_event(
|
async def test_humanifying_deconz_event(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test humanifying deCONZ event."""
|
"""Test humanifying deCONZ event."""
|
||||||
data = {
|
data = {
|
||||||
@ -152,8 +154,6 @@ async def test_humanifying_deconz_event(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
switch_event_id = slugify(data["sensors"]["1"]["name"])
|
switch_event_id = slugify(data["sensors"]["1"]["name"])
|
||||||
switch_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
|
switch_serial = serial_from_unique_id(data["sensors"]["1"]["uniqueid"])
|
||||||
switch_entry = device_registry.async_get_device(
|
switch_entry = device_registry.async_get_device(
|
||||||
|
@ -111,17 +111,17 @@ TEST_DATA = [
|
|||||||
async def test_number_entities(
|
async def test_number_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_deconz_websocket,
|
mock_deconz_websocket,
|
||||||
sensor_data,
|
sensor_data,
|
||||||
expected,
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of number entities."""
|
"""Test successful creation of number entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
# Create entity entry to migrate to new unique ID
|
# Create entity entry to migrate to new unique ID
|
||||||
if "old_unique_id" in expected:
|
if "old_unique_id" in expected:
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
NUMBER_DOMAIN,
|
NUMBER_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
expected["old_unique_id"],
|
expected["old_unique_id"],
|
||||||
@ -141,14 +141,14 @@ async def test_number_entities(
|
|||||||
|
|
||||||
# Verify entity registry data
|
# Verify entity registry data
|
||||||
|
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,12 +57,14 @@ TEST_DATA = [
|
|||||||
|
|
||||||
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
||||||
async def test_scenes(
|
async def test_scenes(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
raw_data,
|
||||||
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of scene entities."""
|
"""Test successful creation of scene entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
@ -75,14 +77,14 @@ async def test_scenes(
|
|||||||
|
|
||||||
# Verify entity registry data
|
# Verify entity registry data
|
||||||
|
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -168,12 +168,14 @@ TEST_DATA = [
|
|||||||
|
|
||||||
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("raw_data", "expected"), TEST_DATA)
|
||||||
async def test_select(
|
async def test_select(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, raw_data, expected
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
raw_data,
|
||||||
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of button entities."""
|
"""Test successful creation of button entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
with patch.dict(DECONZ_WEB_REQUEST, raw_data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
@ -186,14 +188,14 @@ async def test_select(
|
|||||||
|
|
||||||
# Verify entity registry data
|
# Verify entity registry data
|
||||||
|
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry data
|
# Verify device registry data
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -792,18 +792,18 @@ TEST_DATA = [
|
|||||||
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
|
@pytest.mark.parametrize(("sensor_data", "expected"), TEST_DATA)
|
||||||
async def test_sensors(
|
async def test_sensors(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
mock_deconz_websocket,
|
mock_deconz_websocket,
|
||||||
sensor_data,
|
sensor_data,
|
||||||
expected,
|
expected,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of sensor entities."""
|
"""Test successful creation of sensor entities."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
# Create entity entry to migrate to new unique ID
|
# Create entity entry to migrate to new unique ID
|
||||||
if "old_unique_id" in expected:
|
if "old_unique_id" in expected:
|
||||||
ent_reg.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
expected["old_unique_id"],
|
expected["old_unique_id"],
|
||||||
@ -817,7 +817,9 @@ async def test_sensors(
|
|||||||
|
|
||||||
# Enable in entity registry
|
# Enable in entity registry
|
||||||
if expected.get("enable_entity"):
|
if expected.get("enable_entity"):
|
||||||
ent_reg.async_update_entity(entity_id=expected["entity_id"], disabled_by=None)
|
entity_registry.async_update_entity(
|
||||||
|
entity_id=expected["entity_id"], disabled_by=None
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_time_changed(
|
async_fire_time_changed(
|
||||||
@ -836,16 +838,16 @@ async def test_sensors(
|
|||||||
|
|
||||||
# Verify entity registry
|
# Verify entity registry
|
||||||
assert (
|
assert (
|
||||||
ent_reg.async_get(expected["entity_id"]).entity_category
|
entity_registry.async_get(expected["entity_id"]).entity_category
|
||||||
is expected["entity_category"]
|
is expected["entity_category"]
|
||||||
)
|
)
|
||||||
ent_reg_entry = ent_reg.async_get(expected["entity_id"])
|
ent_reg_entry = entity_registry.async_get(expected["entity_id"])
|
||||||
assert ent_reg_entry.entity_category is expected["entity_category"]
|
assert ent_reg_entry.entity_category is expected["entity_category"]
|
||||||
assert ent_reg_entry.unique_id == expected["unique_id"]
|
assert ent_reg_entry.unique_id == expected["unique_id"]
|
||||||
|
|
||||||
# Verify device registry
|
# Verify device registry
|
||||||
assert (
|
assert (
|
||||||
len(dr.async_entries_for_config_entry(dev_reg, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== expected["device_count"]
|
== expected["device_count"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -349,7 +349,10 @@ async def test_service_refresh_devices_trigger_no_state_update(
|
|||||||
|
|
||||||
|
|
||||||
async def test_remove_orphaned_entries_service(
|
async def test_remove_orphaned_entries_service(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test service works and also don't remove more than expected."""
|
"""Test service works and also don't remove more than expected."""
|
||||||
data = {
|
data = {
|
||||||
@ -374,7 +377,6 @@ async def test_remove_orphaned_entries_service(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device = device_registry.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,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, "123")},
|
connections={(dr.CONNECTION_NETWORK_MAC, "123")},
|
||||||
@ -391,7 +393,6 @@ async def test_remove_orphaned_entries_service(
|
|||||||
== 5 # Host, gateway, light, switch and orphan
|
== 5 # Host, gateway, light, switch and orphan
|
||||||
)
|
)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
DECONZ_DOMAIN,
|
DECONZ_DOMAIN,
|
||||||
|
@ -119,13 +119,14 @@ async def test_power_plugs(
|
|||||||
|
|
||||||
|
|
||||||
async def test_remove_legacy_on_off_output_as_light(
|
async def test_remove_legacy_on_off_output_as_light(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that switch platform cleans up legacy light entities."""
|
"""Test that switch platform cleans up legacy light entities."""
|
||||||
unique_id = "00:00:00:00:00:00:00:00-00"
|
unique_id = "00:00:00:00:00:00:00:00-00"
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
switch_light_entity = entity_registry.async_get_or_create(
|
||||||
switch_light_entity = registry.async_get_or_create(
|
|
||||||
LIGHT_DOMAIN, DECONZ_DOMAIN, unique_id
|
LIGHT_DOMAIN, DECONZ_DOMAIN, unique_id
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -144,6 +145,6 @@ async def test_remove_legacy_on_off_output_as_light(
|
|||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
assert not registry.async_get("light.on_off_output_device")
|
assert not entity_registry.async_get("light.on_off_output_device")
|
||||||
assert registry.async_get("switch.on_off_output_device")
|
assert entity_registry.async_get("switch.on_off_output_device")
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user