Add snapshot tests to omnilogic (#117986)

This commit is contained in:
epenet 2024-05-23 21:04:31 +02:00 committed by GitHub
parent bdc3bb57f3
commit 34deac1a61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 553 additions and 0 deletions

View file

@ -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

View file

@ -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": [],
},
}

View file

@ -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': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.scrubbed_air_temperature',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
'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': <UnitOfTemperature.CELSIUS: '°C'>,
})
# ---
# 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': <UnitOfTemperature.FAHRENHEIT: '°F'>,
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}),
'context': <ANY>,
'entity_id': 'sensor.scrubbed_air_temperature',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '21',
})
# ---
# name: test_sensors[sensor.scrubbed_spa_water_temperature-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
'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': <UnitOfTemperature.CELSIUS: '°C'>,
})
# ---
# 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': <UnitOfTemperature.FAHRENHEIT: '°F'>,
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}),
'context': <ANY>,
'entity_id': 'sensor.scrubbed_spa_water_temperature',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '22',
})
# ---

View file

@ -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': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'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': <ANY>,
'entity_id': 'switch.scrubbed_spa_filter_pump',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_switches[switch.scrubbed_spa_spa_jets-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'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': <ANY>,
'entity_id': 'switch.scrubbed_spa_spa_jets',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---

View file

@ -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)

View file

@ -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)