mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Adjust helpers tests which create devices (#98214)
This commit is contained in:
parent
f1d4a4bd26
commit
c7b4d4f361
@ -1360,6 +1360,7 @@ async def test_friendly_name_updated(
|
|||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
|
@ -1062,8 +1062,10 @@ async def test_entity_registry_updates_invalid_entity_id(hass: HomeAssistant) ->
|
|||||||
async def test_device_info_called(hass: HomeAssistant) -> None:
|
async def test_device_info_called(hass: HomeAssistant) -> None:
|
||||||
"""Test device info is forwarded correctly."""
|
"""Test device info is forwarded correctly."""
|
||||||
registry = dr.async_get(hass)
|
registry = dr.async_get(hass)
|
||||||
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
via = registry.async_get_or_create(
|
via = registry.async_get_or_create(
|
||||||
config_entry_id="123",
|
config_entry_id=config_entry.entry_id,
|
||||||
connections=set(),
|
connections=set(),
|
||||||
identifiers={("hue", "via-id")},
|
identifiers={("hue", "via-id")},
|
||||||
manufacturer="manufacturer",
|
manufacturer="manufacturer",
|
||||||
@ -1098,7 +1100,6 @@ async def test_device_info_called(hass: HomeAssistant) -> None:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1126,8 +1127,10 @@ async def test_device_info_called(hass: HomeAssistant) -> None:
|
|||||||
async def test_device_info_not_overrides(hass: HomeAssistant) -> None:
|
async def test_device_info_not_overrides(hass: HomeAssistant) -> None:
|
||||||
"""Test device info is forwarded correctly."""
|
"""Test device info is forwarded correctly."""
|
||||||
registry = dr.async_get(hass)
|
registry = dr.async_get(hass)
|
||||||
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
device = registry.async_get_or_create(
|
device = registry.async_get_or_create(
|
||||||
config_entry_id="bla",
|
config_entry_id=config_entry.entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, "abcd")},
|
connections={(dr.CONNECTION_NETWORK_MAC, "abcd")},
|
||||||
manufacturer="test-manufacturer",
|
manufacturer="test-manufacturer",
|
||||||
model="test-model",
|
model="test-model",
|
||||||
@ -1154,7 +1157,6 @@ async def test_device_info_not_overrides(hass: HomeAssistant) -> None:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1176,8 +1178,10 @@ async def test_device_info_homeassistant_url(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test device info with homeassistant URL."""
|
"""Test device info with homeassistant URL."""
|
||||||
registry = dr.async_get(hass)
|
registry = dr.async_get(hass)
|
||||||
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
config_entry_id="123",
|
config_entry_id=config_entry.entry_id,
|
||||||
connections=set(),
|
connections=set(),
|
||||||
identifiers={("mqtt", "via-id")},
|
identifiers={("mqtt", "via-id")},
|
||||||
manufacturer="manufacturer",
|
manufacturer="manufacturer",
|
||||||
@ -1201,7 +1205,6 @@ async def test_device_info_homeassistant_url(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1222,8 +1225,10 @@ async def test_device_info_change_to_no_url(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test device info changes to no URL."""
|
"""Test device info changes to no URL."""
|
||||||
registry = dr.async_get(hass)
|
registry = dr.async_get(hass)
|
||||||
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
registry.async_get_or_create(
|
registry.async_get_or_create(
|
||||||
config_entry_id="123",
|
config_entry_id=config_entry.entry_id,
|
||||||
connections=set(),
|
connections=set(),
|
||||||
identifiers={("mqtt", "via-id")},
|
identifiers={("mqtt", "via-id")},
|
||||||
manufacturer="manufacturer",
|
manufacturer="manufacturer",
|
||||||
@ -1248,7 +1253,6 @@ async def test_device_info_change_to_no_url(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1304,6 +1308,7 @@ async def test_entity_disabled_by_device(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id", domain=DOMAIN)
|
config_entry = MockConfigEntry(entry_id="super-mock-id", domain=DOMAIN)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1621,6 +1626,7 @@ async def test_entity_name_influences_entity_id(
|
|||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1690,6 +1696,7 @@ async def test_translated_entity_name_influences_entity_id(
|
|||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1773,6 +1780,7 @@ async def test_translated_device_class_name_influences_entity_id(
|
|||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
@ -1878,6 +1886,7 @@ async def test_device_type_error_checking(
|
|||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
title="Mock Config Entry Title", entry_id="super-mock-id"
|
title="Mock Config Entry Title", entry_id="super-mock-id"
|
||||||
)
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
hass, platform_name=config_entry.domain, platform=platform
|
hass, platform_name=config_entry.domain, platform=platform
|
||||||
)
|
)
|
||||||
|
@ -1017,6 +1017,7 @@ async def test_remove_device_removes_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we remove entities tied to a device."""
|
"""Test that we remove entities tied to a device."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
device_entry = device_registry.async_get_or_create(
|
device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
@ -1046,7 +1047,9 @@ async def test_remove_config_entry_from_device_removes_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we remove entities tied to a device when config entry is removed."""
|
"""Test that we remove entities tied to a device when config entry is removed."""
|
||||||
config_entry_1 = MockConfigEntry(domain="hue")
|
config_entry_1 = MockConfigEntry(domain="hue")
|
||||||
|
config_entry_1.add_to_hass(hass)
|
||||||
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
||||||
|
config_entry_2.add_to_hass(hass)
|
||||||
|
|
||||||
# Create device with two config entries
|
# Create device with two config entries
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
@ -1112,7 +1115,9 @@ async def test_remove_config_entry_from_device_removes_entities_2(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we don't remove entities with no config entry when device is modified."""
|
"""Test that we don't remove entities with no config entry when device is modified."""
|
||||||
config_entry_1 = MockConfigEntry(domain="hue")
|
config_entry_1 = MockConfigEntry(domain="hue")
|
||||||
|
config_entry_1.add_to_hass(hass)
|
||||||
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
config_entry_2 = MockConfigEntry(domain="device_tracker")
|
||||||
|
config_entry_2.add_to_hass(hass)
|
||||||
|
|
||||||
# Create device with two config entries
|
# Create device with two config entries
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
@ -1155,6 +1160,7 @@ async def test_update_device_race(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test race when a device is created, updated and removed."""
|
"""Test race when a device is created, updated and removed."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Create device
|
# Create device
|
||||||
device_entry = device_registry.async_get_or_create(
|
device_entry = device_registry.async_get_or_create(
|
||||||
@ -1331,6 +1337,7 @@ async def test_disabled_entities_excluded_from_entity_list(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test that disabled entities are excluded from async_entries_for_device."""
|
"""Test that disabled entities are excluded from async_entries_for_device."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
device_entry = device_registry.async_get_or_create(
|
device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
|
@ -18,6 +18,8 @@ from homeassistant.helpers import (
|
|||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
class MockIntentHandler(intent.IntentHandler):
|
class MockIntentHandler(intent.IntentHandler):
|
||||||
"""Provide a mock intent handler."""
|
"""Provide a mock intent handler."""
|
||||||
@ -116,11 +118,15 @@ async def test_match_device_area(
|
|||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test async_match_state with a device in an area."""
|
"""Test async_match_state with a device in an area."""
|
||||||
|
config_entry = MockConfigEntry()
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
area_kitchen = area_registry.async_get_or_create("kitchen")
|
area_kitchen = area_registry.async_get_or_create("kitchen")
|
||||||
area_bedroom = area_registry.async_get_or_create("bedroom")
|
area_bedroom = area_registry.async_get_or_create("bedroom")
|
||||||
|
|
||||||
kitchen_device = device_registry.async_get_or_create(
|
kitchen_device = device_registry.async_get_or_create(
|
||||||
config_entry_id="1234", connections=set(), identifiers={("demo", "id-1234")}
|
config_entry_id=config_entry.entry_id,
|
||||||
|
connections=set(),
|
||||||
|
identifiers={("demo", "id-1234")},
|
||||||
)
|
)
|
||||||
device_registry.async_update_device(kitchen_device.id, area_id=area_kitchen.id)
|
device_registry.async_update_device(kitchen_device.id, area_id=area_kitchen.id)
|
||||||
|
|
||||||
|
@ -2709,6 +2709,7 @@ async def test_device_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test device_entities function."""
|
"""Test device_entities function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing device ids
|
# Test non existing device ids
|
||||||
info = render_to_info(hass, "{{ device_entities('abc123') }}")
|
info = render_to_info(hass, "{{ device_entities('abc123') }}")
|
||||||
@ -2858,6 +2859,7 @@ async def test_device_id(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test device_id function."""
|
"""Test device_id function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
device_entry = device_registry.async_get_or_create(
|
device_entry = 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, "12:34:56:AB:CD:EF")},
|
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
@ -2903,6 +2905,7 @@ async def test_device_attr(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test device_attr and is_device_attr functions."""
|
"""Test device_attr and is_device_attr functions."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing device ids (device_attr)
|
# Test non existing device ids (device_attr)
|
||||||
info = render_to_info(hass, "{{ device_attr('abc123', 'id') }}")
|
info = render_to_info(hass, "{{ device_attr('abc123', 'id') }}")
|
||||||
@ -3049,6 +3052,7 @@ async def test_area_id(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test area_id function."""
|
"""Test area_id function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing entity id
|
# Test non existing entity id
|
||||||
info = render_to_info(hass, "{{ area_id('sensor.fake') }}")
|
info = render_to_info(hass, "{{ area_id('sensor.fake') }}")
|
||||||
@ -3155,6 +3159,7 @@ async def test_area_name(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test area_name function."""
|
"""Test area_name function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing entity id
|
# Test non existing entity id
|
||||||
info = render_to_info(hass, "{{ area_name('sensor.fake') }}")
|
info = render_to_info(hass, "{{ area_name('sensor.fake') }}")
|
||||||
@ -3236,6 +3241,7 @@ async def test_area_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test area_entities function."""
|
"""Test area_entities function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing device id
|
# Test non existing device id
|
||||||
info = render_to_info(hass, "{{ area_entities('deadbeef') }}")
|
info = render_to_info(hass, "{{ area_entities('deadbeef') }}")
|
||||||
@ -3290,6 +3296,7 @@ async def test_area_devices(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test area_devices function."""
|
"""Test area_devices function."""
|
||||||
config_entry = MockConfigEntry(domain="light")
|
config_entry = MockConfigEntry(domain="light")
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Test non existing device id
|
# Test non existing device id
|
||||||
info = render_to_info(hass, "{{ area_devices('deadbeef') }}")
|
info = render_to_info(hass, "{{ area_devices('deadbeef') }}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user