Snapshot testing for Plugwise Sensor platform (#153021)

This commit is contained in:
Bouwe Westerdijk
2025-09-26 11:22:14 +02:00
committed by GitHub
parent b17cc71dfb
commit ec0380fd3b
2 changed files with 8125 additions and 98 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3,49 +3,35 @@
from unittest.mock import MagicMock
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.plugwise.const import DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, snapshot_platform
async def test_adam_climate_sensor_entities(
hass: HomeAssistant, mock_smile_adam: MagicMock, init_integration: MockConfigEntry
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_sensor_snapshot(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test creation of climate related sensor entities."""
state = hass.states.get("sensor.adam_outdoor_temperature")
assert state
assert float(state.state) == 7.81
state = hass.states.get("sensor.cv_pomp_electricity_consumed")
assert state
assert float(state.state) == 35.6
state = hass.states.get("sensor.onoff_water_temperature")
assert state
assert float(state.state) == 70.0
state = hass.states.get("sensor.cv_pomp_electricity_consumed_interval")
assert state
assert float(state.state) == 7.37
await async_update_entity(hass, "sensor.zone_lisa_wk_battery")
state = hass.states.get("sensor.zone_lisa_wk_battery")
assert state
assert int(state.state) == 34
"""Test Adam sensor snapshot."""
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
async def test_adam_climate_sensor_entity_2(
async def test_adam_climate_sensor_humidity(
hass: HomeAssistant,
mock_smile_adam_jip: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test creation of climate related sensor entities."""
"""Test creation of climate related humidity sensor entity."""
state = hass.states.get("sensor.woonkamer_humidity")
assert state
assert float(state.state) == 56.2
@@ -96,83 +82,51 @@ async def test_unique_id_migration_humidity(
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
async def test_anna_as_smt_climate_sensor_entities(
hass: HomeAssistant, mock_smile_anna: MagicMock, init_integration: MockConfigEntry
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_sensor_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test creation of climate related sensor entities."""
state = hass.states.get("sensor.opentherm_outdoor_air_temperature")
assert state
assert float(state.state) == 3.0
state = hass.states.get("sensor.opentherm_water_temperature")
assert state
assert float(state.state) == 29.1
state = hass.states.get("sensor.opentherm_dhw_temperature")
assert state
assert float(state.state) == 46.3
state = hass.states.get("sensor.anna_illuminance")
assert state
assert float(state.state) == 86.0
"""Test Anna sensor snapshot."""
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["a455b61e52394b2db5081ce025a430f3"], indirect=True
)
async def test_p1_dsmr_sensor_entities(
hass: HomeAssistant, mock_smile_p1: MagicMock, init_integration: MockConfigEntry
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_p1_dsmr_sensor_snapshot(
hass: HomeAssistant,
mock_smile_p1: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test creation of power related sensor entities."""
state = hass.states.get("sensor.p1_net_electricity_point")
assert state
assert int(state.state) == 486
state = hass.states.get("sensor.p1_electricity_consumed_off_peak_cumulative")
assert state
assert float(state.state) == 17643.423
state = hass.states.get("sensor.p1_electricity_produced_peak_point")
assert state
assert int(state.state) == 0
state = hass.states.get("sensor.p1_electricity_consumed_peak_cumulative")
assert state
assert float(state.state) == 13966.608
state = hass.states.get("sensor.p1_gas_consumed_cumulative")
assert not state
"""Test P1 1-phase sensor snapshot."""
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.parametrize("chosen_env", ["p1v4_442_triple"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["03e65b16e4b247a29ae0d75a78cb492e"], indirect=True
)
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_p1_3ph_dsmr_sensor_entities(
async def test_p1_3ph_dsmr_sensor_snapshot(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_smile_p1: MagicMock,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test creation of power related sensor entities."""
state = hass.states.get("sensor.p1_electricity_phase_one_consumed")
assert state
assert int(state.state) == 1763
state = hass.states.get("sensor.p1_electricity_phase_two_consumed")
assert state
assert int(state.state) == 1703
state = hass.states.get("sensor.p1_electricity_phase_three_consumed")
assert state
assert int(state.state) == 2080
# Default disabled sensor test
state = hass.states.get("sensor.p1_voltage_phase_one")
assert state
assert float(state.state) == 233.2
"""Test P1 3-phase sensor snapshot."""
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.parametrize("chosen_env", ["p1v4_442_triple"], indirect=True)
@@ -186,18 +140,29 @@ async def test_p1_3ph_dsmr_sensor_disabled_entities(
init_integration: MockConfigEntry,
) -> None:
"""Test disabled power related sensor entities intent."""
state = hass.states.get("sensor.p1_voltage_phase_one")
entity_id = "sensor.p1_voltage_phase_one"
state = hass.states.get(entity_id)
assert not state
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async def test_stretch_sensor_entities(
hass: HomeAssistant, mock_stretch: MagicMock, init_integration: MockConfigEntry
await hass.config_entries.async_reload(init_integration.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.p1_voltage_phase_one")
assert state
assert float(state.state) == 233.2
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_stretch_sensor_snapshot(
hass: HomeAssistant,
mock_stretch: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
) -> None:
"""Test creation of power related sensor entities."""
state = hass.states.get("sensor.koelkast_92c4a_electricity_consumed")
assert state
assert float(state.state) == 50.5
state = hass.states.get("sensor.droger_52559_electricity_consumed_interval")
assert state
assert float(state.state) == 0.0
"""Test Stretch sensor snapshot."""
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)