mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Avoid mutating entity descriptions in efergy tests (#105717)
This commit is contained in:
parent
7721840298
commit
9095027363
@ -1,7 +1,8 @@
|
|||||||
"""The tests for Efergy sensor platform."""
|
"""The tests for Efergy sensor platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.efergy.sensor import SENSOR_TYPES
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
ATTR_STATE_CLASS,
|
ATTR_STATE_CLASS,
|
||||||
DOMAIN as SENSOR_DOMAIN,
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
@ -25,15 +26,18 @@ from tests.common import async_fire_time_changed
|
|||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def enable_all_entities(entity_registry_enabled_by_default):
|
||||||
|
"""Make sure all entities are enabled."""
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_readings(
|
async def test_sensor_readings(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for successfully setting up the Efergy platform."""
|
"""Test for successfully setting up the Efergy platform."""
|
||||||
for description in SENSOR_TYPES:
|
await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
|
||||||
description.entity_registry_enabled_default = True
|
|
||||||
entry = await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
|
|
||||||
|
|
||||||
state = hass.states.get("sensor.efergy_power_usage")
|
state = hass.states.get("sensor.efergy_power_usage")
|
||||||
assert state.state == "1580"
|
assert state.state == "1580"
|
||||||
@ -85,11 +89,6 @@ async def test_sensor_readings(
|
|||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||||
entity = entity_registry.async_get("sensor.efergy_power_usage_728386")
|
|
||||||
assert entity.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
|
||||||
entity_registry.async_update_entity(entity.entity_id, **{"disabled_by": None})
|
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
state = hass.states.get("sensor.efergy_power_usage_728386")
|
state = hass.states.get("sensor.efergy_power_usage_728386")
|
||||||
assert state.state == "1628"
|
assert state.state == "1628"
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||||
@ -101,8 +100,6 @@ async def test_multi_sensor_readings(
|
|||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for multiple sensors in one household."""
|
"""Test for multiple sensors in one household."""
|
||||||
for description in SENSOR_TYPES:
|
|
||||||
description.entity_registry_enabled_default = True
|
|
||||||
await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN, MULTI_SENSOR_TOKEN)
|
await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN, MULTI_SENSOR_TOKEN)
|
||||||
state = hass.states.get("sensor.efergy_power_usage_728386")
|
state = hass.states.get("sensor.efergy_power_usage_728386")
|
||||||
assert state.state == "218"
|
assert state.state == "218"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user