From 34deac1a61e63d4127374ca7919a6772c073ba74 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 23 May 2024 21:04:31 +0200 Subject: [PATCH] Add snapshot tests to omnilogic (#117986) --- tests/components/omnilogic/__init__.py | 37 +++ tests/components/omnilogic/const.py | 266 ++++++++++++++++++ .../omnilogic/snapshots/test_sensor.ambr | 101 +++++++ .../omnilogic/snapshots/test_switch.ambr | 93 ++++++ tests/components/omnilogic/test_sensor.py | 28 ++ tests/components/omnilogic/test_switch.py | 28 ++ 6 files changed, 553 insertions(+) create mode 100644 tests/components/omnilogic/const.py create mode 100644 tests/components/omnilogic/snapshots/test_sensor.ambr create mode 100644 tests/components/omnilogic/snapshots/test_switch.ambr create mode 100644 tests/components/omnilogic/test_sensor.py create mode 100644 tests/components/omnilogic/test_switch.py diff --git a/tests/components/omnilogic/__init__.py b/tests/components/omnilogic/__init__.py index b7b8008abaa..61fec0ce1a5 100644 --- a/tests/components/omnilogic/__init__.py +++ b/tests/components/omnilogic/__init__.py @@ -1 +1,38 @@ """Tests for the Omnilogic integration.""" + +from unittest.mock import patch + +from homeassistant.components.omnilogic.const import DOMAIN +from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.core import HomeAssistant + +from .const import TELEMETRY + +from tests.common import MockConfigEntry + + +async def init_integration(hass: HomeAssistant) -> MockConfigEntry: + """Mock integration setup.""" + with ( + patch( + "homeassistant.components.omnilogic.OmniLogic.connect", + return_value=True, + ), + patch( + "homeassistant.components.omnilogic.OmniLogic.get_telemetry_data", + return_value={}, + ), + patch( + "homeassistant.components.omnilogic.common.OmniLogicUpdateCoordinator._async_update_data", + return_value=TELEMETRY, + ), + ): + entry = MockConfigEntry( + domain=DOMAIN, + data={CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"}, + entry_id="6fa019921cf8e7a3f57a3c2ed001a10d", + ) + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + return entry diff --git a/tests/components/omnilogic/const.py b/tests/components/omnilogic/const.py new file mode 100644 index 00000000000..e434cfef00a --- /dev/null +++ b/tests/components/omnilogic/const.py @@ -0,0 +1,266 @@ +"""Constants for the Omnilogic integration tests.""" + +TELEMETRY = { + ("Backyard", "SCRUBBED"): { + "systemId": "SCRUBBED", + "statusVersion": "3", + "airTemp": "70", + "status": "1", + "state": "1", + "configUpdatedTime": "2020-10-08T09:04:42.0556413Z", + "datetime": "2020-10-11T16:36:53.4128627", + "Relays": [], + "BOWS": [ + { + "systemId": "1", + "flow": "255", + "waterTemp": "71", + "Name": "Spa", + "Supports-Spillover": "no", + "Filter": { + "systemId": "2", + "valvePosition": "1", + "filterSpeed": "100", + "filterState": "1", + "lastSpeed": "0", + "Name": "Filter Pump", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Filter-Type": "FMT_SINGLE_SPEED", + "Max-Pump-Speed": "100", + "Min-Pump-Speed": "100", + "Max-Pump-RPM": "3450", + "Min-Pump-RPM": "600", + "Priming-Enabled": "no", + "Alarms": [], + }, + "VirtualHeater": { + "systemId": "3", + "Current-Set-Point": "103", + "enable": "no", + }, + "Heater": { + "systemId": "4", + "heaterState": "0", + "enable": "yes", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Operation": { + "VirtualHeater": { + "System-Id": "4", + "Name": "Heater", + "Type": "PET_HEATER", + "Heater-Type": "HTR_GAS", + "Enabled": "yes", + "Priority": "HTR_PRIORITY_1", + "Run-For-Priority": "HTR_MAINTAINS_PRIORITY_FOR_AS_LONG_AS_VALID", + "Shared-Equipment-System-ID": "-1", + "Current-Set-Point": "103", + "Max-Water-Temp": "104", + "Min-Settable-Water-Temp": "65", + "Max-Settable-Water-Temp": "104", + "enable": "yes", + "systemId": "3", + } + }, + "Alarms": [], + }, + "Group": {"systemId": "13", "groupState": "0"}, + "Lights": [ + { + "systemId": "6", + "lightState": "0", + "currentShow": "0", + "Name": "Lights", + "Type": "COLOR_LOGIC_UCL", + "Alarms": [], + } + ], + "Relays": [ + { + "systemId": "10", + "relayState": "0", + "Name": "Overflow", + "Type": "RLY_VALVE_ACTUATOR", + "Function": "RLY_WATER_FEATURE", + "Alarms": [], + } + ], + "Pumps": [ + { + "systemId": "5", + "pumpState": "0", + "pumpSpeed": "0", + "lastSpeed": "0", + "Name": "Spa Jets", + "Type": "PMP_SINGLE_SPEED", + "Function": "PMP_WATER_FEATURE", + "Min-Pump-Speed": "18", + "Max-Pump-Speed": "100", + "Alarms": [], + } + ], + } + ], + "BackyardName": "SCRUBBED", + "Msp-Vsp-Speed-Format": "Percent", + "Msp-Time-Format": "12 Hour Format", + "Units": "Standard", + "Msp-Chlor-Display": "Salt", + "Msp-Language": "English", + "Unit-of-Measurement": "Standard", + "Alarms": [], + "Unit-of-Temperature": "UNITS_FAHRENHEIT", + }, + ("Backyard", "SCRUBBED", "BOWS", "1"): { + "systemId": "1", + "flow": "255", + "waterTemp": "71", + "Name": "Spa", + "Supports-Spillover": "no", + "Filter": { + "systemId": "2", + "valvePosition": "1", + "filterSpeed": "100", + "filterState": "1", + "lastSpeed": "0", + "Name": "Filter Pump", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Filter-Type": "FMT_SINGLE_SPEED", + "Max-Pump-Speed": "100", + "Min-Pump-Speed": "100", + "Max-Pump-RPM": "3450", + "Min-Pump-RPM": "600", + "Priming-Enabled": "no", + "Alarms": [], + }, + "VirtualHeater": {"systemId": "3", "Current-Set-Point": "103", "enable": "no"}, + "Heater": { + "systemId": "4", + "heaterState": "0", + "enable": "yes", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Operation": { + "VirtualHeater": { + "System-Id": "4", + "Name": "Heater", + "Type": "PET_HEATER", + "Heater-Type": "HTR_GAS", + "Enabled": "yes", + "Priority": "HTR_PRIORITY_1", + "Run-For-Priority": "HTR_MAINTAINS_PRIORITY_FOR_AS_LONG_AS_VALID", + "Shared-Equipment-System-ID": "-1", + "Current-Set-Point": "103", + "Max-Water-Temp": "104", + "Min-Settable-Water-Temp": "65", + "Max-Settable-Water-Temp": "104", + "enable": "yes", + "systemId": "3", + } + }, + "Alarms": [], + }, + "Group": {"systemId": "13", "groupState": "0"}, + "Lights": [ + { + "systemId": "6", + "lightState": "0", + "currentShow": "0", + "Name": "Lights", + "Type": "COLOR_LOGIC_UCL", + "Alarms": [], + } + ], + "Relays": [ + { + "systemId": "10", + "relayState": "0", + "Name": "Overflow", + "Type": "RLY_VALVE_ACTUATOR", + "Function": "RLY_WATER_FEATURE", + "Alarms": [], + } + ], + "Pumps": [ + { + "systemId": "5", + "pumpState": "0", + "pumpSpeed": "0", + "lastSpeed": "0", + "Name": "Spa Jets", + "Type": "PMP_SINGLE_SPEED", + "Function": "PMP_WATER_FEATURE", + "Min-Pump-Speed": "18", + "Max-Pump-Speed": "100", + "Alarms": [], + } + ], + }, + ("Backyard", "SCRUBBED", "BOWS", "1", "Pumps", "5"): { + "systemId": "5", + "pumpState": "0", + "pumpSpeed": "0", + "lastSpeed": "0", + "Name": "Spa Jets", + "Type": "PMP_SINGLE_SPEED", + "Function": "PMP_WATER_FEATURE", + "Min-Pump-Speed": "18", + "Max-Pump-Speed": "100", + "Alarms": [], + }, + ("Backyard", "SCRUBBED", "BOWS", "1", "Relays", "10"): { + "systemId": "10", + "relayState": "0", + "Name": "Overflow", + "Type": "RLY_VALVE_ACTUATOR", + "Function": "RLY_WATER_FEATURE", + "Alarms": [], + }, + ("Backyard", "SCRUBBED", "BOWS", "1", "Lights", "6"): { + "systemId": "6", + "lightState": "0", + "currentShow": "0", + "Name": "Lights", + "Type": "COLOR_LOGIC_UCL", + "Alarms": [], + }, + ("Backyard", "SCRUBBED", "BOWS", "1", "Heater", "4"): { + "systemId": "4", + "heaterState": "0", + "enable": "yes", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Operation": { + "VirtualHeater": { + "System-Id": "4", + "Name": "Heater", + "Type": "PET_HEATER", + "Heater-Type": "HTR_GAS", + "Enabled": "yes", + "Priority": "HTR_PRIORITY_1", + "Run-For-Priority": "HTR_MAINTAINS_PRIORITY_FOR_AS_LONG_AS_VALID", + "Shared-Equipment-System-ID": "-1", + "Current-Set-Point": "103", + "Max-Water-Temp": "104", + "Min-Settable-Water-Temp": "65", + "Max-Settable-Water-Temp": "104", + "enable": "yes", + "systemId": "3", + } + }, + "Alarms": [], + }, + ("Backyard", "SCRUBBED", "BOWS", "1", "Filter", "2"): { + "systemId": "2", + "valvePosition": "1", + "filterSpeed": "100", + "filterState": "1", + "lastSpeed": "0", + "Name": "Filter Pump", + "Shared-Type": "BOW_NO_EQUIPMENT_SHARED", + "Filter-Type": "FMT_SINGLE_SPEED", + "Max-Pump-Speed": "100", + "Min-Pump-Speed": "100", + "Max-Pump-RPM": "3450", + "Min-Pump-RPM": "600", + "Priming-Enabled": "no", + "Alarms": [], + }, +} diff --git a/tests/components/omnilogic/snapshots/test_sensor.ambr b/tests/components/omnilogic/snapshots/test_sensor.ambr new file mode 100644 index 00000000000..a4ea7f02a03 --- /dev/null +++ b/tests/components/omnilogic/snapshots/test_sensor.ambr @@ -0,0 +1,101 @@ +# serializer version: 1 +# name: test_sensors[sensor.scrubbed_air_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.scrubbed_air_temperature', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'SCRUBBED Air Temperature', + 'platform': 'omnilogic', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'SCRUBBED_SCRUBBED_air_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[sensor.scrubbed_air_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'SCRUBBED Air Temperature', + 'hayward_temperature': '70', + 'hayward_unit_of_measure': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.scrubbed_air_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '21', + }) +# --- +# name: test_sensors[sensor.scrubbed_spa_water_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.scrubbed_spa_water_temperature', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'SCRUBBED Spa Water Temperature', + 'platform': 'omnilogic', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'SCRUBBED_1_water_temperature', + 'unit_of_measurement': , + }) +# --- +# name: test_sensors[sensor.scrubbed_spa_water_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'SCRUBBED Spa Water Temperature', + 'hayward_temperature': '71', + 'hayward_unit_of_measure': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.scrubbed_spa_water_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '22', + }) +# --- diff --git a/tests/components/omnilogic/snapshots/test_switch.ambr b/tests/components/omnilogic/snapshots/test_switch.ambr new file mode 100644 index 00000000000..a5d77f1adcf --- /dev/null +++ b/tests/components/omnilogic/snapshots/test_switch.ambr @@ -0,0 +1,93 @@ +# serializer version: 1 +# name: test_switches[switch.scrubbed_spa_filter_pump-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.scrubbed_spa_filter_pump', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'SCRUBBED Spa Filter Pump ', + 'platform': 'omnilogic', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'SCRUBBED_1_2_pump', + 'unit_of_measurement': None, + }) +# --- +# name: test_switches[switch.scrubbed_spa_filter_pump-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'SCRUBBED Spa Filter Pump ', + }), + 'context': , + 'entity_id': 'switch.scrubbed_spa_filter_pump', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_switches[switch.scrubbed_spa_spa_jets-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.scrubbed_spa_spa_jets', + 'has_entity_name': False, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'SCRUBBED Spa Spa Jets ', + 'platform': 'omnilogic', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'SCRUBBED_1_5_pump', + 'unit_of_measurement': None, + }) +# --- +# name: test_switches[switch.scrubbed_spa_spa_jets-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'SCRUBBED Spa Spa Jets ', + }), + 'context': , + 'entity_id': 'switch.scrubbed_spa_spa_jets', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- diff --git a/tests/components/omnilogic/test_sensor.py b/tests/components/omnilogic/test_sensor.py new file mode 100644 index 00000000000..166eb7f87f2 --- /dev/null +++ b/tests/components/omnilogic/test_sensor.py @@ -0,0 +1,28 @@ +"""Tests for the omnilogic sensors.""" + +from unittest.mock import patch + +from syrupy import SnapshotAssertion + +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from . import init_integration + +from tests.common import snapshot_platform + + +async def test_sensors( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test sensors.""" + with patch( + "homeassistant.components.omnilogic.PLATFORMS", + [Platform.SENSOR], + ): + entry = await init_integration(hass) + + await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id) diff --git a/tests/components/omnilogic/test_switch.py b/tests/components/omnilogic/test_switch.py new file mode 100644 index 00000000000..1f9506380a2 --- /dev/null +++ b/tests/components/omnilogic/test_switch.py @@ -0,0 +1,28 @@ +"""Tests for the omnilogic switches.""" + +from unittest.mock import patch + +from syrupy import SnapshotAssertion + +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from . import init_integration + +from tests.common import snapshot_platform + + +async def test_switches( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test switches.""" + with patch( + "homeassistant.components.omnilogic.PLATFORMS", + [Platform.SWITCH], + ): + entry = await init_integration(hass) + + await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)