Add diagnostics to Flu Near You (#64597)
parent
b54722952c
commit
224d0d80b2
|
@ -0,0 +1,36 @@
|
||||||
|
"""Diagnostics support for Flu Near You."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
from .const import CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT, DOMAIN
|
||||||
|
|
||||||
|
TO_REDACT = {
|
||||||
|
CONF_LATITUDE,
|
||||||
|
CONF_LONGITUDE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
coordinators: dict[str, DataUpdateCoordinator] = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"data": {
|
||||||
|
CATEGORY_CDC_REPORT: async_redact_data(
|
||||||
|
coordinators[CATEGORY_CDC_REPORT].data, TO_REDACT
|
||||||
|
),
|
||||||
|
CATEGORY_USER_REPORT: [
|
||||||
|
async_redact_data(report, TO_REDACT)
|
||||||
|
for report in coordinators[CATEGORY_USER_REPORT].data
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
|
@ -34,12 +34,20 @@ def data_cdc_fixture():
|
||||||
return json.loads(load_fixture("cdc_data.json", "flunearyou"))
|
return json.loads(load_fixture("cdc_data.json", "flunearyou"))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="data_user", scope="session")
|
||||||
|
def data_user_fixture():
|
||||||
|
"""Define user data."""
|
||||||
|
return json.loads(load_fixture("user_data.json", "flunearyou"))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_flunearyou")
|
@pytest.fixture(name="setup_flunearyou")
|
||||||
async def setup_flunearyou_fixture(hass, config, data_cdc):
|
async def setup_flunearyou_fixture(hass, data_cdc, data_user, config):
|
||||||
"""Define a fixture to set up Flu Near You."""
|
"""Define a fixture to set up Flu Near You."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyflunearyou.cdc.CdcReport.status_by_coordinates", return_value=data_cdc
|
"pyflunearyou.cdc.CdcReport.status_by_coordinates", return_value=data_cdc
|
||||||
), patch("pyflunearyou.user.UserReport.status_by_coordinates"), patch(
|
), patch(
|
||||||
|
"pyflunearyou.user.UserReport.status_by_coordinates", return_value=data_user
|
||||||
|
), patch(
|
||||||
"homeassistant.components.flunearyou.PLATFORMS", []
|
"homeassistant.components.flunearyou.PLATFORMS", []
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
assert await async_setup_component(hass, DOMAIN, config)
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"city": "Chester(72934)",
|
||||||
|
"place_id": "49377",
|
||||||
|
"zip": "72934",
|
||||||
|
"contained_by": "610",
|
||||||
|
"latitude": "35.687603",
|
||||||
|
"longitude": "-94.253845",
|
||||||
|
"none": 1,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"city": "Los Angeles(90046)",
|
||||||
|
"place_id": "23818",
|
||||||
|
"zip": "90046",
|
||||||
|
"contained_by": "204",
|
||||||
|
"latitude": "34.114731",
|
||||||
|
"longitude": "-118.363724",
|
||||||
|
"none": 2,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"city": "Corvallis(97330)",
|
||||||
|
"place_id": "21462",
|
||||||
|
"zip": "97330",
|
||||||
|
"contained_by": "239",
|
||||||
|
"latitude": "44.638504",
|
||||||
|
"longitude": "-123.292938",
|
||||||
|
"none": 3,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
"""Test Flu Near You diagnostics."""
|
||||||
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_flunearyou):
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
|
"data": {
|
||||||
|
"cdc_report": {
|
||||||
|
"level": "Low",
|
||||||
|
"level2": "None",
|
||||||
|
"week_date": "2020-05-16",
|
||||||
|
"name": "Washington State",
|
||||||
|
"fill": {"color": "#00B7B6", "opacity": 0.7},
|
||||||
|
},
|
||||||
|
"user_report": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"city": "Chester(72934)",
|
||||||
|
"place_id": "49377",
|
||||||
|
"zip": "72934",
|
||||||
|
"contained_by": "610",
|
||||||
|
"latitude": REDACTED,
|
||||||
|
"longitude": REDACTED,
|
||||||
|
"none": 1,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"city": "Los Angeles(90046)",
|
||||||
|
"place_id": "23818",
|
||||||
|
"zip": "90046",
|
||||||
|
"contained_by": "204",
|
||||||
|
"latitude": REDACTED,
|
||||||
|
"longitude": REDACTED,
|
||||||
|
"none": 2,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"city": "Corvallis(97330)",
|
||||||
|
"place_id": "21462",
|
||||||
|
"zip": "97330",
|
||||||
|
"contained_by": "239",
|
||||||
|
"latitude": REDACTED,
|
||||||
|
"longitude": REDACTED,
|
||||||
|
"none": 3,
|
||||||
|
"symptoms": 0,
|
||||||
|
"flu": 0,
|
||||||
|
"lepto": 0,
|
||||||
|
"dengue": 0,
|
||||||
|
"chick": 0,
|
||||||
|
"icon": "1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue