Skip to content
Snippets Groups Projects
Unverified Commit d2b9a3b1 authored by epenet's avatar epenet Committed by GitHub
Browse files

Add sensor and weather tests to meteo_france (#137318)

parent 4ceced64
No related branches found
No related tags found
No related merge requests found
......@@ -2,13 +2,48 @@
from unittest.mock import patch
from meteofrance_api.model import CurrentPhenomenons, Forecast, Rain
import pytest
from homeassistant.components.meteo_france.const import CONF_CITY, DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_json_object_fixture
@pytest.fixture(autouse=True)
def patch_requests():
"""Stub out services that makes requests."""
patch_client = patch("homeassistant.components.meteo_france.MeteoFranceClient")
with patch("homeassistant.components.meteo_france.MeteoFranceClient") as mock_data:
mock_data = mock_data.return_value
mock_data.get_forecast.return_value = Forecast(
load_json_object_fixture("raw_forecast.json", DOMAIN)
)
mock_data.get_rain.return_value = Rain(
load_json_object_fixture("raw_rain.json", DOMAIN)
)
mock_data.get_warning_current_phenomenoms.return_value = CurrentPhenomenons(
load_json_object_fixture("raw_warning_current_phenomenoms.json", DOMAIN)
)
yield mock_data
with patch_client:
yield
@pytest.fixture(name="config_entry")
def get_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Create and register mock config entry."""
entry_data = {
CONF_CITY: "La Clusaz",
CONF_LATITUDE: 45.90417,
CONF_LONGITUDE: 6.42306,
}
config_entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_USER,
unique_id=f"{entry_data[CONF_LATITUDE], entry_data[CONF_LONGITUDE]}",
title=entry_data[CONF_CITY],
data=entry_data,
)
config_entry.add_to_hass(hass)
return config_entry
{
"updated_on": 1737995400,
"position": {
"country": "FR - France",
"dept": "74",
"insee": "74080",
"lat": 45.90417,
"lon": 6.42306,
"name": "La Clusaz",
"rain_product_available": 1,
"timezone": "Europe/Paris"
},
"daily_forecast": [
{
"T": { "max": 10.4, "min": 6.9, "sea": null },
"dt": 1737936000,
"humidity": { "max": 90, "min": 65 },
"precipitation": { "24h": 1.3 },
"sun": { "rise": 1737963392, "set": 1737996163 },
"uv": 1,
"weather12H": { "desc": "Eclaircies", "icon": "p2j" }
}
],
"forecast": [
{
"T": { "value": 9.1, "windchill": 5.4 },
"clouds": 70,
"dt": 1737990000,
"humidity": 75,
"iso0": 1250,
"rain": { "1h": 0 },
"rain snow limit": "Non pertinent",
"sea_level": 988.7,
"snow": { "1h": 0 },
"uv": 1,
"weather": { "desc": "Eclaircies", "icon": "p2j" },
"wind": {
"direction": 200,
"gust": 18,
"icon": "SSO",
"speed": 8
}
}
],
"probability_forecast": [
{
"dt": 1737990000,
"freezing": 0,
"rain": { "3h": null, "6h": null },
"snow": { "3h": null, "6h": null }
}
]
}
{
"position": {
"lat": 48.807166,
"lon": 2.239895,
"alti": 76,
"name": "Meudon",
"country": "FR - France",
"dept": "92",
"timezone": "Europe/Paris"
},
"updated_on": 1589995200,
"quality": 0,
"forecast": [
{ "dt": 1589996100, "rain": 1, "desc": "Temps sec" },
{ "dt": 1589996400, "rain": 1, "desc": "Temps sec" },
{ "dt": 1589996700, "rain": 1, "desc": "Temps sec" },
{ "dt": 1589997000, "rain": 2, "desc": "Pluie faible" },
{ "dt": 1589997300, "rain": 3, "desc": "Pluie modérée" },
{ "dt": 1589997600, "rain": 2, "desc": "Pluie faible" },
{ "dt": 1589998200, "rain": 1, "desc": "Temps sec" },
{ "dt": 1589998800, "rain": 1, "desc": "Temps sec" },
{ "dt": 1589999400, "rain": 1, "desc": "Temps sec" }
]
}
{
"update_time": 1591279200,
"end_validity_time": 1591365600,
"domain_id": "32",
"phenomenons_max_colors": [
{ "phenomenon_id": "6", "phenomenon_max_color_id": 1 },
{ "phenomenon_id": "4", "phenomenon_max_color_id": 1 },
{ "phenomenon_id": "5", "phenomenon_max_color_id": 3 },
{ "phenomenon_id": "2", "phenomenon_max_color_id": 1 },
{ "phenomenon_id": "1", "phenomenon_max_color_id": 1 },
{ "phenomenon_id": "3", "phenomenon_max_color_id": 2 }
]
}
This diff is collapsed.
# serializer version: 1
# name: test_weather[weather.la_clusaz-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.la_clusaz',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'La Clusaz',
'platform': 'meteo_france',
'previous_unique_id': None,
'supported_features': <WeatherEntityFeature: 3>,
'translation_key': None,
'unique_id': '45.90417,6.42306',
'unit_of_measurement': None,
})
# ---
# name: test_weather[weather.la_clusaz-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by Météo-France',
'friendly_name': 'La Clusaz',
'humidity': 75,
'precipitation_unit': <UnitOfPrecipitationDepth.MILLIMETERS: 'mm'>,
'pressure': 988.7,
'pressure_unit': <UnitOfPressure.HPA: 'hPa'>,
'supported_features': <WeatherEntityFeature: 3>,
'temperature': 9.1,
'temperature_unit': <UnitOfTemperature.CELSIUS: '°C'>,
'visibility_unit': <UnitOfLength.KILOMETERS: 'km'>,
'wind_bearing': 200,
'wind_speed': 28.8,
'wind_speed_unit': <UnitOfSpeed.KILOMETERS_PER_HOUR: 'km/h'>,
}),
'context': <ANY>,
'entity_id': 'weather.la_clusaz',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'partlycloudy',
})
# ---
"""Test Météo France weather entity."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.fixture(autouse=True)
def override_platforms() -> Generator[None]:
"""Override PLATFORMS."""
with patch("homeassistant.components.meteo_france.PLATFORMS", [Platform.SENSOR]):
yield
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensor(
hass: HomeAssistant,
config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the sensor entity."""
await hass.config_entries.async_setup(config_entry.entry_id)
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
"""Test Météo France weather entity."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.fixture(autouse=True)
def override_platforms() -> Generator[None]:
"""Override PLATFORMS."""
with patch("homeassistant.components.meteo_france.PLATFORMS", [Platform.WEATHER]):
yield
async def test_weather(
hass: HomeAssistant,
config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the weather entity."""
await hass.config_entries.async_setup(config_entry.entry_id)
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment