From a5dcc25aaba041b7f92b27f85a7cf59339ca0653 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 30 Aug 2023 17:11:55 +0200 Subject: [PATCH] Add snapshot assertion to Airzone (#98760) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Álvaro Fernández Rojas --- .../airzone/snapshots/test_diagnostics.ambr | 687 ++++++++++++++++++ tests/components/airzone/test_climate.py | 5 +- tests/components/airzone/test_diagnostics.py | 78 +- tests/components/airzone/test_sensor.py | 3 +- tests/components/airzone/util.py | 1 + 5 files changed, 700 insertions(+), 74 deletions(-) create mode 100644 tests/components/airzone/snapshots/test_diagnostics.ambr diff --git a/tests/components/airzone/snapshots/test_diagnostics.ambr b/tests/components/airzone/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..b9ab7198148 --- /dev/null +++ b/tests/components/airzone/snapshots/test_diagnostics.ambr @@ -0,0 +1,687 @@ +# serializer version: 1 +# name: test_config_entry_diagnostics + dict({ + 'api_data': dict({ + 'hvac': dict({ + 'systems': list([ + dict({ + 'data': list([ + dict({ + 'air_demand': 0, + 'coldStage': 1, + 'coldStages': 1, + 'coldangle': 0, + 'errors': list([ + ]), + 'floor_demand': 0, + 'heatStage': 1, + 'heatStages': 1, + 'heatangle': 0, + 'humidity': 34, + 'maxTemp': 30, + 'minTemp': 15, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Salon', + 'on': 0, + 'roomTemp': 19.6, + 'setpoint': 19.1, + 'sleep': 0, + 'speed': 0, + 'speeds': 3, + 'systemID': 1, + 'thermos_firmware': '3.51', + 'thermos_radio': 0, + 'thermos_type': 2, + 'units': 0, + 'zoneID': 1, + }), + dict({ + 'air_demand': 1, + 'coldStage': 1, + 'coldStages': 1, + 'coldangle': 2, + 'errors': list([ + ]), + 'floor_demand': 1, + 'heatStage': 3, + 'heatStages': 3, + 'heatangle': 1, + 'humidity': 39, + 'maxTemp': 30, + 'minTemp': 15, + 'mode': 3, + 'name': 'Dorm Ppal', + 'on': 1, + 'roomTemp': 21.1, + 'setpoint': 19.2, + 'sleep': 30, + 'speed': 0, + 'speeds': 2, + 'systemID': 1, + 'thermos_firmware': '3.33', + 'thermos_radio': 1, + 'thermos_type': 4, + 'units': 0, + 'zoneID': 2, + }), + dict({ + 'air_demand': 0, + 'coldStage': 1, + 'coldStages': 1, + 'coldangle': 0, + 'errors': list([ + ]), + 'floor_demand': 0, + 'heatStage': 2, + 'heatStages': 2, + 'heatangle': 0, + 'humidity': 35, + 'maxTemp': 30, + 'minTemp': 15, + 'mode': 3, + 'name': 'Dorm #1', + 'on': 1, + 'roomTemp': 20.8, + 'setpoint': 19.3, + 'sleep': 0, + 'systemID': 1, + 'thermos_firmware': '3.33', + 'thermos_radio': 1, + 'thermos_type': 4, + 'units': 0, + 'zoneID': 3, + }), + dict({ + 'air_demand': 0, + 'coldStage': 1, + 'coldStages': 1, + 'coldangle': 0, + 'errors': list([ + dict({ + 'Zone': 'Low battery', + }), + ]), + 'floor_demand': 0, + 'heatStage': 1, + 'heatStages': 1, + 'heatangle': 0, + 'humidity': 36, + 'maxTemp': 86, + 'minTemp': 59, + 'mode': 3, + 'name': 'Despacho', + 'on': 0, + 'roomTemp': 70.16, + 'setpoint': 66.92, + 'sleep': 0, + 'systemID': 1, + 'thermos_firmware': '3.33', + 'thermos_radio': 1, + 'thermos_type': 4, + 'units': 1, + 'zoneID': 4, + }), + dict({ + 'air_demand': 0, + 'coldStage': 1, + 'coldStages': 1, + 'coldangle': 0, + 'errors': list([ + ]), + 'floor_demand': 0, + 'heatStage': 1, + 'heatStages': 1, + 'heatangle': 0, + 'humidity': 40, + 'maxTemp': 30, + 'minTemp': 15, + 'mode': 3, + 'name': 'Dorm #2', + 'on': 0, + 'roomTemp': 20.5, + 'setpoint': 19.5, + 'sleep': 0, + 'systemID': 1, + 'thermos_firmware': '3.33', + 'thermos_radio': 1, + 'thermos_type': 4, + 'units': 0, + 'zoneID': 5, + }), + ]), + }), + dict({ + 'data': list([ + dict({ + 'coldStage': 1, + 'coldStages': 1, + 'errors': list([ + ]), + 'heatStage': 1, + 'heatStages': 1, + 'humidity': 62, + 'maxTemp': 30, + 'minTemp': 15, + 'on': 0, + 'roomTemp': 22.299999, + 'setpoint': 19, + 'speed': 0, + 'speeds': 4, + 'systemID': 2, + 'units': 0, + 'zoneID': 1, + }), + ]), + }), + dict({ + 'data': list([ + dict({ + 'air_demand': 1, + 'coldStage': 0, + 'coldStages': 0, + 'coolmaxtemp': 90, + 'coolmintemp': 64, + 'coolsetpoint': 73, + 'errors': list([ + ]), + 'floor_demand': 0, + 'heatStage': 0, + 'heatStages': 0, + 'heatmaxtemp': 86, + 'heatmintemp': 50, + 'heatsetpoint': 77, + 'humidity': 0, + 'maxTemp': 90, + 'minTemp': 64, + 'mode': 7, + 'modes': list([ + 4, + 2, + 3, + 5, + 7, + ]), + 'name': 'DKN Plus', + 'on': 1, + 'roomTemp': 71, + 'setpoint': 73, + 'speed': 2, + 'speeds': 5, + 'systemID': 3, + 'units': 1, + 'zoneID': 1, + }), + ]), + }), + ]), + }), + 'version': dict({ + 'version': '1.62', + }), + 'webserver': dict({ + 'mac': '**REDACTED**', + 'wifi_channel': 6, + 'wifi_rssi': -42, + }), + }), + 'config_entry': dict({ + 'data': dict({ + 'host': '192.168.1.100', + 'port': 3000, + }), + 'disabled_by': None, + 'domain': 'airzone', + 'entry_id': '6e7a0798c1734ba81d26ced0e690eaec', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Mock Title', + 'unique_id': '**REDACTED**', + 'version': 1, + }), + 'coord_data': dict({ + 'hot-water': dict({ + 'name': 'Airzone DHW', + 'on': True, + 'operation': 1, + 'operations': list([ + 0, + 1, + 2, + ]), + 'power-mode': False, + 'temp': 43, + 'temp-max': 75, + 'temp-min': 30, + 'temp-set': 45, + 'temp-unit': 0, + }), + 'new-systems': list([ + ]), + 'new-zones': list([ + ]), + 'num-systems': 3, + 'num-zones': 7, + 'systems': dict({ + '1': dict({ + 'available': True, + 'firmware': '3.31', + 'full-name': 'Airzone [1] System', + 'id': 1, + 'master-system-zone': '1:1', + 'master-zone': 1, + 'mode': 3, + 'model': 'C6', + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'problems': False, + }), + '2': dict({ + 'available': True, + 'full-name': 'Airzone [2] System', + 'id': 2, + 'master-system-zone': '2:1', + 'master-zone': 1, + 'mode': 7, + 'modes': list([ + 7, + 1, + ]), + 'problems': False, + }), + '3': dict({ + 'available': True, + 'full-name': 'Airzone [3] System', + 'id': 3, + 'master-system-zone': '3:1', + 'master-zone': 1, + 'mode': 7, + 'modes': list([ + 4, + 2, + 3, + 5, + 7, + 1, + ]), + 'problems': False, + }), + }), + 'version': '1.62', + 'webserver': dict({ + 'mac': '**REDACTED**', + 'wifi-channel': 6, + 'wifi-rssi': -42, + }), + 'zones': dict({ + '1:1': dict({ + 'absolute-temp-max': 30.0, + 'absolute-temp-min': 15.0, + 'action': 6, + 'air-demand': False, + 'available': True, + 'cold-angle': 0, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': False, + 'double-set-point': False, + 'full-name': 'Airzone [1:1] Salon', + 'heat-angle': 0, + 'heat-stage': 1, + 'heat-stages': list([ + 0, + 1, + ]), + 'humidity': 34, + 'id': 1, + 'master': True, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Salon', + 'on': False, + 'problems': False, + 'sleep': 0, + 'speed': 0, + 'speeds': list([ + 0, + 1, + 2, + 3, + ]), + 'system': 1, + 'temp': 19.6, + 'temp-max': 30.0, + 'temp-min': 15.0, + 'temp-set': 19.1, + 'temp-step': 0.5, + 'temp-unit': 0, + 'thermostat-fw': '3.51', + 'thermostat-model': 'Blueface Zero', + 'thermostat-radio': False, + }), + '1:2': dict({ + 'absolute-temp-max': 30.0, + 'absolute-temp-min': 15.0, + 'action': 4, + 'air-demand': True, + 'available': True, + 'battery-low': False, + 'cold-angle': 2, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': True, + 'double-set-point': False, + 'floor-demand': True, + 'full-name': 'Airzone [1:2] Dorm Ppal', + 'heat-angle': 1, + 'heat-stage': 3, + 'heat-stages': list([ + 0, + 1, + 2, + 3, + ]), + 'humidity': 39, + 'id': 2, + 'master': False, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Dorm Ppal', + 'on': True, + 'problems': False, + 'sleep': 30, + 'speed': 0, + 'speeds': list([ + 0, + 1, + 2, + ]), + 'system': 1, + 'temp': 21.1, + 'temp-max': 30.0, + 'temp-min': 15.0, + 'temp-set': 19.2, + 'temp-step': 0.5, + 'temp-unit': 0, + 'thermostat-fw': '3.33', + 'thermostat-model': 'Think (Radio)', + 'thermostat-radio': True, + }), + '1:3': dict({ + 'absolute-temp-max': 30.0, + 'absolute-temp-min': 15.0, + 'action': 5, + 'air-demand': False, + 'available': True, + 'battery-low': False, + 'cold-angle': 0, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': False, + 'double-set-point': False, + 'floor-demand': False, + 'full-name': 'Airzone [1:3] Dorm #1', + 'heat-angle': 0, + 'heat-stage': 2, + 'heat-stages': list([ + 0, + 2, + ]), + 'humidity': 35, + 'id': 3, + 'master': False, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Dorm #1', + 'on': True, + 'problems': False, + 'sleep': 0, + 'system': 1, + 'temp': 20.8, + 'temp-max': 30.0, + 'temp-min': 15.0, + 'temp-set': 19.3, + 'temp-step': 0.5, + 'temp-unit': 0, + 'thermostat-fw': '3.33', + 'thermostat-model': 'Think (Radio)', + 'thermostat-radio': True, + }), + '1:4': dict({ + 'absolute-temp-max': 86.0, + 'absolute-temp-min': 59.0, + 'action': 6, + 'air-demand': False, + 'available': True, + 'battery-low': True, + 'cold-angle': 0, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': False, + 'double-set-point': False, + 'errors': list([ + 'Low battery', + ]), + 'full-name': 'Airzone [1:4] Despacho', + 'heat-angle': 0, + 'heat-stage': 1, + 'heat-stages': list([ + 0, + 1, + ]), + 'humidity': 36, + 'id': 4, + 'master': False, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Despacho', + 'on': False, + 'problems': True, + 'sleep': 0, + 'system': 1, + 'temp': 70.16, + 'temp-max': 86.0, + 'temp-min': 59.0, + 'temp-set': 66.9, + 'temp-step': 1.0, + 'temp-unit': 1, + 'thermostat-fw': '3.33', + 'thermostat-model': 'Think (Radio)', + 'thermostat-radio': True, + }), + '1:5': dict({ + 'absolute-temp-max': 30.0, + 'absolute-temp-min': 15.0, + 'action': 6, + 'air-demand': False, + 'available': True, + 'battery-low': False, + 'cold-angle': 0, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': False, + 'double-set-point': False, + 'full-name': 'Airzone [1:5] Dorm #2', + 'heat-angle': 0, + 'heat-stage': 1, + 'heat-stages': list([ + 0, + 1, + ]), + 'humidity': 40, + 'id': 5, + 'master': False, + 'mode': 3, + 'modes': list([ + 1, + 4, + 2, + 3, + 5, + ]), + 'name': 'Dorm #2', + 'on': False, + 'problems': False, + 'sleep': 0, + 'system': 1, + 'temp': 20.5, + 'temp-max': 30.0, + 'temp-min': 15.0, + 'temp-set': 19.5, + 'temp-step': 0.5, + 'temp-unit': 0, + 'thermostat-fw': '3.33', + 'thermostat-model': 'Think (Radio)', + 'thermostat-radio': True, + }), + '2:1': dict({ + 'absolute-temp-max': 30.0, + 'absolute-temp-min': 15.0, + 'action': 6, + 'available': True, + 'cold-stage': 1, + 'cold-stages': list([ + 0, + 1, + ]), + 'demand': False, + 'double-set-point': True, + 'full-name': 'Airzone [2:1] Airzone 2:1', + 'heat-stage': 1, + 'heat-stages': list([ + 0, + 1, + ]), + 'humidity': 62, + 'id': 1, + 'master': True, + 'mode': 7, + 'modes': list([ + 7, + 1, + ]), + 'name': 'Airzone 2:1', + 'on': False, + 'problems': False, + 'speed': 0, + 'speeds': list([ + 0, + 1, + 2, + 3, + 4, + ]), + 'system': 2, + 'temp': 22.3, + 'temp-max': 30.0, + 'temp-min': 15.0, + 'temp-set': 19.0, + 'temp-step': 0.5, + 'temp-unit': 0, + }), + '3:1': dict({ + 'absolute-temp-max': 90.0, + 'absolute-temp-min': 50.0, + 'action': 1, + 'air-demand': True, + 'available': True, + 'cold-stage': 0, + 'cool-temp-max': 90.0, + 'cool-temp-min': 64.0, + 'cool-temp-set': 73.0, + 'demand': True, + 'double-set-point': True, + 'floor-demand': False, + 'full-name': 'Airzone [3:1] DKN Plus', + 'heat-stage': 0, + 'heat-temp-max': 86.0, + 'heat-temp-min': 50.0, + 'heat-temp-set': 77.0, + 'id': 1, + 'master': True, + 'mode': 7, + 'modes': list([ + 4, + 2, + 3, + 5, + 7, + 1, + ]), + 'name': 'DKN Plus', + 'on': True, + 'problems': False, + 'speed': 2, + 'speeds': list([ + 0, + 1, + 2, + 3, + 4, + 5, + ]), + 'system': 3, + 'temp': 71.0, + 'temp-max': 90.0, + 'temp-min': 64.0, + 'temp-set': 73.0, + 'temp-step': 1.0, + 'temp-unit': 1, + }), + }), + }), + }) +# --- diff --git a/tests/components/airzone/test_climate.py b/tests/components/airzone/test_climate.py index 1f8667d0344..591584da10b 100644 --- a/tests/components/airzone/test_climate.py +++ b/tests/components/airzone/test_climate.py @@ -1,4 +1,5 @@ """The climate tests for the Airzone platform.""" +import copy from unittest.mock import patch from aioairzone.const import ( @@ -222,7 +223,7 @@ async def test_airzone_create_climates(hass: HomeAssistant) -> None: assert state.attributes.get(ATTR_TARGET_TEMP_STEP) == API_TEMPERATURE_STEP assert state.attributes.get(ATTR_TEMPERATURE) == 22.8 - HVAC_MOCK_CHANGED = {**HVAC_MOCK} + HVAC_MOCK_CHANGED = copy.deepcopy(HVAC_MOCK) HVAC_MOCK_CHANGED[API_SYSTEMS][0][API_DATA][0][API_MAX_TEMP] = 25 HVAC_MOCK_CHANGED[API_SYSTEMS][0][API_DATA][0][API_MIN_TEMP] = 10 @@ -437,7 +438,7 @@ async def test_airzone_climate_set_hvac_mode(hass: HomeAssistant) -> None: state = hass.states.get("climate.salon") assert state.state == HVACMode.FAN_ONLY - HVAC_MOCK_NO_SET_POINT = {**HVAC_MOCK} + HVAC_MOCK_NO_SET_POINT = copy.deepcopy(HVAC_MOCK) del HVAC_MOCK_NO_SET_POINT[API_SYSTEMS][0][API_DATA][0][API_SET_POINT] with patch( diff --git a/tests/components/airzone/test_diagnostics.py b/tests/components/airzone/test_diagnostics.py index 33f0175bdb7..b64f346f27e 100644 --- a/tests/components/airzone/test_diagnostics.py +++ b/tests/components/airzone/test_diagnostics.py @@ -2,30 +2,13 @@ from unittest.mock import patch -from aioairzone.const import ( - API_DATA, - API_MAC, - API_SYSTEM_ID, - API_SYSTEMS, - API_VERSION, - API_WIFI_RSSI, - AZD_ID, - AZD_MASTER, - AZD_SYSTEM, - AZD_SYSTEMS, - AZD_ZONES, - RAW_HVAC, - RAW_VERSION, - RAW_WEBSERVER, -) +from aioairzone.const import RAW_HVAC, RAW_VERSION, RAW_WEBSERVER +from syrupy import SnapshotAssertion from homeassistant.components.airzone.const import DOMAIN -from homeassistant.components.diagnostics import REDACTED -from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.core import HomeAssistant from .util import ( - CONFIG, HVAC_MOCK, HVAC_VERSION_MOCK, HVAC_WEBSERVER_MOCK, @@ -37,7 +20,9 @@ from tests.typing import ClientSessionGenerator async def test_config_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" await async_init_integration(hass) @@ -52,54 +37,5 @@ async def test_config_entry_diagnostics( RAW_WEBSERVER: HVAC_WEBSERVER_MOCK, }, ): - diag = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) - - assert ( - diag["api_data"][RAW_HVAC][API_SYSTEMS][0][API_DATA][0].items() - >= { - API_SYSTEM_ID: HVAC_MOCK[API_SYSTEMS][0][API_DATA][0][API_SYSTEM_ID], - }.items() - ) - - assert ( - diag["api_data"][RAW_VERSION].items() - >= { - API_VERSION: HVAC_VERSION_MOCK[API_VERSION], - }.items() - ) - - assert ( - diag["api_data"][RAW_WEBSERVER].items() - >= { - API_MAC: REDACTED, - API_WIFI_RSSI: HVAC_WEBSERVER_MOCK[API_WIFI_RSSI], - }.items() - ) - - assert ( - diag["config_entry"].items() - >= { - "data": { - CONF_HOST: CONFIG[CONF_HOST], - CONF_PORT: CONFIG[CONF_PORT], - }, - "domain": DOMAIN, - "unique_id": REDACTED, - }.items() - ) - - assert ( - diag["coord_data"][AZD_SYSTEMS]["1"].items() - >= { - AZD_ID: 1, - }.items() - ) - - assert ( - diag["coord_data"][AZD_ZONES]["1:1"].items() - >= { - AZD_ID: 1, - AZD_MASTER: True, - AZD_SYSTEM: 1, - }.items() - ) + result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + assert result == snapshot diff --git a/tests/components/airzone/test_sensor.py b/tests/components/airzone/test_sensor.py index 4de1cae7555..6d94defa004 100644 --- a/tests/components/airzone/test_sensor.py +++ b/tests/components/airzone/test_sensor.py @@ -1,5 +1,6 @@ """The sensor tests for the Airzone platform.""" +import copy from unittest.mock import patch from aioairzone.const import API_DATA, API_SYSTEMS @@ -87,7 +88,7 @@ async def test_airzone_sensors_availability( await async_init_integration(hass) - HVAC_MOCK_UNAVAILABLE_ZONE = {**HVAC_MOCK} + HVAC_MOCK_UNAVAILABLE_ZONE = copy.deepcopy(HVAC_MOCK) del HVAC_MOCK_UNAVAILABLE_ZONE[API_SYSTEMS][0][API_DATA][1] with patch( diff --git a/tests/components/airzone/util.py b/tests/components/airzone/util.py index 74cda7c8017..eb687731eb7 100644 --- a/tests/components/airzone/util.py +++ b/tests/components/airzone/util.py @@ -313,6 +313,7 @@ async def async_init_integration( config_entry = MockConfigEntry( data=CONFIG, + entry_id="6e7a0798c1734ba81d26ced0e690eaec", domain=DOMAIN, unique_id="airzone_unique_id", )