Add diagnostics to IQVIA (#64602)

This commit is contained in:
Aaron Bach 2022-01-20 23:09:36 -07:00 committed by GitHub
parent 3dd7ec6856
commit d170faeffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 771 additions and 4 deletions

View file

@ -0,0 +1,28 @@
"""Diagnostics support for IQVIA."""
from __future__ import annotations
from typing import Any
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import DOMAIN
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 {
"entry": {
"title": entry.title,
"data": dict(entry.data),
},
"data": {
data_type: coordinator.data
for data_type, coordinator in coordinators.items()
},
}

View file

@ -1,4 +1,5 @@
"""Define test fixtures for IQVIA.""" """Define test fixtures for IQVIA."""
import json
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@ -6,13 +7,13 @@ import pytest
from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry, load_fixture
@pytest.fixture(name="config_entry") @pytest.fixture(name="config_entry")
def config_entry_fixture(hass, config, unique_id): def config_entry_fixture(hass, config, unique_id):
"""Define a config entry fixture.""" """Define a config entry fixture."""
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id) entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id, data=config)
entry.add_to_hass(hass) entry.add_to_hass(hass)
return entry return entry
@ -25,10 +26,78 @@ def config_fixture(hass):
} }
@pytest.fixture(name="data_allergy_forecast", scope="session")
def data_allergy_forecast_fixture():
"""Define allergy forecast data."""
return json.loads(load_fixture("allergy_forecast_data.json", "iqvia"))
@pytest.fixture(name="data_allergy_index", scope="session")
def data_allergy_index_fixture():
"""Define allergy index data."""
return json.loads(load_fixture("allergy_index_data.json", "iqvia"))
@pytest.fixture(name="data_allergy_outlook", scope="session")
def data_allergy_outlook_fixture():
"""Define allergy outlook data."""
return json.loads(load_fixture("allergy_outlook_data.json", "iqvia"))
@pytest.fixture(name="data_asthma_forecast", scope="session")
def data_asthma_forecast_fixture():
"""Define asthma forecast data."""
return json.loads(load_fixture("asthma_forecast_data.json", "iqvia"))
@pytest.fixture(name="data_asthma_index", scope="session")
def data_asthma_index_fixture():
"""Define asthma index data."""
return json.loads(load_fixture("asthma_index_data.json", "iqvia"))
@pytest.fixture(name="data_disease_forecast", scope="session")
def data_disease_forecast_fixture():
"""Define disease forecast data."""
return json.loads(load_fixture("disease_forecast_data.json", "iqvia"))
@pytest.fixture(name="data_disease_index", scope="session")
def data_disease_index_fixture():
"""Define disease index data."""
return json.loads(load_fixture("disease_index_data.json", "iqvia"))
@pytest.fixture(name="setup_iqvia") @pytest.fixture(name="setup_iqvia")
async def setup_iqvia_fixture(hass, config): async def setup_iqvia_fixture(
hass,
config,
data_allergy_forecast,
data_allergy_index,
data_allergy_outlook,
data_asthma_forecast,
data_asthma_index,
data_disease_forecast,
data_disease_index,
):
"""Define a fixture to set up IQVIA.""" """Define a fixture to set up IQVIA."""
with patch("homeassistant.components.iqvia.PLATFORMS", []): with patch(
"pyiqvia.allergens.Allergens.extended", return_value=data_allergy_forecast
), patch(
"pyiqvia.allergens.Allergens.current", return_value=data_allergy_index
), patch(
"pyiqvia.allergens.Allergens.outlook", return_value=data_allergy_outlook
), patch(
"pyiqvia.asthma.Asthma.extended", return_value=data_asthma_forecast
), patch(
"pyiqvia.asthma.Asthma.current", return_value=data_asthma_index
), patch(
"pyiqvia.disease.Disease.extended", return_value=data_disease_forecast
), patch(
"pyiqvia.disease.Disease.current", return_value=data_disease_index
), patch(
"homeassistant.components.iqvia.PLATFORMS", []
):
assert await async_setup_component(hass, DOMAIN, config) assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
yield yield

