mirror of
https://github.com/home-assistant/core.git
synced 2026-09-13 20:20:10 +01:00
Use snapshot_platform helper in aemet weather tests (#181816)
This commit is contained in:
@@ -1,4 +1,67 @@
|
||||
# serializer version: 1
|
||||
# name: test_all_entities[weather.aemet-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'weather',
|
||||
'entity_category': None,
|
||||
'entity_id': 'weather.aemet',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'aemet',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <WeatherEntityFeature: 3>,
|
||||
'translation_key': None,
|
||||
'unique_id': '40.30403754--3.72935236',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[weather.aemet-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.ATTRIBUTION: 'attribution'>: 'Powered by AEMET OpenData',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'AEMET',
|
||||
<WeatherEntityStateAttribute.HUMIDITY: 'humidity'>: 99,
|
||||
<WeatherEntityStateAttribute.PRECIPITATION_UNIT: 'precipitation_unit'>: <UnitOfPrecipitationDepth.MILLIMETERS: 'mm'>,
|
||||
<WeatherEntityStateAttribute.PRESSURE: 'pressure'>: 1004.4,
|
||||
<WeatherEntityStateAttribute.PRESSURE_UNIT: 'pressure_unit'>: <UnitOfPressure.HPA: 'hPa'>,
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <WeatherEntityFeature: 3>,
|
||||
<WeatherEntityStateAttribute.TEMPERATURE: 'temperature'>: -0.7,
|
||||
<WeatherEntityStateAttribute.TEMPERATURE_UNIT: 'temperature_unit'>: <UnitOfTemperature.CELSIUS: '°C'>,
|
||||
<WeatherEntityStateAttribute.VISIBILITY_UNIT: 'visibility_unit'>: <UnitOfLength.KILOMETERS: 'km'>,
|
||||
<WeatherEntityStateAttribute.WIND_BEARING: 'wind_bearing'>: 122.0,
|
||||
<WeatherEntityStateAttribute.WIND_GUST_SPEED: 'wind_gust_speed'>: 12.2,
|
||||
<WeatherEntityStateAttribute.WIND_SPEED: 'wind_speed'>: 3.2,
|
||||
<WeatherEntityStateAttribute.WIND_SPEED_UNIT: 'wind_speed_unit'>: <UnitOfSpeed.KILOMETERS_PER_HOUR: 'km/h'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'weather.aemet',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'snowy',
|
||||
})
|
||||
# ---
|
||||
# name: test_forecast_service[get_forecasts]
|
||||
dict({
|
||||
'weather.aemet': dict({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""The sensor tests for the AEMET OpenData platform."""
|
||||
"""The weather tests for the AEMET OpenData platform."""
|
||||
|
||||
from collections.abc import Generator
|
||||
import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -7,50 +8,44 @@ from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.aemet.const import ATTRIBUTION
|
||||
from homeassistant.components.aemet.coordinator import WEATHER_UPDATE_INTERVAL
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_CONDITION_SNOWY,
|
||||
ATTR_WEATHER_HUMIDITY,
|
||||
ATTR_WEATHER_PRESSURE,
|
||||
ATTR_WEATHER_TEMPERATURE,
|
||||
ATTR_WEATHER_WIND_BEARING,
|
||||
ATTR_WEATHER_WIND_GUST_SPEED,
|
||||
ATTR_WEATHER_WIND_SPEED,
|
||||
DOMAIN as WEATHER_DOMAIN,
|
||||
SERVICE_GET_FORECASTS,
|
||||
)
|
||||
from homeassistant.const import ATTR_ATTRIBUTION
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .util import async_init_integration, mock_api_call
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
async def test_aemet_weather(
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_platforms() -> Generator[None]:
|
||||
"""Override PLATFORMS."""
|
||||
with patch("homeassistant.components.aemet.PLATFORMS", [Platform.WEATHER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_all_entities(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test states of the weather."""
|
||||
"""Test all entities."""
|
||||
|
||||
await hass.config.async_set_time_zone("UTC")
|
||||
freezer.move_to("2021-01-09 12:00:00+00:00")
|
||||
await async_init_integration(hass)
|
||||
config_entry = await async_init_integration(hass)
|
||||
|
||||
state = hass.states.get("weather.aemet")
|
||||
assert state
|
||||
assert state.state == ATTR_CONDITION_SNOWY
|
||||
assert state.attributes[ATTR_ATTRIBUTION] == ATTRIBUTION
|
||||
assert state.attributes[ATTR_WEATHER_HUMIDITY] == 99.0
|
||||
assert state.attributes[ATTR_WEATHER_PRESSURE] == 1004.4 # 100440.0 Pa -> hPa
|
||||
assert state.attributes[ATTR_WEATHER_TEMPERATURE] == -0.7
|
||||
assert state.attributes[ATTR_WEATHER_WIND_BEARING] == 122.0
|
||||
assert state.attributes[ATTR_WEATHER_WIND_GUST_SPEED] == 12.2
|
||||
assert state.attributes[ATTR_WEATHER_WIND_SPEED] == 3.2
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
state = hass.states.get("weather.aemet_hourly")
|
||||
assert state is None
|
||||
# The hourly forecast is served by the single weather entity, not a separate one
|
||||
assert hass.states.get("weather.aemet_hourly") is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -67,7 +67,7 @@ def mock_api_call(cmd: str, fetch_data: bool = False) -> dict[str, Any]:
|
||||
return {}
|
||||
|
||||
|
||||
async def async_init_integration(hass: HomeAssistant):
|
||||
async def async_init_integration(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Set up the AEMET OpenData integration in Home Assistant."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
@@ -92,3 +92,5 @@ async def async_init_integration(hass: HomeAssistant):
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return config_entry
|
||||
|
||||
Reference in New Issue
Block a user