Use snapshot test helper in Ambient Network (#115887)

This commit is contained in:
Joost Lekkerkerker 2024-04-20 21:29:14 +02:00 committed by GitHub
parent ee116713cf
commit 48d1692cd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 110 additions and 23 deletions

View file

@ -10,7 +10,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_absolute_pressure', 'entity_id': 'sensor.station_a_absolute_pressure',
@ -22,6 +22,9 @@
}), }),
'name': None, 'name': None,
'options': dict({ 'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
'sensor.private': dict({ 'sensor.private': dict({
'suggested_unit_of_measurement': <UnitOfPressure.HPA: 'hPa'>, 'suggested_unit_of_measurement': <UnitOfPressure.HPA: 'hPa'>,
}), }),
@ -38,7 +41,21 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_absolute_pressure-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_absolute_pressure-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'device_class': 'pressure',
'friendly_name': 'Station A Absolute pressure',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPressure.HPA: 'hPa'>,
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_absolute_pressure',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '977.616536580043',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_daily_rain-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_daily_rain-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
@ -332,7 +349,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_irradiance', 'entity_id': 'sensor.station_a_irradiance',
@ -344,6 +361,9 @@
}), }),
'name': None, 'name': None,
'options': dict({ 'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
}), }),
'original_device_class': <SensorDeviceClass.IRRADIANCE: 'irradiance'>, 'original_device_class': <SensorDeviceClass.IRRADIANCE: 'irradiance'>,
'original_icon': None, 'original_icon': None,
@ -357,7 +377,21 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_irradiance-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_irradiance-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'device_class': 'irradiance',
'friendly_name': 'Station A Irradiance',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfIrradiance.WATTS_PER_SQUARE_METER: 'W/m²'>,
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_irradiance',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '37.64',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_last_rain-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_last_rain-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
@ -368,7 +402,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_last_rain', 'entity_id': 'sensor.station_a_last_rain',
@ -393,7 +427,19 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_last_rain-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_last_rain-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'device_class': 'timestamp',
'friendly_name': 'Station A Last rain',
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_last_rain',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2023-10-30T09:45:00+00:00',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_max_daily_gust-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_max_daily_gust-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
@ -464,7 +510,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_monthly_rain', 'entity_id': 'sensor.station_a_monthly_rain',
@ -476,6 +522,9 @@
}), }),
'name': None, 'name': None,
'options': dict({ 'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
'sensor.private': dict({ 'sensor.private': dict({
'suggested_unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>, 'suggested_unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>,
}), }),
@ -492,7 +541,21 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_monthly_rain-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_monthly_rain-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'device_class': 'precipitation',
'friendly_name': 'Station A Monthly rain',
'state_class': <SensorStateClass.TOTAL: 'total'>,
'unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>,
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_monthly_rain',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.0',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_relative_pressure-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_relative_pressure-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
@ -672,7 +735,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_weekly_rain', 'entity_id': 'sensor.station_a_weekly_rain',
@ -684,6 +747,9 @@
}), }),
'name': None, 'name': None,
'options': dict({ 'options': dict({
'sensor': dict({
'suggested_display_precision': 1,
}),
'sensor.private': dict({ 'sensor.private': dict({
'suggested_unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>, 'suggested_unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>,
}), }),
@ -700,7 +766,21 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_weekly_rain-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_weekly_rain-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'device_class': 'precipitation',
'friendly_name': 'Station A Weekly rain',
'state_class': <SensorStateClass.TOTAL: 'total'>,
'unit_of_measurement': <UnitOfLength.MILLIMETERS: 'mm'>,
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_weekly_rain',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.0',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_direction-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_direction-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
@ -711,7 +791,7 @@
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>, 'disabled_by': None,
'domain': 'sensor', 'domain': 'sensor',
'entity_category': None, 'entity_category': None,
'entity_id': 'sensor.station_a_wind_direction', 'entity_id': 'sensor.station_a_wind_direction',
@ -723,6 +803,9 @@
}), }),
'name': None, 'name': None,
'options': dict({ 'options': dict({
'sensor': dict({
'suggested_display_precision': 0,
}),
}), }),
'original_device_class': None, 'original_device_class': None,
'original_icon': None, 'original_icon': None,
@ -736,7 +819,19 @@
}) })
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_direction-state] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_direction-state]
None StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by ambientnetwork.net',
'friendly_name': 'Station A Wind direction',
'unit_of_measurement': '°',
}),
'context': <ANY>,
'entity_id': 'sensor.station_a_wind_direction',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '11',
})
# --- # ---
# name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_gust-entry] # name: test_sensors[AA:AA:AA:AA:AA:AA][sensor.station_a_wind_gust-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({

View file

@ -14,11 +14,12 @@ from homeassistant.helpers import entity_registry as er
from .conftest import setup_platform from .conftest import setup_platform
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed, snapshot_platform
@freeze_time("2023-11-08") @freeze_time("2023-11-08")
@pytest.mark.parametrize("config_entry", ["AA:AA:AA:AA:AA:AA"], indirect=True) @pytest.mark.parametrize("config_entry", ["AA:AA:AA:AA:AA:AA"], indirect=True)
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors( async def test_sensors(
hass: HomeAssistant, hass: HomeAssistant,
open_api: OpenAPI, open_api: OpenAPI,
@ -30,16 +31,7 @@ async def test_sensors(
"""Test all sensors under normal operation.""" """Test all sensors under normal operation."""
await setup_platform(True, hass, config_entry) await setup_platform(True, hass, config_entry)
entity_entries = er.async_entries_for_config_entry( await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
entity_registry, config_entry.entry_id
)
assert entity_entries
for entity_entry in entity_entries:
assert hass.states.get(entity_entry.entity_id) == snapshot(
name=f"{entity_entry.entity_id}-state"
)
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
@freeze_time("2023-11-09") @freeze_time("2023-11-09")