View file

@ -0,0 +1,33 @@
{
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Period": "2018-06-12T13:47:12.897",
"Index": 6.6
},
{
"Period": "2018-06-13T13:47:12.897",
"Index": 6.3
},
{
"Period": "2018-06-14T13:47:12.897",
"Index": 7.6
},
{
"Period": "2018-06-15T13:47:12.897",
"Index": 7.6
},
{
"Period": "2018-06-16T13:47:12.897",
"Index": 7.3
}
],
"DisplayLocation": "Schenectady, NY"
}
}

View file

@ -0,0 +1,88 @@
{
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree"
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass"
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed"
}
],
"Period": "0001-01-01T00:00:00",
"Type": "Yesterday",
"Index": 7.2
},
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree"
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass"
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed"
}
],
"Period": "0001-01-01T00:00:00",
"Type": "Today",
"Index": 6.6
},
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree"
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass"
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed"
}
],
"Period": "0001-01-01T00:00:00",
"Type": "Tomorrow",
"Index": 6.3
}
],
"DisplayLocation": "Schenectady, NY"
}
}

View file

@ -0,0 +1,9 @@
{
"Market": "SCHENECTADY, CO",
"ZIP": "12345",
"TrendID": 4,
"Trend": "subsiding",
"Outlook": "The amount of pollen in the air for Wednesday...",
"Season": "Tree"
}

View file

@ -0,0 +1,38 @@
{
"Type": "asthma",
"ForecastDate": "2018-10-28T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Period": "2018-10-28T05:45:01.45",
"Index": 4.5,
"Idx": "4.5"
},
{
"Period": "2018-10-29T05:45:01.45",
"Index": 4.7,
"Idx": "4.7"
},
{
"Period": "2018-10-30T05:45:01.45",
"Index": 5,
"Idx": "5.0"
},
{
"Period": "2018-10-31T05:45:01.45",
"Index": 5.2,
"Idx": "5.2"
},
{
"Period": "2018-11-01T05:45:01.45",
"Index": 5.5,
"Idx": "5.5"
}
],
"DisplayLocation": "Schenectady, NY"
}
}

View file

@ -0,0 +1,72 @@
{
"Type": "asthma",
"ForecastDate": "2018-10-29T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Triggers": [
{
"LGID": 1,
"Name": "OZONE",
"PPM": 42,
"Description": "Ozone (O3) is a odorless, colorless ...."
},
{
"LGID": 1,
"Name": "PM2.5",
"PPM": 30,
"Description": "Fine particles (PM2.5) are 2.5 ..."
},
{
"LGID": 1,
"Name": "PM10",
"PPM": 19,
"Description": "Coarse dust particles (PM10) are 2.5 ..."
}
],
"Period": "0001-01-01T00:00:00",
"Type": "Yesterday",
"Index": 4.1,
"Idx": "4.1"
},
{
"Triggers": [
{
"LGID": 3,
"Name": "PM2.5",
"PPM": 105,
"Description": "Fine particles (PM2.5) are 2.5 ..."
},
{
"LGID": 2,
"Name": "PM10",
"PPM": 65,
"Description": "Coarse dust particles (PM10) are 2.5 ..."
},
{
"LGID": 1,
"Name": "OZONE",
"PPM": 42,
"Description": "Ozone (O3) is a odorless, colorless ..."
}
],
"Period": "0001-01-01T00:00:00",
"Type": "Today",
"Index": 4.5,
"Idx": "4.5"
},
{
"Triggers": [],
"Period": "0001-01-01T00:00:00",
"Type": "Tomorrow",
"Index": 4.6,
"Idx": "4.6"
}
],
"DisplayLocation": "Schenectady, NY"
}
}

View file

@ -0,0 +1,29 @@
{
"Type": "cold",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Period": "2018-06-12T05:13:51.817",
"Index": 2.4
},
{
"Period": "2018-06-13T05:13:51.817",
"Index": 2.5
},
{
"Period": "2018-06-14T05:13:51.817",
"Index": 2.5
},
{
"Period": "2018-06-15T05:13:51.817",
"Index": 2.5
}
],
"DisplayLocation": "Schenectady, NY"
}
}

