mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use registry fixtures in tests (a-h) (#118288)
This commit is contained in:
parent
e9ab9b818f
commit
8837c50da7
@ -27,8 +27,6 @@ async def test_cover_async_setup_entry(
|
|||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
|
||||||
|
|
||||||
# Test Fresh Air Switch Entity
|
# Test Fresh Air Switch Entity
|
||||||
entity_id = "switch.myzone_fresh_air"
|
entity_id = "switch.myzone_fresh_air"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -61,7 +59,7 @@ async def test_cover_async_setup_entry(
|
|||||||
entity_id = "switch.myzone_myfan"
|
entity_id = "switch.myzone_myfan"
|
||||||
assert hass.states.get(entity_id) == snapshot(name=entity_id)
|
assert hass.states.get(entity_id) == snapshot(name=entity_id)
|
||||||
|
|
||||||
entry = registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-ac1-myfan"
|
assert entry.unique_id == "uniqueid-ac1-myfan"
|
||||||
|
|
||||||
|
@ -144,7 +144,9 @@ async def test_load_and_unload(
|
|||||||
|
|
||||||
|
|
||||||
async def test_stale_device_removal(
|
async def test_stale_device_removal(
|
||||||
hass: HomeAssistant, mock_aladdinconnect_api: MagicMock
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
mock_aladdinconnect_api: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test component setup missing door device is removed."""
|
"""Test component setup missing door device is removed."""
|
||||||
DEVICE_CONFIG_DOOR_2 = {
|
DEVICE_CONFIG_DOOR_2 = {
|
||||||
@ -172,7 +174,6 @@ async def test_stale_device_removal(
|
|||||||
)
|
)
|
||||||
config_entry_other.add_to_hass(hass)
|
config_entry_other.add_to_hass(hass)
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device_entry_other = device_registry.async_get_or_create(
|
device_entry_other = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry_other.entry_id,
|
config_entry_id=config_entry_other.entry_id,
|
||||||
identifiers={("OtherDomain", "533255-2")},
|
identifiers={("OtherDomain", "533255-2")},
|
||||||
@ -193,8 +194,6 @@ async def test_stale_device_removal(
|
|||||||
assert config_entry.state is ConfigEntryState.LOADED
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
device_entries = dr.async_entries_for_config_entry(
|
device_entries = dr.async_entries_for_config_entry(
|
||||||
device_registry, config_entry.entry_id
|
device_registry, config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
@ -378,13 +378,14 @@ async def init_components(hass: HomeAssistant, init_supporting_components):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def assist_device(hass: HomeAssistant, init_components) -> dr.DeviceEntry:
|
async def assist_device(
|
||||||
|
hass: HomeAssistant, device_registry: dr.DeviceRegistry, init_components
|
||||||
|
) -> dr.DeviceEntry:
|
||||||
"""Create an assist device."""
|
"""Create an assist device."""
|
||||||
config_entry = MockConfigEntry(domain="test_assist_device")
|
config_entry = MockConfigEntry(domain="test_assist_device")
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
dev_reg = dr.async_get(hass)
|
device = device_registry.async_get_or_create(
|
||||||
device = dev_reg.async_get_or_create(
|
|
||||||
name="Test Device",
|
name="Test Device",
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={("test_assist_device", "test")},
|
identifiers={("test_assist_device", "test")},
|
||||||
|
@ -88,7 +88,9 @@ grid_entity_ids = {
|
|||||||
|
|
||||||
|
|
||||||
async def test_sensors_created(
|
async def test_sensors_created(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if all sensors are created."""
|
"""Test if all sensors are created."""
|
||||||
await init_integration(
|
await init_integration(
|
||||||
@ -100,8 +102,6 @@ async def test_sensors_created(
|
|||||||
grid,
|
grid,
|
||||||
)
|
)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
sensors = er.async_entries_for_config_entry(entity_registry, "uuid")
|
sensors = er.async_entries_for_config_entry(entity_registry, "uuid")
|
||||||
assert len(charge_point_status) + len(charge_point_status_timestamps) + len(
|
assert len(charge_point_status) + len(charge_point_status_timestamps) + len(
|
||||||
grid
|
grid
|
||||||
@ -109,13 +109,16 @@ async def test_sensors_created(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
async def test_sensors(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
await init_integration(
|
await init_integration(
|
||||||
hass, config_entry, "sensor", charge_point, charge_point_status, grid
|
hass, config_entry, "sensor", charge_point, charge_point_status, grid
|
||||||
)
|
)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
for entity_id, key in charge_point_entity_ids.items():
|
for entity_id, key in charge_point_entity_ids.items():
|
||||||
entry = entity_registry.async_get(f"sensor.101_{entity_id}")
|
entry = entity_registry.async_get(f"sensor.101_{entity_id}")
|
||||||
assert entry
|
assert entry
|
||||||
@ -138,14 +141,15 @@ async def test_sensors(hass: HomeAssistant, config_entry: MockConfigEntry) -> No
|
|||||||
|
|
||||||
|
|
||||||
async def test_timestamp_sensors(
|
async def test_timestamp_sensors(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
await init_integration(
|
await init_integration(
|
||||||
hass, config_entry, "sensor", status=charge_point_status_timestamps
|
hass, config_entry, "sensor", status=charge_point_status_timestamps
|
||||||
)
|
)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
for entity_id, key in charge_point_timestamp_entity_ids.items():
|
for entity_id, key in charge_point_timestamp_entity_ids.items():
|
||||||
entry = entity_registry.async_get(f"sensor.101_{entity_id}")
|
entry = entity_registry.async_get(f"sensor.101_{entity_id}")
|
||||||
assert entry
|
assert entry
|
||||||
|
@ -532,7 +532,10 @@ async def test_ws_delete(
|
|||||||
|
|
||||||
|
|
||||||
async def test_update_min_max(
|
async def test_update_min_max(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
|
hass: HomeAssistant,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
storage_setup,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test updating min/max updates the state."""
|
"""Test updating min/max updates the state."""
|
||||||
|
|
||||||
@ -549,7 +552,6 @@ async def test_update_min_max(
|
|||||||
|
|
||||||
input_id = "from_storage"
|
input_id = "from_storage"
|
||||||
input_entity_id = f"{DOMAIN}.{input_id}"
|
input_entity_id = f"{DOMAIN}.{input_id}"
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
state = hass.states.get(input_entity_id)
|
state = hass.states.get(input_entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
@ -620,7 +622,10 @@ async def test_update_min_max(
|
|||||||
|
|
||||||
|
|
||||||
async def test_create(
|
async def test_create(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
|
hass: HomeAssistant,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
storage_setup,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test creating counter using WS."""
|
"""Test creating counter using WS."""
|
||||||
|
|
||||||
@ -630,7 +635,6 @@ async def test_create(
|
|||||||
|
|
||||||
counter_id = "new_counter"
|
counter_id = "new_counter"
|
||||||
input_entity_id = f"{DOMAIN}.{counter_id}"
|
input_entity_id = f"{DOMAIN}.{counter_id}"
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
state = hass.states.get(input_entity_id)
|
state = hass.states.get(input_entity_id)
|
||||||
assert state is None
|
assert state is None
|
||||||
|
@ -38,14 +38,12 @@ async def setup_enphase_envoy_sensor_fixture(hass, config, mock_envoy):
|
|||||||
|
|
||||||
async def test_sensor(
|
async def test_sensor(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
setup_enphase_envoy_sensor,
|
setup_enphase_envoy_sensor,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test enphase_envoy sensor entities."""
|
"""Test enphase_envoy sensor entities."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
assert entity_registry
|
|
||||||
|
|
||||||
# compare registered entities against snapshot of prior run
|
# compare registered entities against snapshot of prior run
|
||||||
entity_entries = er.async_entries_for_config_entry(
|
entity_entries = er.async_entries_for_config_entry(
|
||||||
entity_registry, config_entry.entry_id
|
entity_registry, config_entry.entry_id
|
||||||
|
@ -32,6 +32,7 @@ from .conftest import MockESPHomeDevice
|
|||||||
|
|
||||||
async def test_entities_removed(
|
async def test_entities_removed(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
hass_storage: dict[str, Any],
|
hass_storage: dict[str, Any],
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
@ -40,7 +41,6 @@ async def test_entities_removed(
|
|||||||
],
|
],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test entities are removed when static info changes."""
|
"""Test entities are removed when static info changes."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
entity_info = [
|
entity_info = [
|
||||||
BinarySensorInfo(
|
BinarySensorInfo(
|
||||||
object_id="mybinary_sensor",
|
object_id="mybinary_sensor",
|
||||||
@ -86,7 +86,9 @@ async def test_entities_removed(
|
|||||||
assert state.attributes[ATTR_RESTORED] is True
|
assert state.attributes[ATTR_RESTORED] is True
|
||||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is not None
|
assert reg_entry is not None
|
||||||
assert state.attributes[ATTR_RESTORED] is True
|
assert state.attributes[ATTR_RESTORED] is True
|
||||||
|
|
||||||
@ -114,7 +116,9 @@ async def test_entities_removed(
|
|||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||||
assert state is None
|
assert state is None
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is None
|
assert reg_entry is None
|
||||||
await hass.config_entries.async_unload(entry.entry_id)
|
await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -123,6 +127,7 @@ async def test_entities_removed(
|
|||||||
|
|
||||||
async def test_entities_removed_after_reload(
|
async def test_entities_removed_after_reload(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
hass_storage: dict[str, Any],
|
hass_storage: dict[str, Any],
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
@ -131,7 +136,6 @@ async def test_entities_removed_after_reload(
|
|||||||
],
|
],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test entities and their registry entry are removed when static info changes after a reload."""
|
"""Test entities and their registry entry are removed when static info changes after a reload."""
|
||||||
ent_reg = er.async_get(hass)
|
|
||||||
entity_info = [
|
entity_info = [
|
||||||
BinarySensorInfo(
|
BinarySensorInfo(
|
||||||
object_id="mybinary_sensor",
|
object_id="mybinary_sensor",
|
||||||
@ -167,7 +171,9 @@ async def test_entities_removed_after_reload(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is not None
|
assert reg_entry is not None
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
@ -182,7 +188,9 @@ async def test_entities_removed_after_reload(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.attributes[ATTR_RESTORED] is True
|
assert state.attributes[ATTR_RESTORED] is True
|
||||||
|
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is not None
|
assert reg_entry is not None
|
||||||
|
|
||||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
@ -196,7 +204,9 @@ async def test_entities_removed_after_reload(
|
|||||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert ATTR_RESTORED not in state.attributes
|
assert ATTR_RESTORED not in state.attributes
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is not None
|
assert reg_entry is not None
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
@ -241,7 +251,9 @@ async def test_entities_removed_after_reload(
|
|||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
reg_entry = ent_reg.async_get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
reg_entry = entity_registry.async_get(
|
||||||
|
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||||
|
)
|
||||||
assert reg_entry is None
|
assert reg_entry is None
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -968,6 +968,7 @@ async def test_esphome_user_services_changes(
|
|||||||
|
|
||||||
async def test_esphome_device_with_suggested_area(
|
async def test_esphome_device_with_suggested_area(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||||
@ -983,9 +984,8 @@ async def test_esphome_device_with_suggested_area(
|
|||||||
states=[],
|
states=[],
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
entry = device.entry
|
entry = device.entry
|
||||||
dev = dev_reg.async_get_device(
|
dev = device_registry.async_get_device(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
||||||
)
|
)
|
||||||
assert dev.suggested_area == "kitchen"
|
assert dev.suggested_area == "kitchen"
|
||||||
@ -993,6 +993,7 @@ async def test_esphome_device_with_suggested_area(
|
|||||||
|
|
||||||
async def test_esphome_device_with_project(
|
async def test_esphome_device_with_project(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||||
@ -1008,9 +1009,8 @@ async def test_esphome_device_with_project(
|
|||||||
states=[],
|
states=[],
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
entry = device.entry
|
entry = device.entry
|
||||||
dev = dev_reg.async_get_device(
|
dev = device_registry.async_get_device(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
||||||
)
|
)
|
||||||
assert dev.manufacturer == "mfr"
|
assert dev.manufacturer == "mfr"
|
||||||
@ -1020,6 +1020,7 @@ async def test_esphome_device_with_project(
|
|||||||
|
|
||||||
async def test_esphome_device_with_manufacturer(
|
async def test_esphome_device_with_manufacturer(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||||
@ -1035,9 +1036,8 @@ async def test_esphome_device_with_manufacturer(
|
|||||||
states=[],
|
states=[],
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
entry = device.entry
|
entry = device.entry
|
||||||
dev = dev_reg.async_get_device(
|
dev = device_registry.async_get_device(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
||||||
)
|
)
|
||||||
assert dev.manufacturer == "acme"
|
assert dev.manufacturer == "acme"
|
||||||
@ -1045,6 +1045,7 @@ async def test_esphome_device_with_manufacturer(
|
|||||||
|
|
||||||
async def test_esphome_device_with_web_server(
|
async def test_esphome_device_with_web_server(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||||
@ -1060,9 +1061,8 @@ async def test_esphome_device_with_web_server(
|
|||||||
states=[],
|
states=[],
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
entry = device.entry
|
entry = device.entry
|
||||||
dev = dev_reg.async_get_device(
|
dev = device_registry.async_get_device(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
||||||
)
|
)
|
||||||
assert dev.configuration_url == "http://test.local:80"
|
assert dev.configuration_url == "http://test.local:80"
|
||||||
@ -1070,6 +1070,7 @@ async def test_esphome_device_with_web_server(
|
|||||||
|
|
||||||
async def test_esphome_device_with_compilation_time(
|
async def test_esphome_device_with_compilation_time(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_esphome_device: Callable[
|
mock_esphome_device: Callable[
|
||||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||||
@ -1085,9 +1086,8 @@ async def test_esphome_device_with_compilation_time(
|
|||||||
states=[],
|
states=[],
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
entry = device.entry
|
entry = device.entry
|
||||||
dev = dev_reg.async_get_device(
|
dev = device_registry.async_get_device(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
|
||||||
)
|
)
|
||||||
assert "comp_time" in dev.sw_version
|
assert "comp_time" in dev.sw_version
|
||||||
|
@ -97,6 +97,7 @@ async def test_generic_numeric_sensor(
|
|||||||
|
|
||||||
async def test_generic_numeric_sensor_with_entity_category_and_icon(
|
async def test_generic_numeric_sensor_with_entity_category_and_icon(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_generic_device_entry,
|
mock_generic_device_entry,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -123,8 +124,7 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "50"
|
assert state.state == "50"
|
||||||
assert state.attributes[ATTR_ICON] == "mdi:leaf"
|
assert state.attributes[ATTR_ICON] == "mdi:leaf"
|
||||||
entity_reg = er.async_get(hass)
|
entry = entity_registry.async_get("sensor.test_mysensor")
|
||||||
entry = entity_reg.async_get("sensor.test_mysensor")
|
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
# Note that ESPHome includes the EntityInfo type in the unique id
|
# Note that ESPHome includes the EntityInfo type in the unique id
|
||||||
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
||||||
@ -134,6 +134,7 @@ async def test_generic_numeric_sensor_with_entity_category_and_icon(
|
|||||||
|
|
||||||
async def test_generic_numeric_sensor_state_class_measurement(
|
async def test_generic_numeric_sensor_state_class_measurement(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_client: APIClient,
|
mock_client: APIClient,
|
||||||
mock_generic_device_entry,
|
mock_generic_device_entry,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -161,8 +162,7 @@ async def test_generic_numeric_sensor_state_class_measurement(
|
|||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "50"
|
assert state.state == "50"
|
||||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
entity_reg = er.async_get(hass)
|
entry = entity_registry.async_get("sensor.test_mysensor")
|
||||||
entry = entity_reg.async_get("sensor.test_mysensor")
|
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
# Note that ESPHome includes the EntityInfo type in the unique id
|
# Note that ESPHome includes the EntityInfo type in the unique id
|
||||||
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
# as this is not a 1:1 mapping to the entity platform (ie. text_sensor)
|
||||||
|
@ -250,6 +250,7 @@ async def test_services(
|
|||||||
service_call: list[dict[str, Any]],
|
service_call: list[dict[str, Any]],
|
||||||
bypass_throttle: Generator[None, Any, None],
|
bypass_throttle: Generator[None, Any, None],
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
integration_setup: Callable[[], Awaitable[bool]],
|
integration_setup: Callable[[], Awaitable[bool]],
|
||||||
setup_credentials: None,
|
setup_credentials: None,
|
||||||
@ -262,7 +263,6 @@ async def test_services(
|
|||||||
assert await integration_setup()
|
assert await integration_setup()
|
||||||
assert config_entry.state == ConfigEntryState.LOADED
|
assert config_entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
device_registry = dr.async_get(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,
|
||||||
identifiers={(DOMAIN, appliance.haId)},
|
identifiers={(DOMAIN, appliance.haId)},
|
||||||
|
@ -52,14 +52,17 @@ async def test_sensor_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
|
||||||
await setup_test_config_entry(hass, hyperion_client=client)
|
await setup_test_config_entry(hass, hyperion_client=client)
|
||||||
|
|
||||||
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
|
||||||
@ -69,7 +72,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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user