From 37cdc6d500b1bf4eb77f5d4d7eb69c9dac593d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20H=C3=B6rsken?= Date: Tue, 17 Sep 2024 23:17:04 +0200 Subject: [PATCH] Add diagnostics support for WMS WebControl pro (#126077) --- .../components/wmspro/diagnostics.py | 16 ++ homeassistant/components/wmspro/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../wmspro/snapshots/test_diagnostics.ambr | 240 ++++++++++++++++++ tests/components/wmspro/test_diagnostics.py | 34 +++ 6 files changed, 293 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/wmspro/diagnostics.py create mode 100644 tests/components/wmspro/snapshots/test_diagnostics.ambr create mode 100644 tests/components/wmspro/test_diagnostics.py diff --git a/homeassistant/components/wmspro/diagnostics.py b/homeassistant/components/wmspro/diagnostics.py new file mode 100644 index 00000000000..c35cecc5ab5 --- /dev/null +++ b/homeassistant/components/wmspro/diagnostics.py @@ -0,0 +1,16 @@ +"""Diagnostics support for WMS WebControl pro API integration.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.core import HomeAssistant + +from . import WebControlProConfigEntry + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: WebControlProConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + return entry.runtime_data.diag() diff --git a/homeassistant/components/wmspro/manifest.json b/homeassistant/components/wmspro/manifest.json index ec97f444a54..3e0c4e21e6c 100644 --- a/homeassistant/components/wmspro/manifest.json +++ b/homeassistant/components/wmspro/manifest.json @@ -15,5 +15,5 @@ "documentation": "https://www.home-assistant.io/integrations/wmspro", "integration_type": "hub", "iot_class": "local_polling", - "requirements": ["pywmspro==0.1.0"] + "requirements": ["pywmspro==0.2.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index ee7704f5f46..96edcc6cb0e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2471,7 +2471,7 @@ pywilight==0.0.74 pywizlight==0.5.14 # homeassistant.components.wmspro -pywmspro==0.1.0 +pywmspro==0.2.0 # homeassistant.components.ws66i pyws66i==1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b7e3e897817..3f693181f36 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1971,7 +1971,7 @@ pywilight==0.0.74 pywizlight==0.5.14 # homeassistant.components.wmspro -pywmspro==0.1.0 +pywmspro==0.2.0 # homeassistant.components.ws66i pyws66i==1.1 diff --git a/tests/components/wmspro/snapshots/test_diagnostics.ambr b/tests/components/wmspro/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..6a87c0416ab --- /dev/null +++ b/tests/components/wmspro/snapshots/test_diagnostics.ambr @@ -0,0 +1,240 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'config': dict({ + 'command': 'getConfiguration', + 'destinations': list([ + dict({ + 'actions': list([ + dict({ + 'actionDescription': 0, + 'actionType': 0, + 'id': 0, + 'maxValue': 100, + 'minValue': 0, + }), + dict({ + 'actionDescription': 12, + 'actionType': 6, + 'id': 16, + }), + dict({ + 'actionDescription': 13, + 'actionType': 8, + 'id': 22, + }), + ]), + 'animationType': 1, + 'id': 58717, + 'names': list([ + 'Markise', + '', + '', + '', + ]), + }), + dict({ + 'actions': list([ + dict({ + 'actionDescription': 8, + 'actionType': 0, + 'id': 0, + 'maxValue': 100, + 'minValue': 0, + }), + dict({ + 'actionDescription': 12, + 'actionType': 6, + 'id': 17, + }), + dict({ + 'actionDescription': 6, + 'actionType': 4, + 'id': 20, + }), + dict({ + 'actionDescription': 13, + 'actionType': 8, + 'id': 22, + }), + ]), + 'animationType': 6, + 'id': 97358, + 'names': list([ + 'Licht', + '', + '', + '', + ]), + }), + ]), + 'protocolVersion': '1.0.0', + 'rooms': list([ + dict({ + 'destinations': list([ + 58717, + 97358, + ]), + 'id': 19239, + 'name': 'Terrasse', + 'scenes': list([ + 687471, + 765095, + ]), + }), + ]), + 'scenes': list([ + dict({ + 'id': 687471, + 'names': list([ + 'Licht an', + '', + '', + '', + ]), + }), + dict({ + 'id': 765095, + 'names': list([ + 'Licht aus', + '', + '', + '', + ]), + }), + ]), + }), + 'dests': dict({ + '58717': dict({ + 'actions': dict({ + '0': dict({ + 'actionDescription': 'AwningDrive', + 'actionType': 'Percentage', + 'attrs': dict({ + 'maxValue': 100, + 'minValue': 0, + }), + 'id': 0, + 'params': dict({ + }), + }), + '16': dict({ + 'actionDescription': 'ManualCommand', + 'actionType': 'Stop', + 'attrs': dict({ + }), + 'id': 16, + 'params': dict({ + }), + }), + '22': dict({ + 'actionDescription': 'Identify', + 'actionType': 'Identify', + 'attrs': dict({ + }), + 'id': 22, + 'params': dict({ + }), + }), + }), + 'animationType': 'Awning', + 'available': True, + 'blocking': None, + 'drivingCause': 'Unknown', + 'heartbeatError': None, + 'id': 58717, + 'name': 'Markise', + 'room': dict({ + '19239': 'Terrasse', + }), + 'status': dict({ + }), + }), + '97358': dict({ + 'actions': dict({ + '0': dict({ + 'actionDescription': 'LightDimming', + 'actionType': 'Percentage', + 'attrs': dict({ + 'maxValue': 100, + 'minValue': 0, + }), + 'id': 0, + 'params': dict({ + }), + }), + '17': dict({ + 'actionDescription': 'ManualCommand', + 'actionType': 'Stop', + 'attrs': dict({ + }), + 'id': 17, + 'params': dict({ + }), + }), + '20': dict({ + 'actionDescription': 'LightSwitch', + 'actionType': 'Switch', + 'attrs': dict({ + }), + 'id': 20, + 'params': dict({ + }), + }), + '22': dict({ + 'actionDescription': 'Identify', + 'actionType': 'Identify', + 'attrs': dict({ + }), + 'id': 22, + 'params': dict({ + }), + }), + }), + 'animationType': 'Dimmer', + 'available': True, + 'blocking': None, + 'drivingCause': 'Unknown', + 'heartbeatError': None, + 'id': 97358, + 'name': 'Licht', + 'room': dict({ + '19239': 'Terrasse', + }), + 'status': dict({ + }), + }), + }), + 'host': 'webcontrol', + 'rooms': dict({ + '19239': dict({ + 'destinations': dict({ + '58717': 'Markise', + '97358': 'Licht', + }), + 'id': 19239, + 'name': 'Terrasse', + 'scenes': dict({ + '687471': 'Licht an', + '765095': 'Licht aus', + }), + }), + }), + 'scenes': dict({ + '687471': dict({ + 'id': 687471, + 'name': 'Licht an', + 'room': dict({ + '19239': 'Terrasse', + }), + }), + '765095': dict({ + 'id': 765095, + 'name': 'Licht aus', + 'room': dict({ + '19239': 'Terrasse', + }), + }), + }), + }) +# --- diff --git a/tests/components/wmspro/test_diagnostics.py b/tests/components/wmspro/test_diagnostics.py new file mode 100644 index 00000000000..930c3f2898e --- /dev/null +++ b/tests/components/wmspro/test_diagnostics.py @@ -0,0 +1,34 @@ +"""Test the wmspro diagnostics.""" + +from unittest.mock import AsyncMock + +from syrupy import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from . import setup_config_entry + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_config_entry: MockConfigEntry, + mock_hub_ping: AsyncMock, + mock_hub_configuration_prod: AsyncMock, + mock_dest_refresh: AsyncMock, + snapshot: SnapshotAssertion, +) -> None: + """Test that a config entry can be loaded with DeviceConfig.""" + assert await setup_config_entry(hass, mock_config_entry) + assert len(mock_hub_ping.mock_calls) == 1 + assert len(mock_hub_configuration_prod.mock_calls) == 1 + assert len(mock_dest_refresh.mock_calls) == 2 + + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + assert result == snapshot