mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add diagnostics to Trafikverket Weatherstation (#134314)
This commit is contained in:
parent
5cff79ce50
commit
2be578a33f
@ -0,0 +1,17 @@
|
||||
"""Diagnostics support for Trafikverket Weatherstation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import TVWeatherConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: TVWeatherConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for Trafikverket Weatherstation config entry."""
|
||||
return asdict(entry.runtime_data.data)
|
@ -1 +1,9 @@
|
||||
"""Tests for the Trafikverket weatherstation integration."""
|
||||
|
||||
from homeassistant.components.trafikverket_weatherstation.const import CONF_STATION
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
|
||||
ENTRY_CONFIG = {
|
||||
CONF_API_KEY: "1234567890",
|
||||
CONF_STATION: "Arlanda",
|
||||
}
|
||||
|
80
tests/components/trafikverket_weatherstation/conftest.py
Normal file
80
tests/components/trafikverket_weatherstation/conftest.py
Normal file
@ -0,0 +1,80 @@
|
||||
"""Fixtures for the Trafikverket Weatherstation integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from pytrafikverket import WeatherStationInfoModel
|
||||
|
||||
from homeassistant.components.trafikverket_weatherstation.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import ENTRY_CONFIG
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def load_int(
|
||||
hass: HomeAssistant, mock_response: WeatherStationInfoModel
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Trafikverket Weatherstation integration in Home Assistant."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
source=SOURCE_USER,
|
||||
data=ENTRY_CONFIG,
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return config_entry
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_response")
|
||||
async def mock_weather_response(
|
||||
get_data: WeatherStationInfoModel,
|
||||
) -> AsyncGenerator[None]:
|
||||
"""Mock a successful response."""
|
||||
with patch(
|
||||
"homeassistant.components.trafikverket_weatherstation.coordinator.TrafikverketWeather.async_get_weather",
|
||||
return_value=get_data,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="get_data")
|
||||
async def get_data_from_library(hass: HomeAssistant) -> WeatherStationInfoModel:
|
||||
"""Retrieve data from Trafikverket Weatherstation library."""
|
||||
return WeatherStationInfoModel(
|
||||
station_name="Arlanda",
|
||||
station_id="227",
|
||||
road_temp=-3.4,
|
||||
air_temp=-3.0,
|
||||
dew_point=-5.0,
|
||||
humidity=84.1,
|
||||
visible_distance=20000.0,
|
||||
precipitationtype="no",
|
||||
raining=False,
|
||||
snowing=False,
|
||||
road_ice=None,
|
||||
road_ice_depth=None,
|
||||
road_snow=None,
|
||||
road_snow_depth=None,
|
||||
road_water=None,
|
||||
road_water_depth=None,
|
||||
road_water_equivalent_depth=None,
|
||||
winddirection="202",
|
||||
wind_height=6.0,
|
||||
windforce=1.2,
|
||||
windforcemax=2.3,
|
||||
measure_time=datetime.fromisoformat("2024-12-30T23:00:03+01:00"),
|
||||
precipitation_amount=0.0,
|
||||
modified_time=datetime.fromisoformat("2024-12-30T22:03:45.143000+00:00"),
|
||||
)
|
@ -0,0 +1,29 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'air_temp': -3.0,
|
||||
'dew_point': -5.0,
|
||||
'humidity': 84.1,
|
||||
'measure_time': '2024-12-30T23:00:03+01:00',
|
||||
'modified_time': '2024-12-30T22:03:45.143000+00:00',
|
||||
'precipitation_amount': 0.0,
|
||||
'precipitationtype': 'no',
|
||||
'raining': False,
|
||||
'road_ice': None,
|
||||
'road_ice_depth': None,
|
||||
'road_snow': None,
|
||||
'road_snow_depth': None,
|
||||
'road_temp': -3.4,
|
||||
'road_water': None,
|
||||
'road_water_depth': None,
|
||||
'road_water_equivalent_depth': None,
|
||||
'snowing': False,
|
||||
'station_id': '227',
|
||||
'station_name': 'Arlanda',
|
||||
'visible_distance': 20000.0,
|
||||
'wind_height': 6.0,
|
||||
'winddirection': '202',
|
||||
'windforce': 1.2,
|
||||
'windforcemax': 2.3,
|
||||
})
|
||||
# ---
|
@ -0,0 +1,23 @@
|
||||
"""Test Trafikverket Weatherstation diagnostics."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
load_int: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test generating diagnostics for a config entry."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, load_int) == snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user