View file

@ -0,0 +1,77 @@
{
"ForecastDate": "2019-04-07T00:00:00-04:00",
"Location": {
"City": "SCHENECTADY",
"DisplayLocation": "Schenectady, NY",
"State": "NY",
"ZIP": "12345",
"periods": [
{
"Idx": "6.8",
"Index": 6.8,
"Period": "2019-04-06T00:00:00",
"Triggers": [
{
"Description": "Influenza",
"Idx": "3.1",
"Index": 3.1,
"Name": "Flu"
},
{
"Description": "High Fever",
"Idx": "6.2",
"Index": 6.2,
"Name": "Fever"
},
{
"Description": "Strep & Sore throat",
"Idx": "5.2",
"Index": 5.2,
"Name": "Strep"
},
{
"Description": "Cough",
"Idx": "7.8",
"Index": 7.8,
"Name": "Cough"
}
],
"Type": "Yesterday"
},
{
"Idx": "6.7",
"Index": 6.7,
"Period": "2019-04-07T03:52:58",
"Triggers": [
{
"Description": "Influenza",
"Idx": "3.1",
"Index": 3.1,
"Name": "Flu"
},
{
"Description": "High Fever",
"Idx": "5.9",
"Index": 5.9,
"Name": "Fever"
},
{
"Description": "Strep & Sore throat",
"Idx": "5.1",
"Index": 5.1,
"Name": "Strep"
},
{
"Description": "Cough",
"Idx": "7.7",
"Index": 7.7,
"Name": "Cough"
}
],
"Type": "Today"
}
]
},
"Type": "cold"
}

View file

