diff --git a/homeassistant/components/iqvia/diagnostics.py b/homeassistant/components/iqvia/diagnostics.py new file mode 100644 index 00000000000..ee722005874 --- /dev/null +++ b/homeassistant/components/iqvia/diagnostics.py @@ -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() + }, + } diff --git a/tests/components/iqvia/conftest.py b/tests/components/iqvia/conftest.py index 5ec258e3c97..5b6a76e7e57 100644 --- a/tests/components/iqvia/conftest.py +++ b/tests/components/iqvia/conftest.py @@ -1,4 +1,5 @@ """Define test fixtures for IQVIA.""" +import json from unittest.mock import patch import pytest @@ -6,13 +7,13 @@ import pytest from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN from homeassistant.setup import async_setup_component -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, load_fixture @pytest.fixture(name="config_entry") def config_entry_fixture(hass, config, unique_id): """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) 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") -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.""" - 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) await hass.async_block_till_done() yield diff --git a/tests/components/iqvia/fixtures/allergy_forecast_data.json b/tests/components/iqvia/fixtures/allergy_forecast_data.json new file mode 100644 index 00000000000..2888feaa5a6 --- /dev/null +++ b/tests/components/iqvia/fixtures/allergy_forecast_data.json @@ -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" + } +} + diff --git a/tests/components/iqvia/fixtures/allergy_index_data.json b/tests/components/iqvia/fixtures/allergy_index_data.json new file mode 100644 index 00000000000..9954c780dbb --- /dev/null +++ b/tests/components/iqvia/fixtures/allergy_index_data.json @@ -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" + } +} + diff --git a/tests/components/iqvia/fixtures/allergy_outlook_data.json b/tests/components/iqvia/fixtures/allergy_outlook_data.json new file mode 100644 index 00000000000..8696b45173a --- /dev/null +++ b/tests/components/iqvia/fixtures/allergy_outlook_data.json @@ -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" +} + diff --git a/tests/components/iqvia/fixtures/asthma_forecast_data.json b/tests/components/iqvia/fixtures/asthma_forecast_data.json new file mode 100644 index 00000000000..89b9d2279c0 --- /dev/null +++ b/tests/components/iqvia/fixtures/asthma_forecast_data.json @@ -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" + } +} + diff --git a/tests/components/iqvia/fixtures/asthma_index_data.json b/tests/components/iqvia/fixtures/asthma_index_data.json new file mode 100644 index 00000000000..3ddf54c150b --- /dev/null +++ b/tests/components/iqvia/fixtures/asthma_index_data.json @@ -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" + } +} + diff --git a/tests/components/iqvia/fixtures/disease_forecast_data.json b/tests/components/iqvia/fixtures/disease_forecast_data.json new file mode 100644 index 00000000000..3760d60a549 --- /dev/null +++ b/tests/components/iqvia/fixtures/disease_forecast_data.json @@ -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" + } +} + diff --git a/tests/components/iqvia/fixtures/disease_index_data.json b/tests/components/iqvia/fixtures/disease_index_data.json new file mode 100644 index 00000000000..3f8241bf10c --- /dev/null +++ b/tests/components/iqvia/fixtures/disease_index_data.json @@ -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" +} + diff --git a/tests/components/iqvia/test_diagnostics.py b/tests/components/iqvia/test_diagnostics.py new file mode 100644 index 00000000000..4c5f4bcac75 --- /dev/null +++ b/tests/components/iqvia/test_diagnostics.py @@ -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", + }, + }, + }