diff --git a/homeassistant/components/rainmachine/diagnostics.py b/homeassistant/components/rainmachine/diagnostics.py index 58b918c18ee..131f2e130e7 100644 --- a/homeassistant/components/rainmachine/diagnostics.py +++ b/homeassistant/components/rainmachine/diagnostics.py @@ -1,20 +1,38 @@ """Diagnostics support for RainMachine.""" from __future__ import annotations +import asyncio from typing import Any +from regenmaschine.errors import RequestError + from homeassistant.components.diagnostics import async_redact_data from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_PASSWORD +from homeassistant.const import ( + CONF_ELEVATION, + CONF_LATITUDE, + CONF_LONGITUDE, + CONF_PASSWORD, +) from homeassistant.core import HomeAssistant from . import RainMachineData from .const import DOMAIN +CONF_STATION_ID = "stationID" +CONF_STATION_NAME = "stationName" +CONF_STATION_SOURCE = "stationSource" +CONF_TIMEZONE = "timezone" + TO_REDACT = { + CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_PASSWORD, + CONF_STATION_ID, + CONF_STATION_NAME, + CONF_STATION_SOURCE, + CONF_TIMEZONE, } @@ -24,6 +42,14 @@ async def async_get_config_entry_diagnostics( """Return diagnostics for a config entry.""" data: RainMachineData = hass.data[DOMAIN][entry.entry_id] + controller_tasks = { + "versions": data.controller.api.versions(), + "current_diagnostics": data.controller.diagnostics.current(), + } + controller_results = await asyncio.gather( + *controller_tasks.values(), return_exceptions=True + ) + return { "entry": { "title": entry.title, @@ -39,10 +65,9 @@ async def async_get_config_entry_diagnostics( TO_REDACT, ), "controller": { - "api_version": data.controller.api_version, - "hardware_version": data.controller.hardware_version, - "name": data.controller.name, - "software_version": data.controller.software_version, + category: result + for category, result in zip(controller_tasks, controller_results) + if not isinstance(result, RequestError) }, }, } diff --git a/tests/components/rainmachine/conftest.py b/tests/components/rainmachine/conftest.py index 457df4a3ef2..72b4a5d4293 100644 --- a/tests/components/rainmachine/conftest.py +++ b/tests/components/rainmachine/conftest.py @@ -39,6 +39,8 @@ def config_entry_fixture(hass, config, controller_mac): @pytest.fixture(name="controller") def controller_fixture( controller_mac, + data_api_versions, + data_diagnostics_current, data_programs, data_provision_settings, data_restrictions_current, @@ -55,6 +57,8 @@ def controller_fixture( controller.mac = controller_mac controller.software_version = "4.0.925" + controller.api.versions.return_value = data_api_versions + controller.diagnostics.current.return_value = data_diagnostics_current controller.programs.all.return_value = data_programs controller.provisioning.settings.return_value = data_provision_settings controller.restrictions.current.return_value = data_restrictions_current @@ -70,6 +74,18 @@ def controller_mac_fixture(): return "aa:bb:cc:dd:ee:ff" +@pytest.fixture(name="data_api_versions", scope="session") +def data_api_versions_fixture(): + """Define API version data.""" + return json.loads(load_fixture("api_versions_data.json", "rainmachine")) + + +@pytest.fixture(name="data_diagnostics_current", scope="session") +def data_diagnostics_current_fixture(): + """Define current diagnostics data.""" + return json.loads(load_fixture("diagnostics_current_data.json", "rainmachine")) + + @pytest.fixture(name="data_programs", scope="session") def data_programs_fixture(): """Define program data.""" diff --git a/tests/components/rainmachine/fixtures/api_versions_data.json b/tests/components/rainmachine/fixtures/api_versions_data.json new file mode 100644 index 00000000000..d4ec1fb80e9 --- /dev/null +++ b/tests/components/rainmachine/fixtures/api_versions_data.json @@ -0,0 +1,5 @@ +{ + "apiVer": "4.6.1", + "hwVer": 3, + "swVer": "4.0.1144" +} diff --git a/tests/components/rainmachine/fixtures/diagnostics_current_data.json b/tests/components/rainmachine/fixtures/diagnostics_current_data.json new file mode 100644 index 00000000000..40afd504911 --- /dev/null +++ b/tests/components/rainmachine/fixtures/diagnostics_current_data.json @@ -0,0 +1,21 @@ +{ + "hasWifi": true, + "uptime": "3 days, 18:14:14", + "uptimeSeconds": 324854, + "memUsage": 16196, + "networkStatus": true, + "bootCompleted": true, + "lastCheckTimestamp": 1659895175, + "wizardHasRun": true, + "standaloneMode": false, + "cpuUsage": 1, + "lastCheck": "2022-08-07 11:59:35", + "softwareVersion": "4.0.1144", + "internetStatus": true, + "locationStatus": true, + "timeStatus": true, + "wifiMode": null, + "gatewayAddress": "172.16.20.1", + "cloudStatus": 0, + "weatherStatus": true +} diff --git a/tests/components/rainmachine/test_diagnostics.py b/tests/components/rainmachine/test_diagnostics.py index d770d01fd36..b0876a2f597 100644 --- a/tests/components/rainmachine/test_diagnostics.py +++ b/tests/components/rainmachine/test_diagnostics.py @@ -19,6 +19,90 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_rainmach }, "data": { "coordinator": { + "provision.settings": { + "system": { + "httpEnabled": True, + "rainSensorSnoozeDuration": 0, + "uiUnitsMetric": False, + "programZonesShowInactive": False, + "programSingleSchedule": False, + "standaloneMode": False, + "masterValveAfter": 0, + "touchSleepTimeout": 10, + "selfTest": False, + "useSoftwareRainSensor": False, + "defaultZoneWateringDuration": 300, + "maxLEDBrightness": 40, + "simulatorHistorySize": 0, + "vibration": False, + "masterValveBefore": 0, + "touchProgramToRun": None, + "useRainSensor": False, + "wizardHasRun": True, + "waterLogHistorySize": 365, + "netName": "Home", + "softwareRainSensorMinQPF": 5, + "touchAdvanced": False, + "useBonjourService": True, + "hardwareVersion": 3, + "touchLongPressTimeout": 3, + "showRestrictionsOnLed": False, + "parserDataSizeInDays": 6, + "programListShowInactive": True, + "parserHistorySize": 365, + "allowAlexaDiscovery": False, + "automaticUpdates": True, + "minLEDBrightness": 0, + "minWateringDurationThreshold": 0, + "localValveCount": 12, + "touchAuthAPSeconds": 60, + "useCommandLineArguments": False, + "databasePath": "/rainmachine-app/DB/Default", + "touchCyclePrograms": True, + "zoneListShowInactive": True, + "rainSensorRainStart": None, + "zoneDuration": [ + 300, + 300, + 300, + 300, + 300, + 300, + 300, + 300, + 300, + 300, + 300, + 300, + ], + "rainSensorIsNormallyClosed": True, + "useCorrectionForPast": True, + "useMasterValve": False, + "runParsersBeforePrograms": True, + "maxWateringCoef": 2, + "mixerHistorySize": 365, + }, + "location": { + "elevation": REDACTED, + "doyDownloaded": True, + "zip": None, + "windSensitivity": 0.5, + "krs": 0.16, + "stationID": REDACTED, + "stationSource": REDACTED, + "et0Average": 6.578, + "latitude": REDACTED, + "state": "Default", + "stationName": REDACTED, + "wsDays": 2, + "stationDownloaded": True, + "address": "Default", + "rainSensitivity": 0.8, + "timezone": REDACTED, + "longitude": REDACTED, + "name": "Home", + }, + }, "programs": [ { "uid": 1, @@ -297,90 +381,6 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_rainmach ], }, ], - "provision.settings": { - "system": { - "httpEnabled": True, - "rainSensorSnoozeDuration": 0, - "uiUnitsMetric": False, - "programZonesShowInactive": False, - "programSingleSchedule": False, - "standaloneMode": False, - "masterValveAfter": 0, - "touchSleepTimeout": 10, - "selfTest": False, - "useSoftwareRainSensor": False, - "defaultZoneWateringDuration": 300, - "maxLEDBrightness": 40, - "simulatorHistorySize": 0, - "vibration": False, - "masterValveBefore": 0, - "touchProgramToRun": None, - "useRainSensor": False, - "wizardHasRun": True, - "waterLogHistorySize": 365, - "netName": "Home", - "softwareRainSensorMinQPF": 5, - "touchAdvanced": False, - "useBonjourService": True, - "hardwareVersion": 3, - "touchLongPressTimeout": 3, - "showRestrictionsOnLed": False, - "parserDataSizeInDays": 6, - "programListShowInactive": True, - "parserHistorySize": 365, - "allowAlexaDiscovery": False, - "automaticUpdates": True, - "minLEDBrightness": 0, - "minWateringDurationThreshold": 0, - "localValveCount": 12, - "touchAuthAPSeconds": 60, - "useCommandLineArguments": False, - "databasePath": "/rainmachine-app/DB/Default", - "touchCyclePrograms": True, - "zoneListShowInactive": True, - "rainSensorRainStart": None, - "zoneDuration": [ - 300, - 300, - 300, - 300, - 300, - 300, - 300, - 300, - 300, - 300, - 300, - 300, - ], - "rainSensorIsNormallyClosed": True, - "useCorrectionForPast": True, - "useMasterValve": False, - "runParsersBeforePrograms": True, - "maxWateringCoef": 2, - "mixerHistorySize": 365, - }, - "location": { - "elevation": 1593.45141602, - "doyDownloaded": True, - "zip": None, - "windSensitivity": 0.5, - "krs": 0.16, - "stationID": 9172, - "stationSource": "station", - "et0Average": 6.578, - "latitude": REDACTED, - "state": "Default", - "stationName": "MY STATION", - "wsDays": 2, - "stationDownloaded": True, - "address": "Default", - "rainSensitivity": 0.8, - "timezone": "America/Los Angeles", - "longitude": REDACTED, - "name": "Home", - }, - }, "restrictions.current": { "hourly": False, "freeze": False, @@ -583,10 +583,32 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_rainmach ], }, "controller": { - "api_version": "4.5.0", - "hardware_version": 3, - "name": 12345, - "software_version": "4.0.925", + "versions": { + "apiVer": "4.6.1", + "hwVer": 3, + "swVer": "4.0.1144", + }, + "current_diagnostics": { + "hasWifi": True, + "uptime": "3 days, 18:14:14", + "uptimeSeconds": 324854, + "memUsage": 16196, + "networkStatus": True, + "bootCompleted": True, + "lastCheckTimestamp": 1659895175, + "wizardHasRun": True, + "standaloneMode": False, + "cpuUsage": 1, + "lastCheck": "2022-08-07 11:59:35", + "softwareVersion": "4.0.1144", + "internetStatus": True, + "locationStatus": True, + "timeStatus": True, + "wifiMode": None, + "gatewayAddress": "172.16.20.1", + "cloudStatus": 0, + "weatherStatus": True, + }, }, }, }