diff --git a/homeassistant/components/gios/diagnostics.py b/homeassistant/components/gios/diagnostics.py new file mode 100644 index 00000000000..b056473fbec --- /dev/null +++ b/homeassistant/components/gios/diagnostics.py @@ -0,0 +1,24 @@ +"""Diagnostics support for GIOS.""" +from __future__ import annotations + +from dataclasses import asdict + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import GiosDataUpdateCoordinator +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, config_entry: ConfigEntry +) -> dict: + """Return diagnostics for a config entry.""" + coordinator: GiosDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id] + + diagnostics_data = { + "config_entry": config_entry.as_dict(), + "coordinator_data": asdict(coordinator.data), + } + + return diagnostics_data diff --git a/tests/components/gios/fixtures/diagnostics_data.json b/tests/components/gios/fixtures/diagnostics_data.json new file mode 100644 index 00000000000..1044c9887bb --- /dev/null +++ b/tests/components/gios/fixtures/diagnostics_data.json @@ -0,0 +1,50 @@ +{ + "aqi": { + "name": "AQI", + "id": null, + "index": null, + "value": "dobry" + }, + "c6h6": { + "name": "benzen", + "id": 658, + "index": "bardzo dobry", + "value": 0.23789 + }, + "co": { + "name": "tlenek węgla", + "id": 660, + "index": "dobry", + "value": 251.874 + }, + "no2": { + "name": "dwutlenek azotu", + "id": 665, + "index": "dobry", + "value": 7.13411 + }, + "o3": { + "name": "ozon", + "id": 667, + "index": "dobry", + "value": 95.7768 + }, + "pm10": { + "name": "py\u0142 zawieszony PM10", + "id": 14395, + "index": "dobry", + "value": 16.8344 + }, + "pm25": { + "name": "py\u0142 zawieszony PM2.5", + "id": 670, + "index": "dobry", + "value": 4 + }, + "so2": { + "name": "dwutlenek siarki", + "id": 672, + "index": "bardzo dobry", + "value": 4.35478 + } +} diff --git a/tests/components/gios/test_diagnostics.py b/tests/components/gios/test_diagnostics.py new file mode 100644 index 00000000000..e72880feed7 --- /dev/null +++ b/tests/components/gios/test_diagnostics.py @@ -0,0 +1,33 @@ +"""Test GIOS diagnostics.""" +import json + +from tests.common import load_fixture +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.components.gios import init_integration + + +async def test_entry_diagnostics(hass, hass_client): + """Test config entry diagnostics.""" + entry = await init_integration(hass) + + coordinator_data = json.loads(load_fixture("diagnostics_data.json", "gios")) + + result = await get_diagnostics_for_config_entry(hass, hass_client, entry) + + assert result["config_entry"] == { + "entry_id": entry.entry_id, + "version": 1, + "domain": "gios", + "title": "Home", + "data": { + "station_id": 123, + "name": "Home", + }, + "options": {}, + "pref_disable_new_entities": False, + "pref_disable_polling": False, + "source": "user", + "unique_id": "123", + "disabled_by": None, + } + assert result["coordinator_data"] == coordinator_data