mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Add diagnostic support to WAQI (#156811)
This commit is contained in:
committed by
GitHub
parent
d01843e1ab
commit
babe19767d
20
homeassistant/components/waqi/diagnostics.py
Normal file
20
homeassistant/components/waqi/diagnostics.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Diagnostics support for WAQI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import WAQIConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: WAQIConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
return {
|
||||
subentry_id: asdict(coordinator.data)
|
||||
for subentry_id, coordinator in entry.runtime_data.items()
|
||||
}
|
||||
44
tests/components/waqi/snapshots/test_diagnostics.ambr
Normal file
44
tests/components/waqi/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,44 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'ABCDEF': dict({
|
||||
'air_quality_index': 29,
|
||||
'attributions': list([
|
||||
dict({
|
||||
'logo': 'Netherland-RIVM.png',
|
||||
'name': 'RIVM - Rijksinstituut voor Volksgezondheid en Milieum, Landelijk Meetnet Luchtkwaliteit',
|
||||
'url': 'http://www.luchtmeetnet.nl/',
|
||||
}),
|
||||
dict({
|
||||
'logo': None,
|
||||
'name': 'World Air Quality Index Project',
|
||||
'url': 'https://waqi.info/',
|
||||
}),
|
||||
]),
|
||||
'city': dict({
|
||||
'coordinates': dict({
|
||||
'latitude': 52.105031,
|
||||
'longitude': 5.124464,
|
||||
}),
|
||||
'external_url': 'https://aqicn.org/city/netherland/utrecht/de-jongweg',
|
||||
'location': None,
|
||||
'name': 'de Jongweg, Utrecht',
|
||||
}),
|
||||
'dominant_pollutant': 'o3',
|
||||
'extended_air_quality': dict({
|
||||
'carbon_monoxide': 2.3,
|
||||
'humidity': 80,
|
||||
'nephelometry': 80,
|
||||
'nitrogen_dioxide': 2.3,
|
||||
'ozone': 29.4,
|
||||
'pm10': 12,
|
||||
'pm25': 17,
|
||||
'pressure': 1008.8,
|
||||
'sulfur_dioxide': 2.3,
|
||||
'temperature': 16,
|
||||
}),
|
||||
'measured_at': '2023-08-07T17:00:00+02:00',
|
||||
'station_id': 4584,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
28
tests/components/waqi/test_diagnostics.py
Normal file
28
tests/components/waqi/test_diagnostics.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Tests for the diagnostics data provided by the WAQI integration."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
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,
|
||||
mock_waqi: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user