From 0546e7601cd42204dcab8791e4948eba25368f66 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 9 Jul 2023 22:50:12 +0200 Subject: [PATCH] Enhance diagnostics for Sensibo (#96150) * Diag Sensibo * Fix snapshot --- .../components/sensibo/diagnostics.py | 6 +- .../sensibo/snapshots/test_diagnostics.ambr | 257 ++++++++++++++++++ tests/components/sensibo/test_diagnostics.py | 22 +- 3 files changed, 276 insertions(+), 9 deletions(-) create mode 100644 tests/components/sensibo/snapshots/test_diagnostics.ambr diff --git a/homeassistant/components/sensibo/diagnostics.py b/homeassistant/components/sensibo/diagnostics.py index 72029acc2f1..9d998e739f0 100644 --- a/homeassistant/components/sensibo/diagnostics.py +++ b/homeassistant/components/sensibo/diagnostics.py @@ -33,4 +33,8 @@ async def async_get_config_entry_diagnostics( ) -> dict[str, Any]: """Return diagnostics for Sensibo config entry.""" coordinator: SensiboDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - return async_redact_data(coordinator.data.raw, TO_REDACT) + diag_data = {} + diag_data["raw"] = async_redact_data(coordinator.data.raw, TO_REDACT) + for device, device_data in coordinator.data.parsed.items(): + diag_data[device] = async_redact_data(device_data.__dict__, TO_REDACT) + return diag_data diff --git a/tests/components/sensibo/snapshots/test_diagnostics.ambr b/tests/components/sensibo/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..a3ec6952c6c --- /dev/null +++ b/tests/components/sensibo/snapshots/test_diagnostics.ambr @@ -0,0 +1,257 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'fanLevel': 'high', + 'horizontalSwing': 'stopped', + 'light': 'on', + 'mode': 'heat', + 'on': True, + 'swing': 'stopped', + 'targetTemperature': 25, + 'timestamp': dict({ + 'secondsAgo': -1, + 'time': '2022-04-30T11:23:30.019722Z', + }), + }) +# --- +# name: test_diagnostics.1 + dict({ + 'modes': dict({ + 'auto': dict({ + 'fanLevels': list([ + 'quiet', + 'low', + 'medium', + ]), + 'horizontalSwing': list([ + 'stopped', + 'fixedLeft', + 'fixedCenterLeft', + ]), + 'light': list([ + 'on', + 'off', + ]), + 'swing': list([ + 'stopped', + 'fixedTop', + 'fixedMiddleTop', + ]), + 'temperatures': dict({ + 'C': dict({ + 'isNative': True, + 'values': list([ + 10, + 16, + 17, + 18, + 19, + 20, + ]), + }), + 'F': dict({ + 'isNative': False, + 'values': list([ + 64, + 66, + 68, + ]), + }), + }), + }), + 'cool': dict({ + 'fanLevels': list([ + 'quiet', + 'low', + 'medium', + ]), + 'horizontalSwing': list([ + 'stopped', + 'fixedLeft', + 'fixedCenterLeft', + ]), + 'light': list([ + 'on', + 'off', + ]), + 'swing': list([ + 'stopped', + 'fixedTop', + 'fixedMiddleTop', + ]), + 'temperatures': dict({ + 'C': dict({ + 'isNative': True, + 'values': list([ + 10, + 16, + 17, + 18, + 19, + 20, + ]), + }), + 'F': dict({ + 'isNative': False, + 'values': list([ + 64, + 66, + 68, + ]), + }), + }), + }), + 'dry': dict({ + 'horizontalSwing': list([ + 'stopped', + 'fixedLeft', + 'fixedCenterLeft', + ]), + 'light': list([ + 'on', + 'off', + ]), + 'swing': list([ + 'stopped', + 'fixedTop', + 'fixedMiddleTop', + ]), + 'temperatures': dict({ + 'C': dict({ + 'isNative': True, + 'values': list([ + 10, + 16, + 17, + 18, + 19, + 20, + ]), + }), + 'F': dict({ + 'isNative': False, + 'values': list([ + 64, + 66, + 68, + ]), + }), + }), + }), + 'fan': dict({ + 'fanLevels': list([ + 'quiet', + 'low', + 'medium', + ]), + 'horizontalSwing': list([ + 'stopped', + 'fixedLeft', + 'fixedCenterLeft', + ]), + 'light': list([ + 'on', + 'off', + ]), + 'swing': list([ + 'stopped', + 'fixedTop', + 'fixedMiddleTop', + ]), + 'temperatures': dict({ + }), + }), + 'heat': dict({ + 'fanLevels': list([ + 'quiet', + 'low', + 'medium', + ]), + 'horizontalSwing': list([ + 'stopped', + 'fixedLeft', + 'fixedCenterLeft', + ]), + 'light': list([ + 'on', + 'off', + ]), + 'swing': list([ + 'stopped', + 'fixedTop', + 'fixedMiddleTop', + ]), + 'temperatures': dict({ + 'C': dict({ + 'isNative': True, + 'values': list([ + 10, + 16, + 17, + 18, + 19, + 20, + ]), + }), + 'F': dict({ + 'isNative': False, + 'values': list([ + 63, + 64, + 66, + ]), + }), + }), + }), + }), + }) +# --- +# name: test_diagnostics.2 + dict({ + 'low': 'low', + 'medium': 'medium', + 'quiet': 'quiet', + }) +# --- +# name: test_diagnostics.3 + dict({ + 'fixedmiddletop': 'fixedMiddleTop', + 'fixedtop': 'fixedTop', + 'stopped': 'stopped', + }) +# --- +# name: test_diagnostics.4 + dict({ + 'fixedcenterleft': 'fixedCenterLeft', + 'fixedleft': 'fixedLeft', + 'stopped': 'stopped', + }) +# --- +# name: test_diagnostics.5 + dict({ + 'fanlevel': 'low', + 'horizontalswing': 'stopped', + 'light': 'on', + 'mode': 'heat', + 'on': True, + 'swing': 'stopped', + 'targettemperature': 21, + 'temperatureunit': 'c', + }) +# --- +# name: test_diagnostics.6 + dict({ + 'fanlevel': 'high', + 'horizontalswing': 'stopped', + 'light': 'on', + 'mode': 'cool', + 'on': True, + 'swing': 'stopped', + 'targettemperature': 21, + 'temperatureunit': 'c', + }) +# --- +# name: test_diagnostics.7 + dict({ + }) +# --- diff --git a/tests/components/sensibo/test_diagnostics.py b/tests/components/sensibo/test_diagnostics.py index 2cbd20a7437..c3e1625d623 100644 --- a/tests/components/sensibo/test_diagnostics.py +++ b/tests/components/sensibo/test_diagnostics.py @@ -1,6 +1,8 @@ """Test Sensibo diagnostics.""" from __future__ import annotations +from syrupy.assertion import SnapshotAssertion + from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -9,17 +11,21 @@ from tests.typing import ClientSessionGenerator async def test_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator, load_int: ConfigEntry + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + load_int: ConfigEntry, + snapshot: SnapshotAssertion, ) -> None: """Test generating diagnostics for a config entry.""" entry = load_int diag = await get_diagnostics_for_config_entry(hass, hass_client, entry) - assert diag["status"] == "success" - for device in diag["result"]: - assert device["id"] == "**REDACTED**" - assert device["qrId"] == "**REDACTED**" - assert device["macAddress"] == "**REDACTED**" - assert device["location"] == "**REDACTED**" - assert device["productModel"] in ["skyv2", "pure"] + assert diag["ABC999111"]["ac_states"] == snapshot + assert diag["ABC999111"]["full_capabilities"] == snapshot + assert diag["ABC999111"]["fan_modes_translated"] == snapshot + assert diag["ABC999111"]["swing_modes_translated"] == snapshot + assert diag["ABC999111"]["horizontal_swing_modes_translated"] == snapshot + assert diag["ABC999111"]["smart_low_state"] == snapshot + assert diag["ABC999111"]["smart_high_state"] == snapshot + assert diag["ABC999111"]["pure_conf"] == snapshot