diff --git a/tests/components/aemet/snapshots/test_weather.ambr b/tests/components/aemet/snapshots/test_weather.ambr index 58c854dcda93..bd378c1d13b9 100644 --- a/tests/components/aemet/snapshots/test_weather.ambr +++ b/tests/components/aemet/snapshots/test_weather.ambr @@ -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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'weather', + 'entity_category': None, + 'entity_id': 'weather.aemet', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'translation_key': None, + 'unique_id': '40.30403754--3.72935236', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[weather.aemet-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Powered by AEMET OpenData', + : 'AEMET', + : 99, + : , + : 1004.4, + : , + : , + : -0.7, + : , + : , + : 122.0, + : 12.2, + : 3.2, + : , + }), + 'context': , + 'entity_id': 'weather.aemet', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'snowy', + }) +# --- # name: test_forecast_service[get_forecasts] dict({ 'weather.aemet': dict({ diff --git a/tests/components/aemet/test_weather.py b/tests/components/aemet/test_weather.py index 049fd6d18c7a..ce08b464f739 100644 --- a/tests/components/aemet/test_weather.py +++ b/tests/components/aemet/test_weather.py @@ -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( diff --git a/tests/components/aemet/util.py b/tests/components/aemet/util.py index 0361ca9e6d8a..30fcd741c2b0 100644 --- a/tests/components/aemet/util.py +++ b/tests/components/aemet/util.py @@ -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