@ -0,0 +1,324 @@
"""Test IQVIA diagnostics."""
from tests.components.diagnostics import get_diagnostics_for_config_entry
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_iqvia):
"""Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": {
"title": "Mock Title",
"data": {
"zip_code": "12345",
},
},
"data": {
"allergy_average_forecasted": {
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{"Period": "2018-06-12T13:47:12.897", "Index": 6.6},
{"Period": "2018-06-13T13:47:12.897", "Index": 6.3},
{"Period": "2018-06-14T13:47:12.897", "Index": 7.6},
{"Period": "2018-06-15T13:47:12.897", "Index": 7.6},
{"Period": "2018-06-16T13:47:12.897", "Index": 7.3},
],
"DisplayLocation": "Schenectady, NY",
},
},
"allergy_index": {
"Type": "pollen",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree",
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass",
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed",
},
],
"Period": "0001-01-01T00:00:00",
"Type": "Yesterday",
"Index": 7.2,
},
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree",
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass",
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed",
},
],
"Period": "0001-01-01T00:00:00",
"Type": "Today",
"Index": 6.6,
},
{
"Triggers": [
{
"LGID": 272,
"Name": "Juniper",
"Genus": "Juniperus",
"PlantType": "Tree",
},
{
"LGID": 346,
"Name": "Grasses",
"Genus": "Grasses",
"PlantType": "Grass",
},
{
"LGID": 63,
"Name": "Chenopods",
"Genus": "Chenopods",
"PlantType": "Ragweed",
},
],
"Period": "0001-01-01T00:00:00",
"Type": "Tomorrow",
"Index": 6.3,
},
],
"DisplayLocation": "Schenectady, NY",
},
},
"allergy_outlook": {
"Market": "SCHENECTADY, CO",
"ZIP": "12345",
"TrendID": 4,
"Trend": "subsiding",
"Outlook": "The amount of pollen in the air for Wednesday...",
"Season": "Tree",
},
"asthma_average_forecasted": {
"Type": "asthma",
"ForecastDate": "2018-10-28T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Period": "2018-10-28T05:45:01.45",
"Index": 4.5,
"Idx": "4.5",
},
{
"Period": "2018-10-29T05:45:01.45",
"Index": 4.7,
"Idx": "4.7",
},
{"Period": "2018-10-30T05:45:01.45", "Index": 5, "Idx": "5.0"},
{
"Period": "2018-10-31T05:45:01.45",
"Index": 5.2,
"Idx": "5.2",
},
{
"Period": "2018-11-01T05:45:01.45",
"Index": 5.5,
"Idx": "5.5",
},
],
"DisplayLocation": "Schenectady, NY",
},
},
"asthma_index": {
"Type": "asthma",
"ForecastDate": "2018-10-29T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{
"Triggers": [
{
"LGID": 1,
"Name": "OZONE",
"PPM": 42,
"Description": "Ozone (O3) is a odorless, colorless ....",
},
{
"LGID": 1,
"Name": "PM2.5",
"PPM": 30,
"Description": "Fine particles (PM2.5) are 2.5 ...",
},
{
"LGID": 1,
"Name": "PM10",
"PPM": 19,
"Description": "Coarse dust particles (PM10) are 2.5 ...",
},
],
"Period": "0001-01-01T00:00:00",
"Type": "Yesterday",
"Index": 4.1,
"Idx": "4.1",
},
{
"Triggers": [
{
"LGID": 3,
"Name": "PM2.5",
"PPM": 105,
"Description": "Fine particles (PM2.5) are 2.5 ...",
},
{
"LGID": 2,
"Name": "PM10",
"PPM": 65,
"Description": "Coarse dust particles (PM10) are 2.5 ...",
},
{
"LGID": 1,
"Name": "OZONE",
"PPM": 42,
"Description": "Ozone (O3) is a odorless, colorless ...",
},
],
"Period": "0001-01-01T00:00:00",
"Type": "Today",
"Index": 4.5,
"Idx": "4.5",
},
{
"Triggers": [],
"Period": "0001-01-01T00:00:00",
"Type": "Tomorrow",
"Index": 4.6,
"Idx": "4.6",
},
],
"DisplayLocation": "Schenectady, NY",
},
},
"disease_average_forecasted": {
"Type": "cold",
"ForecastDate": "2018-06-12T00:00:00-04:00",
"Location": {
"ZIP": "12345",
"City": "SCHENECTADY",
"State": "NY",
"periods": [
{"Period": "2018-06-12T05:13:51.817", "Index": 2.4},
{"Period": "2018-06-13T05:13:51.817", "Index": 2.5},
{"Period": "2018-06-14T05:13:51.817", "Index": 2.5},
{"Period": "2018-06-15T05:13:51.817", "Index": 2.5},
],
"DisplayLocation": "Schenectady, NY",
},
},
"disease_index": {
"ForecastDate": "2019-04-07T00:00:00-04:00",
"Location": {
"City": "SCHENECTADY",
"DisplayLocation": "Schenectady, NY",
"State": "NY",
"ZIP": "12345",
"periods": [
{
"Idx": "6.8",
"Index": 6.8,
"Period": "2019-04-06T00:00:00",
"Triggers": [
{
"Description": "Influenza",
"Idx": "3.1",
"Index": 3.1,
"Name": "Flu",
},
{
"Description": "High Fever",
"Idx": "6.2",
"Index": 6.2,
"Name": "Fever",
},
{
"Description": "Strep & Sore throat",
"Idx": "5.2",
"Index": 5.2,
"Name": "Strep",
},
{
"Description": "Cough",
"Idx": "7.8",
"Index": 7.8,
"Name": "Cough",
},
],
"Type": "Yesterday",
},
{
"Idx": "6.7",
"Index": 6.7,
"Period": "2019-04-07T03:52:58",
"Triggers": [
{
"Description": "Influenza",
"Idx": "3.1",
"Index": 3.1,
"Name": "Flu",
},
{
"Description": "High Fever",
"Idx": "5.9",
"Index": 5.9,
"Name": "Fever",
},
{
"Description": "Strep & Sore throat",
"Idx": "5.1",
"Index": 5.1,
"Name": "Strep",
},
{
"Description": "Cough",
"Idx": "7.7",
"Index": 7.7,
"Name": "Cough",
},
],
"Type": "Today",
},
],
},
"Type": "cold",
},
},
}