From d56ad146732beab72d66a72d2607a92aa6a669f2 Mon Sep 17 00:00:00 2001 From: mkmer Date: Sun, 10 Sep 2023 09:49:56 -0400 Subject: [PATCH] Add diagnostic platform to Honeywell (#100046) Add diagnostic platform --- .../components/honeywell/diagnostics.py | 33 ++++++++++++ tests/components/honeywell/conftest.py | 43 +++++++++++++++ .../honeywell/snapshots/test_diagnostics.ambr | 53 +++++++++++++++++++ .../components/honeywell/test_diagnostics.py | 35 ++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 homeassistant/components/honeywell/diagnostics.py create mode 100644 tests/components/honeywell/snapshots/test_diagnostics.ambr create mode 100644 tests/components/honeywell/test_diagnostics.py diff --git a/homeassistant/components/honeywell/diagnostics.py b/homeassistant/components/honeywell/diagnostics.py new file mode 100644 index 00000000000..4aebfc4c905 --- /dev/null +++ b/homeassistant/components/honeywell/diagnostics.py @@ -0,0 +1,33 @@ +"""Diagnostics support for Honeywell.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import HoneywellData +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, + config_entry: ConfigEntry, +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + + Honeywell: HoneywellData = hass.data[DOMAIN][config_entry.entry_id] + diagnostics_data = {} + + for device, module in Honeywell.devices.items(): + diagnostics_data.update( + { + f"Device {device}": { + "UI Data": module.raw_ui_data, + "Fan Data": module.raw_fan_data, + "DR Data": module.raw_dr_data, + } + } + ) + + return diagnostics_data diff --git a/tests/components/honeywell/conftest.py b/tests/components/honeywell/conftest.py index 8406d76803a..876050586d2 100644 --- a/tests/components/honeywell/conftest.py +++ b/tests/components/honeywell/conftest.py @@ -108,6 +108,8 @@ def device(): mock_device.heat_away_temp = HEATAWAY mock_device.cool_away_temp = COOLAWAY + mock_device.raw_dr_data = {"CoolSetpLimit": None, "HeatSetpLimit": None} + return mock_device @@ -127,6 +129,27 @@ def device_with_outdoor_sensor(): mock_device.temperature_unit = "C" mock_device.outdoor_temperature = OUTDOORTEMP mock_device.outdoor_humidity = OUTDOORHUMIDITY + mock_device.raw_ui_data = { + "SwitchOffAllowed": True, + "SwitchAutoAllowed": True, + "SwitchCoolAllowed": True, + "SwitchHeatAllowed": True, + "SwitchEmergencyHeatAllowed": True, + "HeatUpperSetptLimit": HEATUPPERSETPOINTLIMIT, + "HeatLowerSetptLimit": HEATLOWERSETPOINTLIMIT, + "CoolUpperSetptLimit": COOLUPPERSETPOINTLIMIT, + "CoolLowerSetptLimit": COOLLOWERSETPOINTLIMIT, + "HeatNextPeriod": NEXTHEATPERIOD, + "CoolNextPeriod": NEXTCOOLPERIOD, + } + mock_device.raw_fan_data = { + "fanModeOnAllowed": True, + "fanModeAutoAllowed": True, + "fanModeCirculateAllowed": True, + } + + mock_device.raw_dr_data = {"CoolSetpLimit": None, "HeatSetpLimit": None} + return mock_device @@ -145,6 +168,26 @@ def another_device(): mock_device.mac_address = "macaddress1" mock_device.outdoor_temperature = None mock_device.outdoor_humidity = None + mock_device.raw_ui_data = { + "SwitchOffAllowed": True, + "SwitchAutoAllowed": True, + "SwitchCoolAllowed": True, + "SwitchHeatAllowed": True, + "SwitchEmergencyHeatAllowed": True, + "HeatUpperSetptLimit": HEATUPPERSETPOINTLIMIT, + "HeatLowerSetptLimit": HEATLOWERSETPOINTLIMIT, + "CoolUpperSetptLimit": COOLUPPERSETPOINTLIMIT, + "CoolLowerSetptLimit": COOLLOWERSETPOINTLIMIT, + "HeatNextPeriod": NEXTHEATPERIOD, + "CoolNextPeriod": NEXTCOOLPERIOD, + } + mock_device.raw_fan_data = { + "fanModeOnAllowed": True, + "fanModeAutoAllowed": True, + "fanModeCirculateAllowed": True, + } + + mock_device.raw_dr_data = {"CoolSetpLimit": None, "HeatSetpLimit": None} return mock_device diff --git a/tests/components/honeywell/snapshots/test_diagnostics.ambr b/tests/components/honeywell/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..3077fc747de --- /dev/null +++ b/tests/components/honeywell/snapshots/test_diagnostics.ambr @@ -0,0 +1,53 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'Device 1234567': dict({ + 'DR Data': dict({ + 'CoolSetpLimit': None, + 'HeatSetpLimit': None, + }), + 'Fan Data': dict({ + 'fanModeAutoAllowed': True, + 'fanModeCirculateAllowed': True, + 'fanModeOnAllowed': True, + }), + 'UI Data': dict({ + 'CoolLowerSetptLimit': 10, + 'CoolNextPeriod': 10, + 'CoolUpperSetptLimit': 20, + 'HeatLowerSetptLimit': 20, + 'HeatNextPeriod': 10, + 'HeatUpperSetptLimit': 35, + 'SwitchAutoAllowed': True, + 'SwitchCoolAllowed': True, + 'SwitchEmergencyHeatAllowed': True, + 'SwitchHeatAllowed': True, + 'SwitchOffAllowed': True, + }), + }), + 'Device 7654321': dict({ + 'DR Data': dict({ + 'CoolSetpLimit': None, + 'HeatSetpLimit': None, + }), + 'Fan Data': dict({ + 'fanModeAutoAllowed': True, + 'fanModeCirculateAllowed': True, + 'fanModeOnAllowed': True, + }), + 'UI Data': dict({ + 'CoolLowerSetptLimit': 10, + 'CoolNextPeriod': 10, + 'CoolUpperSetptLimit': 20, + 'HeatLowerSetptLimit': 20, + 'HeatNextPeriod': 10, + 'HeatUpperSetptLimit': 35, + 'SwitchAutoAllowed': True, + 'SwitchCoolAllowed': True, + 'SwitchEmergencyHeatAllowed': True, + 'SwitchHeatAllowed': True, + 'SwitchOffAllowed': True, + }), + }), + }) +# --- diff --git a/tests/components/honeywell/test_diagnostics.py b/tests/components/honeywell/test_diagnostics.py new file mode 100644 index 00000000000..aafc50d5545 --- /dev/null +++ b/tests/components/honeywell/test_diagnostics.py @@ -0,0 +1,35 @@ +"""Test Honeywell diagnostics.""" +from unittest.mock import MagicMock + +from syrupy import SnapshotAssertion + +from homeassistant.config_entries import ConfigEntryState +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + +YAML_CONFIG = {"username": "test-user", "password": "test-password"} + + +async def test_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, + config_entry: MockConfigEntry, + location: MagicMock, + another_device: MagicMock, +) -> None: + """Test config entry diagnostics for Honeywell.""" + + location.devices_by_id[another_device.deviceid] = another_device + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + assert config_entry.state is ConfigEntryState.LOADED + assert hass.states.async_entity_ids_count() == 6 + + result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + + assert result == snapshot