mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Use snapshot test helper in Accuweather (#115884)
This commit is contained in:
parent
5796b651af
commit
b328981868
@ -1,158 +1,4 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_forecast_service
|
|
||||||
dict({
|
|
||||||
'forecast': list([
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 29.8,
|
|
||||||
'cloud_coverage': 58,
|
|
||||||
'condition': 'lightning-rainy',
|
|
||||||
'datetime': '2020-07-26T05:00:00+00:00',
|
|
||||||
'precipitation': 2.5,
|
|
||||||
'precipitation_probability': 60,
|
|
||||||
'temperature': 29.5,
|
|
||||||
'templow': 15.4,
|
|
||||||
'uv_index': 5,
|
|
||||||
'wind_bearing': 166,
|
|
||||||
'wind_gust_speed': 29.6,
|
|
||||||
'wind_speed': 13.0,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 28.9,
|
|
||||||
'cloud_coverage': 52,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-27T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 25,
|
|
||||||
'temperature': 26.2,
|
|
||||||
'templow': 15.9,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 297,
|
|
||||||
'wind_gust_speed': 14.8,
|
|
||||||
'wind_speed': 9.3,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 31.6,
|
|
||||||
'cloud_coverage': 65,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-28T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 10,
|
|
||||||
'temperature': 31.7,
|
|
||||||
'templow': 16.8,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 198,
|
|
||||||
'wind_gust_speed': 24.1,
|
|
||||||
'wind_speed': 16.7,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 26.5,
|
|
||||||
'cloud_coverage': 45,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-29T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 9,
|
|
||||||
'temperature': 24.0,
|
|
||||||
'templow': 11.7,
|
|
||||||
'uv_index': 6,
|
|
||||||
'wind_bearing': 293,
|
|
||||||
'wind_gust_speed': 24.1,
|
|
||||||
'wind_speed': 13.0,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 22.2,
|
|
||||||
'cloud_coverage': 50,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-30T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 1,
|
|
||||||
'temperature': 21.4,
|
|
||||||
'templow': 12.2,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 280,
|
|
||||||
'wind_gust_speed': 27.8,
|
|
||||||
'wind_speed': 18.5,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_forecast_service[forecast]
|
|
||||||
dict({
|
|
||||||
'weather.home': dict({
|
|
||||||
'forecast': list([
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 29.8,
|
|
||||||
'cloud_coverage': 58,
|
|
||||||
'condition': 'lightning-rainy',
|
|
||||||
'datetime': '2020-07-26T05:00:00+00:00',
|
|
||||||
'precipitation': 2.5,
|
|
||||||
'precipitation_probability': 60,
|
|
||||||
'temperature': 29.5,
|
|
||||||
'templow': 15.4,
|
|
||||||
'uv_index': 5,
|
|
||||||
'wind_bearing': 166,
|
|
||||||
'wind_gust_speed': 29.6,
|
|
||||||
'wind_speed': 13.0,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 28.9,
|
|
||||||
'cloud_coverage': 52,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-27T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 25,
|
|
||||||
'temperature': 26.2,
|
|
||||||
'templow': 15.9,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 297,
|
|
||||||
'wind_gust_speed': 14.8,
|
|
||||||
'wind_speed': 9.3,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 31.6,
|
|
||||||
'cloud_coverage': 65,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-28T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 10,
|
|
||||||
'temperature': 31.7,
|
|
||||||
'templow': 16.8,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 198,
|
|
||||||
'wind_gust_speed': 24.1,
|
|
||||||
'wind_speed': 16.7,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 26.5,
|
|
||||||
'cloud_coverage': 45,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-29T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 9,
|
|
||||||
'temperature': 24.0,
|
|
||||||
'templow': 11.7,
|
|
||||||
'uv_index': 6,
|
|
||||||
'wind_bearing': 293,
|
|
||||||
'wind_gust_speed': 24.1,
|
|
||||||
'wind_speed': 13.0,
|
|
||||||
}),
|
|
||||||
dict({
|
|
||||||
'apparent_temperature': 22.2,
|
|
||||||
'cloud_coverage': 50,
|
|
||||||
'condition': 'partlycloudy',
|
|
||||||
'datetime': '2020-07-30T05:00:00+00:00',
|
|
||||||
'precipitation': 0.0,
|
|
||||||
'precipitation_probability': 1,
|
|
||||||
'temperature': 21.4,
|
|
||||||
'templow': 12.2,
|
|
||||||
'uv_index': 7,
|
|
||||||
'wind_bearing': 280,
|
|
||||||
'wind_gust_speed': 27.8,
|
|
||||||
'wind_speed': 18.5,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
# ---
|
|
||||||
# name: test_forecast_service[get_forecast]
|
# name: test_forecast_service[get_forecast]
|
||||||
dict({
|
dict({
|
||||||
'forecast': list([
|
'forecast': list([
|
||||||
@ -455,3 +301,67 @@
|
|||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_weather[weather.home-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'weather',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'weather.home',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'accuweather',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <WeatherEntityFeature: 1>,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '0123456',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_weather[weather.home-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'apparent_temperature': 22.8,
|
||||||
|
'attribution': 'Data provided by AccuWeather',
|
||||||
|
'cloud_coverage': 10,
|
||||||
|
'dew_point': 16.2,
|
||||||
|
'friendly_name': 'Home',
|
||||||
|
'humidity': 67,
|
||||||
|
'precipitation_unit': <UnitOfPrecipitationDepth.MILLIMETERS: 'mm'>,
|
||||||
|
'pressure': 1012.0,
|
||||||
|
'pressure_unit': <UnitOfPressure.HPA: 'hPa'>,
|
||||||
|
'supported_features': <WeatherEntityFeature: 1>,
|
||||||
|
'temperature': 22.6,
|
||||||
|
'temperature_unit': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||||
|
'uv_index': 6,
|
||||||
|
'visibility': 16.1,
|
||||||
|
'visibility_unit': <UnitOfLength.KILOMETERS: 'km'>,
|
||||||
|
'wind_bearing': 180,
|
||||||
|
'wind_gust_speed': 20.3,
|
||||||
|
'wind_speed': 14.5,
|
||||||
|
'wind_speed_unit': <UnitOfSpeed.KILOMETERS_PER_HOUR: 'km/h'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'weather.home',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'sunny',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
@ -30,6 +30,7 @@ from tests.common import (
|
|||||||
async_fire_time_changed,
|
async_fire_time_changed,
|
||||||
load_json_array_fixture,
|
load_json_array_fixture,
|
||||||
load_json_object_fixture,
|
load_json_object_fixture,
|
||||||
|
snapshot_platform,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -42,14 +43,7 @@ async def test_sensor(
|
|||||||
"""Test states of the sensor."""
|
"""Test states of the sensor."""
|
||||||
with patch("homeassistant.components.accuweather.PLATFORMS", [Platform.SENSOR]):
|
with patch("homeassistant.components.accuweather.PLATFORMS", [Platform.SENSOR]):
|
||||||
entry = await init_integration(hass)
|
entry = await init_integration(hass)
|
||||||
|
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||||
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
|
||||||
|
|
||||||
assert entity_entries
|
|
||||||
for entity_entry in entity_entries:
|
|
||||||
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
|
|
||||||
assert (state := hass.states.get(entity_entry.entity_id))
|
|
||||||
assert state == snapshot(name=f"{entity_entry.entity_id}-state")
|
|
||||||
|
|
||||||
|
|
||||||
async def test_availability(hass: HomeAssistant) -> None:
|
async def test_availability(hass: HomeAssistant) -> None:
|
||||||
|
@ -7,34 +7,14 @@ from freezegun.api import FrozenDateTimeFactory
|
|||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.accuweather.const import (
|
from homeassistant.components.accuweather.const import UPDATE_INTERVAL_DAILY_FORECAST
|
||||||
ATTRIBUTION,
|
|
||||||
UPDATE_INTERVAL_DAILY_FORECAST,
|
|
||||||
)
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_FORECAST_CONDITION,
|
ATTR_FORECAST_CONDITION,
|
||||||
ATTR_WEATHER_APPARENT_TEMPERATURE,
|
|
||||||
ATTR_WEATHER_CLOUD_COVERAGE,
|
|
||||||
ATTR_WEATHER_DEW_POINT,
|
|
||||||
ATTR_WEATHER_HUMIDITY,
|
|
||||||
ATTR_WEATHER_PRESSURE,
|
|
||||||
ATTR_WEATHER_TEMPERATURE,
|
|
||||||
ATTR_WEATHER_UV_INDEX,
|
|
||||||
ATTR_WEATHER_VISIBILITY,
|
|
||||||
ATTR_WEATHER_WIND_BEARING,
|
|
||||||
ATTR_WEATHER_WIND_GUST_SPEED,
|
|
||||||
ATTR_WEATHER_WIND_SPEED,
|
|
||||||
DOMAIN as WEATHER_DOMAIN,
|
DOMAIN as WEATHER_DOMAIN,
|
||||||
LEGACY_SERVICE_GET_FORECAST,
|
LEGACY_SERVICE_GET_FORECAST,
|
||||||
SERVICE_GET_FORECASTS,
|
SERVICE_GET_FORECASTS,
|
||||||
WeatherEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
ATTR_ENTITY_ID,
|
|
||||||
ATTR_SUPPORTED_FEATURES,
|
|
||||||
STATE_UNAVAILABLE,
|
|
||||||
)
|
)
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -46,37 +26,18 @@ from tests.common import (
|
|||||||
async_fire_time_changed,
|
async_fire_time_changed,
|
||||||
load_json_array_fixture,
|
load_json_array_fixture,
|
||||||
load_json_object_fixture,
|
load_json_object_fixture,
|
||||||
|
snapshot_platform,
|
||||||
)
|
)
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_weather(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
|
async def test_weather(
|
||||||
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion
|
||||||
|
) -> None:
|
||||||
"""Test states of the weather without forecast."""
|
"""Test states of the weather without forecast."""
|
||||||
await init_integration(hass)
|
with patch("homeassistant.components.accuweather.PLATFORMS", [Platform.WEATHER]):
|
||||||
|
entry = await init_integration(hass)
|
||||||
state = hass.states.get("weather.home")
|
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||||
assert state
|
|
||||||
assert state.state == "sunny"
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_HUMIDITY) == 67
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_PRESSURE) == 1012.0
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_WIND_BEARING) == 180
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_WIND_SPEED) == 14.5 # 4.03 m/s -> km/h
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_APPARENT_TEMPERATURE) == 22.8
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_DEW_POINT) == 16.2
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_CLOUD_COVERAGE) == 10
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_WIND_GUST_SPEED) == 20.3
|
|
||||||
assert state.attributes.get(ATTR_WEATHER_UV_INDEX) == 6
|
|
||||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
|
||||||
assert (
|
|
||||||
state.attributes.get(ATTR_SUPPORTED_FEATURES)
|
|
||||||
is WeatherEntityFeature.FORECAST_DAILY
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get("weather.home")
|
|
||||||
assert entry
|
|
||||||
assert entry.unique_id == "0123456"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_availability(hass: HomeAssistant) -> None:
|
async def test_availability(hass: HomeAssistant) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user