57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
|
"""The tests for the utility_meter select platform."""
|
||
|
|
||
|
from homeassistant.components.utility_meter.const import DOMAIN
|
||
|
from homeassistant.core import HomeAssistant
|
||
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||
|
|
||
|
from tests.common import MockConfigEntry
|
||
|
|
||
|
|
||
|
async def test_device_id(
|
||
|
hass: HomeAssistant,
|
||
|
device_registry: dr.DeviceRegistry,
|
||
|
entity_registry: er.EntityRegistry,
|
||
|
) -> None:
|
||
|
"""Test for source entity device for Utility Meter."""
|
||
|
source_config_entry = MockConfigEntry()
|
||
|
source_config_entry.add_to_hass(hass)
|
||
|
source_device_entry = device_registry.async_get_or_create(
|
||
|
config_entry_id=source_config_entry.entry_id,
|
||
|
identifiers={("sensor", "identifier_test")},
|
||
|
connections={("mac", "30:31:32:33:34:35")},
|
||
|
)
|
||
|
source_entity = entity_registry.async_get_or_create(
|
||
|
"sensor",
|
||
|
"test",
|
||
|
"source",
|
||
|
config_entry=source_config_entry,
|
||
|
device_id=source_device_entry.id,
|
||
|
)
|
||
|
await hass.async_block_till_done()
|
||
|
assert entity_registry.async_get("sensor.test_source") is not None
|
||
|
|
||
|
utility_meter_config_entry = MockConfigEntry(
|
||
|
data={},
|
||
|
domain=DOMAIN,
|
||
|
options={
|
||
|
"cycle": "monthly",
|
||
|
"delta_values": False,
|
||
|
"name": "Energy",
|
||
|
"net_consumption": False,
|
||
|
"offset": 0,
|
||
|
"periodically_resetting": True,
|
||
|
"source": "sensor.test_source",
|
||
|
"tariffs": ["peak", "offpeak"],
|
||
|
},
|
||
|
title="Energy",
|
||
|
)
|
||
|
|
||
|
utility_meter_config_entry.add_to_hass(hass)
|
||
|
|
||
|
assert await hass.config_entries.async_setup(utility_meter_config_entry.entry_id)
|
||
|
await hass.async_block_till_done()
|
||
|
|
||
|
utility_meter_entity_select = entity_registry.async_get("select.energy")
|
||
|
assert utility_meter_entity_select is not None
|
||
|
assert utility_meter_entity_select.device_id == source_entity.device_id
|