diff --git a/tests/components/template/snapshots/test_weather.ambr b/tests/components/template/snapshots/test_weather.ambr new file mode 100644 index 00000000000..72af2ab1637 --- /dev/null +++ b/tests/components/template/snapshots/test_weather.ambr @@ -0,0 +1,101 @@ +# serializer version: 1 +# name: test_forecasts[config0-1-weather] + dict({ + 'forecast': list([ + dict({ + 'condition': 'cloudy', + 'datetime': '2023-02-17T14:00:00+00:00', + 'temperature': 14.2, + }), + ]), + }) +# --- +# name: test_forecasts[config0-1-weather].1 + dict({ + 'forecast': list([ + dict({ + 'condition': 'cloudy', + 'datetime': '2023-02-17T14:00:00+00:00', + 'temperature': 14.2, + }), + ]), + }) +# --- +# name: test_forecasts[config0-1-weather].2 + dict({ + 'forecast': list([ + dict({ + 'condition': 'fog', + 'datetime': '2023-02-17T14:00:00+00:00', + 'is_daytime': True, + 'temperature': 14.2, + }), + ]), + }) +# --- +# name: test_forecasts[config0-1-weather].3 + dict({ + 'forecast': list([ + dict({ + 'condition': 'cloudy', + 'datetime': '2023-02-17T14:00:00+00:00', + 'temperature': 16.9, + }), + ]), + }) +# --- +# name: test_restore_weather_save_state + dict({ + 'last_apparent_temperature': None, + 'last_cloud_coverage': None, + 'last_dew_point': None, + 'last_humidity': '25.0', + 'last_ozone': None, + 'last_pressure': None, + 'last_temperature': '15.0', + 'last_visibility': None, + 'last_wind_bearing': None, + 'last_wind_gust_speed': None, + 'last_wind_speed': None, + }) +# --- +# name: test_trigger_weather_services[config0-1-template] + dict({ + 'forecast': list([ + dict({ + 'condition': 'sunny', + 'datetime': '2023-10-19T06:50:05-07:00', + 'precipitation': 20.0, + 'temperature': 20.0, + 'templow': 15.0, + }), + ]), + }) +# --- +# name: test_trigger_weather_services[config0-1-template].1 + dict({ + 'forecast': list([ + dict({ + 'condition': 'sunny', + 'datetime': '2023-10-19T06:50:05-07:00', + 'precipitation': 20.0, + 'temperature': 20.0, + 'templow': 15.0, + }), + ]), + }) +# --- +# name: test_trigger_weather_services[config0-1-template].2 + dict({ + 'forecast': list([ + dict({ + 'condition': 'sunny', + 'datetime': '2023-10-19T06:50:05-07:00', + 'is_daytime': True, + 'precipitation': 20.0, + 'temperature': 20.0, + 'templow': 15.0, + }), + ]), + }) +# --- diff --git a/tests/components/template/test_weather.py b/tests/components/template/test_weather.py index 7ca3d11b099..524f9c41aeb 100644 --- a/tests/components/template/test_weather.py +++ b/tests/components/template/test_weather.py @@ -2,6 +2,7 @@ from typing import Any import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.weather import ( ATTR_FORECAST, @@ -112,7 +113,9 @@ async def test_template_state_text(hass: HomeAssistant, start_ha) -> None: }, ], ) -async def test_forecasts(hass: HomeAssistant, start_ha) -> None: +async def test_forecasts( + hass: HomeAssistant, start_ha, snapshot: SnapshotAssertion +) -> None: """Test forecast service.""" for attr, _v_attr, value in [ ("sensor.temperature", ATTR_WEATHER_TEMPERATURE, 22.3), @@ -163,15 +166,7 @@ async def test_forecasts(hass: HomeAssistant, start_ha) -> None: blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "condition": "cloudy", - "datetime": "2023-02-17T14:00:00+00:00", - "temperature": 14.2, - } - ] - } + assert response == snapshot response = await hass.services.async_call( WEATHER_DOMAIN, SERVICE_GET_FORECAST, @@ -179,15 +174,7 @@ async def test_forecasts(hass: HomeAssistant, start_ha) -> None: blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "condition": "cloudy", - "datetime": "2023-02-17T14:00:00+00:00", - "temperature": 14.2, - } - ] - } + assert response == snapshot response = await hass.services.async_call( WEATHER_DOMAIN, SERVICE_GET_FORECAST, @@ -195,16 +182,7 @@ async def test_forecasts(hass: HomeAssistant, start_ha) -> None: blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "condition": "fog", - "datetime": "2023-02-17T14:00:00+00:00", - "temperature": 14.2, - "is_daytime": True, - } - ] - } + assert response == snapshot hass.states.async_set( "weather.forecast", @@ -231,15 +209,7 @@ async def test_forecasts(hass: HomeAssistant, start_ha) -> None: blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "condition": "cloudy", - "datetime": "2023-02-17T14:00:00+00:00", - "temperature": 16.9, - } - ] - } + assert response == snapshot @pytest.mark.parametrize(("count", "domain"), [(1, WEATHER_DOMAIN)]) @@ -263,7 +233,9 @@ async def test_forecasts(hass: HomeAssistant, start_ha) -> None: ], ) async def test_forecast_invalid( - hass: HomeAssistant, start_ha, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + start_ha, + caplog: pytest.LogCaptureFixture, ) -> None: """Test invalid forecasts.""" for attr, _v_attr, value in [ @@ -336,7 +308,9 @@ async def test_forecast_invalid( ], ) async def test_forecast_invalid_is_daytime_missing_in_twice_daily( - hass: HomeAssistant, start_ha, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + start_ha, + caplog: pytest.LogCaptureFixture, ) -> None: """Test forecast service invalid when is_daytime missing in twice_daily forecast.""" for attr, _v_attr, value in [ @@ -395,7 +369,9 @@ async def test_forecast_invalid_is_daytime_missing_in_twice_daily( ], ) async def test_forecast_invalid_datetime_missing( - hass: HomeAssistant, start_ha, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + start_ha, + caplog: pytest.LogCaptureFixture, ) -> None: """Test forecast service invalid when datetime missing.""" for attr, _v_attr, value in [ @@ -712,8 +688,12 @@ async def test_trigger_action( }, ], ) +@pytest.mark.freeze_time("2023-10-19 13:50:05") async def test_trigger_weather_services( - hass: HomeAssistant, start_ha, entity_registry: er.EntityRegistry + hass: HomeAssistant, + start_ha, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, ) -> None: """Test trigger weather entity with services.""" state = hass.states.get("weather.test") @@ -784,17 +764,7 @@ async def test_trigger_weather_services( blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "datetime": now, - "condition": "sunny", - "precipitation": 20.0, - "temperature": 20.0, - "templow": 15.0, - } - ], - } + assert response == snapshot response = await hass.services.async_call( WEATHER_DOMAIN, @@ -806,17 +776,7 @@ async def test_trigger_weather_services( blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "datetime": now, - "condition": "sunny", - "precipitation": 20.0, - "temperature": 20.0, - "templow": 15.0, - } - ], - } + assert response == snapshot response = await hass.services.async_call( WEATHER_DOMAIN, @@ -828,23 +788,11 @@ async def test_trigger_weather_services( blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "datetime": now, - "condition": "sunny", - "precipitation": 20.0, - "temperature": 20.0, - "templow": 15.0, - "is_daytime": True, - } - ], - } + assert response == snapshot async def test_restore_weather_save_state( - hass: HomeAssistant, - hass_storage: dict[str, Any], + hass: HomeAssistant, hass_storage: dict[str, Any], snapshot: SnapshotAssertion ) -> None: """Test Restore saved state for Weather trigger template.""" assert await async_setup_component( @@ -881,19 +829,7 @@ async def test_restore_weather_save_state( state = hass_storage[RESTORE_STATE_KEY]["data"][0]["state"] assert state["entity_id"] == entity.entity_id extra_data = hass_storage[RESTORE_STATE_KEY]["data"][0]["extra_data"] - assert extra_data == { - "last_apparent_temperature": None, - "last_cloud_coverage": None, - "last_dew_point": None, - "last_humidity": "25.0", - "last_ozone": None, - "last_pressure": None, - "last_temperature": "15.0", - "last_visibility": None, - "last_wind_bearing": None, - "last_wind_gust_speed": None, - "last_wind_speed": None, - } + assert extra_data == snapshot SAVED_ATTRIBUTES_1 = { diff --git a/tests/components/weather/snapshots/test_init.ambr b/tests/components/weather/snapshots/test_init.ambr new file mode 100644 index 00000000000..03a2d46c80f --- /dev/null +++ b/tests/components/weather/snapshots/test_init.ambr @@ -0,0 +1,41 @@ +# serializer version: 1 +# name: test_get_forecast[daily-1] + dict({ + 'forecast': list([ + dict({ + 'cloud_coverage': None, + 'temperature': 38.0, + 'templow': 38.0, + 'uv_index': None, + 'wind_bearing': None, + }), + ]), + }) +# --- +# name: test_get_forecast[hourly-2] + dict({ + 'forecast': list([ + dict({ + 'cloud_coverage': None, + 'temperature': 38.0, + 'templow': 38.0, + 'uv_index': None, + 'wind_bearing': None, + }), + ]), + }) +# --- +# name: test_get_forecast[twice_daily-4] + dict({ + 'forecast': list([ + dict({ + 'cloud_coverage': None, + 'is_daytime': True, + 'temperature': 38.0, + 'templow': 38.0, + 'uv_index': None, + 'wind_bearing': None, + }), + ]), + }) +# --- diff --git a/tests/components/weather/test_init.py b/tests/components/weather/test_init.py index 231f08c7cc1..f17edb16f07 100644 --- a/tests/components/weather/test_init.py +++ b/tests/components/weather/test_init.py @@ -4,6 +4,7 @@ from datetime import datetime from typing import Any import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.weather import ( ATTR_CONDITION_SUNNY, @@ -854,14 +855,13 @@ async def test_forecast_twice_daily_missing_is_daytime( @pytest.mark.parametrize( - ("forecast_type", "supported_features", "extra"), + ("forecast_type", "supported_features"), [ - ("daily", WeatherEntityFeature.FORECAST_DAILY, {}), - ("hourly", WeatherEntityFeature.FORECAST_HOURLY, {}), + ("daily", WeatherEntityFeature.FORECAST_DAILY), + ("hourly", WeatherEntityFeature.FORECAST_HOURLY), ( "twice_daily", WeatherEntityFeature.FORECAST_TWICE_DAILY, - {"is_daytime": True}, ), ], ) @@ -870,7 +870,7 @@ async def test_get_forecast( enable_custom_integrations: None, forecast_type: str, supported_features: int, - extra: dict[str, Any], + snapshot: SnapshotAssertion, ) -> None: """Test get forecast service.""" @@ -891,18 +891,7 @@ async def test_get_forecast( blocking=True, return_response=True, ) - assert response == { - "forecast": [ - { - "cloud_coverage": None, - "temperature": 38.0, - "templow": 38.0, - "uv_index": None, - "wind_bearing": None, - } - | extra - ], - } + assert response == snapshot async def test_get_forecast_no_forecast(