From 1fc717ed1cfee06d3ce70cc123a84c9d97319fb5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 8 Feb 2022 12:43:45 +0100 Subject: [PATCH] Add diagnostics support to Plugwise (#65982) --- .../components/plugwise/diagnostics.py | 23 ++ tests/components/plugwise/test_diagnostics.py | 376 ++++++++++++++++++ 2 files changed, 399 insertions(+) create mode 100644 homeassistant/components/plugwise/diagnostics.py create mode 100644 tests/components/plugwise/test_diagnostics.py diff --git a/homeassistant/components/plugwise/diagnostics.py b/homeassistant/components/plugwise/diagnostics.py new file mode 100644 index 00000000000..2b79d22f6a3 --- /dev/null +++ b/homeassistant/components/plugwise/diagnostics.py @@ -0,0 +1,23 @@ +"""Diagnostics support for Plugwise.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .const import COORDINATOR, DOMAIN +from .coordinator import PlugwiseDataUpdateCoordinator + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: PlugwiseDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][ + COORDINATOR + ] + return { + "gateway": coordinator.data.gateway, + "devices": coordinator.data.devices, + } diff --git a/tests/components/plugwise/test_diagnostics.py b/tests/components/plugwise/test_diagnostics.py new file mode 100644 index 00000000000..fdc4ee87920 --- /dev/null +++ b/tests/components/plugwise/test_diagnostics.py @@ -0,0 +1,376 @@ +"""Tests for the diagnostics data provided by the Plugwise integration.""" +from unittest.mock import MagicMock + +from aiohttp import ClientSession + +from homeassistant.core import HomeAssistant + +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.components.plugwise.common import async_init_integration + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSession, + mock_smile_adam: MagicMock, +): + """Test diagnostics.""" + entry = await async_init_integration(hass, mock_smile_adam) + assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == { + "gateway": { + "active_device": True, + "cooling_present": None, + "gateway_id": "fe799307f1624099878210aa0b9f1475", + "heater_id": "90986d591dcd426cae3ec3e8111ff730", + "single_master_thermostat": False, + "smile_name": "Adam", + "notifications": { + "af82e4ccf9c548528166d38e560662a4": { + "warning": "Node Plug (with MAC address 000D6F000D13CB01, in room 'n.a.') has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device." + } + }, + }, + "devices": { + "df4a4a8169904cdb9c03d61a21f42140": { + "class": "zone_thermostat", + "fw": "2016-10-27T02:00:00+02:00", + "location": "12493538af164a409c6a1c79e38afe1c", + "model": "Lisa", + "name": "Zone Lisa Bios", + "vendor": "Plugwise", + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], + "active_preset": "away", + "presets": { + "home": [20.0, 22.0], + "asleep": [17.0, 24.0], + "away": [15.0, 25.0], + "vacation": [15.0, 28.0], + "no_frost": [10.0, 30.0], + }, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie", + ], + "selected_schedule": "None", + "schedule_temperature": 15.0, + "last_used": "Badkamer Schema", + "mode": "off", + "sensors": {"temperature": 16.5, "setpoint": 13.0, "battery": 67}, + }, + "b310b72a0e354bfab43089919b9a88bf": { + "class": "thermo_sensor", + "fw": "2019-03-27T01:00:00+01:00", + "location": "c50f167537524366a5af7aa3942feb1e", + "model": "Tom/Floor", + "name": "Floor kraan", + "vendor": "Plugwise", + "sensors": { + "temperature": 26.0, + "setpoint": 21.5, + "temperature_difference": 3.5, + "valve_position": 100, + }, + }, + "a2c3583e0a6349358998b760cea82d2a": { + "class": "thermo_sensor", + "fw": "2019-03-27T01:00:00+01:00", + "location": "12493538af164a409c6a1c79e38afe1c", + "model": "Tom/Floor", + "name": "Bios Cv Thermostatic Radiator ", + "vendor": "Plugwise", + "sensors": { + "temperature": 17.2, + "setpoint": 13.0, + "battery": 62, + "temperature_difference": -0.2, + "valve_position": 0.0, + }, + }, + "b59bcebaf94b499ea7d46e4a66fb62d8": { + "class": "zone_thermostat", + "fw": "2016-08-02T02:00:00+02:00", + "location": "c50f167537524366a5af7aa3942feb1e", + "model": "Lisa", + "name": "Zone Lisa WK", + "vendor": "Plugwise", + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], + "active_preset": "home", + "presets": { + "home": [20.0, 22.0], + "asleep": [17.0, 24.0], + "away": [15.0, 25.0], + "vacation": [15.0, 28.0], + "no_frost": [10.0, 30.0], + }, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie", + ], + "selected_schedule": "GF7 Woonkamer", + "schedule_temperature": 20.0, + "last_used": "GF7 Woonkamer", + "mode": "auto", + "sensors": {"temperature": 20.9, "setpoint": 21.5, "battery": 34}, + }, + "fe799307f1624099878210aa0b9f1475": { + "class": "gateway", + "fw": "3.0.15", + "location": "1f9dcf83fd4e4b66b72ff787957bfe5d", + "model": "Adam", + "name": "Adam", + "vendor": "Plugwise B.V.", + "binary_sensors": {"plugwise_notification": True}, + "sensors": {"outdoor_temperature": 7.81}, + }, + "d3da73bde12a47d5a6b8f9dad971f2ec": { + "class": "thermo_sensor", + "fw": "2019-03-27T01:00:00+01:00", + "location": "82fa13f017d240daa0d0ea1775420f24", + "model": "Tom/Floor", + "name": "Thermostatic Radiator Jessie", + "vendor": "Plugwise", + "sensors": { + "temperature": 17.1, + "setpoint": 15.0, + "battery": 62, + "temperature_difference": 0.1, + "valve_position": 0.0, + }, + }, + "21f2b542c49845e6bb416884c55778d6": { + "class": "game_console", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "Playstation Smart Plug", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 82.6, + "electricity_consumed_interval": 8.6, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": False}, + }, + "78d1126fc4c743db81b61c20e88342a7": { + "class": "central_heating_pump", + "fw": "2019-06-21T02:00:00+02:00", + "location": "c50f167537524366a5af7aa3942feb1e", + "model": "Plug", + "name": "CV Pomp", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 35.6, + "electricity_consumed_interval": 7.37, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True}, + }, + "90986d591dcd426cae3ec3e8111ff730": { + "class": "heater_central", + "fw": None, + "location": "1f9dcf83fd4e4b66b72ff787957bfe5d", + "model": "Unknown", + "name": "OnOff", + "vendor": None, + "cooling_active": False, + "heating_state": True, + "sensors": { + "water_temperature": 70.0, + "intended_boiler_temperature": 70.0, + "modulation_level": 1, + "device_state": "heating", + }, + }, + "cd0ddb54ef694e11ac18ed1cbce5dbbd": { + "class": "vcr", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "NAS", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 16.5, + "electricity_consumed_interval": 0.5, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": True}, + }, + "4a810418d5394b3f82727340b91ba740": { + "class": "router", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "USG Smart Plug", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 8.5, + "electricity_consumed_interval": 0.0, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": True}, + }, + "02cf28bfec924855854c544690a609ef": { + "class": "vcr", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "NVR", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 34.0, + "electricity_consumed_interval": 9.15, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": True}, + }, + "a28f588dc4a049a483fd03a30361ad3a": { + "class": "settop", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "Fibaro HC2", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 12.5, + "electricity_consumed_interval": 3.8, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": True}, + }, + "6a3bf693d05e48e0b460c815a4fdd09d": { + "class": "zone_thermostat", + "fw": "2016-10-27T02:00:00+02:00", + "location": "82fa13f017d240daa0d0ea1775420f24", + "model": "Lisa", + "name": "Zone Thermostat Jessie", + "vendor": "Plugwise", + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], + "active_preset": "asleep", + "presets": { + "home": [20.0, 22.0], + "asleep": [17.0, 24.0], + "away": [15.0, 25.0], + "vacation": [15.0, 28.0], + "no_frost": [10.0, 30.0], + }, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie", + ], + "selected_schedule": "CV Jessie", + "schedule_temperature": 15.0, + "last_used": "CV Jessie", + "mode": "auto", + "sensors": {"temperature": 17.2, "setpoint": 15.0, "battery": 37}, + }, + "680423ff840043738f42cc7f1ff97a36": { + "class": "thermo_sensor", + "fw": "2019-03-27T01:00:00+01:00", + "location": "08963fec7c53423ca5680aa4cb502c63", + "model": "Tom/Floor", + "name": "Thermostatic Radiator Badkamer", + "vendor": "Plugwise", + "sensors": { + "temperature": 19.1, + "setpoint": 14.0, + "battery": 51, + "temperature_difference": -0.4, + "valve_position": 0.0, + }, + }, + "f1fee6043d3642a9b0a65297455f008e": { + "class": "zone_thermostat", + "fw": "2016-10-27T02:00:00+02:00", + "location": "08963fec7c53423ca5680aa4cb502c63", + "model": "Lisa", + "name": "Zone Thermostat Badkamer", + "vendor": "Plugwise", + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], + "active_preset": "away", + "presets": { + "home": [20.0, 22.0], + "asleep": [17.0, 24.0], + "away": [15.0, 25.0], + "vacation": [15.0, 28.0], + "no_frost": [10.0, 30.0], + }, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie", + ], + "selected_schedule": "Badkamer Schema", + "schedule_temperature": 15.0, + "last_used": "Badkamer Schema", + "mode": "auto", + "sensors": {"temperature": 18.9, "setpoint": 14.0, "battery": 92}, + }, + "675416a629f343c495449970e2ca37b5": { + "class": "router", + "fw": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "Ziggo Modem", + "vendor": "Plugwise", + "sensors": { + "electricity_consumed": 12.2, + "electricity_consumed_interval": 2.97, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0, + }, + "switches": {"relay": True, "lock": True}, + }, + "e7693eb9582644e5b865dba8d4447cf1": { + "class": "thermostatic_radiator_valve", + "fw": "2019-03-27T01:00:00+01:00", + "location": "446ac08dd04d4eff8ac57489757b7314", + "model": "Tom/Floor", + "name": "CV Kraan Garage", + "vendor": "Plugwise", + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], + "active_preset": "no_frost", + "presets": { + "home": [20.0, 22.0], + "asleep": [17.0, 24.0], + "away": [15.0, 25.0], + "vacation": [15.0, 28.0], + "no_frost": [10.0, 30.0], + }, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie", + ], + "selected_schedule": "None", + "schedule_temperature": 15.0, + "last_used": "Badkamer Schema", + "mode": "heat", + "sensors": { + "temperature": 15.6, + "setpoint": 5.5, + "battery": 68, + "temperature_difference": 0.0, + "valve_position": 0.0, + }, + }, + }, + }