Add snapshot tests for setup of LetPot platforms (#137756)

This commit is contained in:
Joris Pelgröm 2025-02-08 13:42:43 +01:00 committed by GitHub
parent 1c7bf9f589
commit fae2c94c74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 345 additions and 14 deletions

View File

@ -2,7 +2,12 @@
import datetime
from letpot.models import AuthenticationInfo, LetPotDeviceErrors, LetPotDeviceStatus
from letpot.models import (
AuthenticationInfo,
LetPotDeviceErrors,
LetPotDeviceStatus,
TemperatureUnit,
)
from homeassistant.core import HomeAssistant
@ -26,17 +31,21 @@ AUTHENTICATION = AuthenticationInfo(
)
STATUS = LetPotDeviceStatus(
errors=LetPotDeviceErrors(low_water=False),
errors=LetPotDeviceErrors(low_water=True, low_nutrients=False, refill_error=False),
light_brightness=500,
light_mode=1,
light_schedule_end=datetime.time(12, 10),
light_schedule_start=datetime.time(12, 0),
light_schedule_end=datetime.time(18, 0),
light_schedule_start=datetime.time(8, 0),
online=True,
plant_days=1,
pump_mode=1,
pump_nutrient=None,
pump_status=0,
raw=[77, 0, 1, 18, 98, 1, 0, 0, 1, 1, 1, 0, 1, 12, 0, 12, 10, 1, 244, 0, 0, 0],
raw=[], # Not used by integration, and it requires a real device to get
system_on=True,
system_sound=False,
temperature_unit=TemperatureUnit.CELSIUS,
temperature_value=18,
water_mode=1,
water_level=100,
)

View File

@ -3,7 +3,7 @@
from collections.abc import Callable, Generator
from unittest.mock import AsyncMock, patch
from letpot.models import LetPotDevice
from letpot.models import DeviceFeature, LetPotDevice
import pytest
from homeassistant.components.letpot.const import (
@ -47,9 +47,9 @@ def mock_client() -> Generator[AsyncMock]:
client.refresh_token.return_value = AUTHENTICATION
client.get_devices.return_value = [
LetPotDevice(
serial_number="LPH21ABCD",
serial_number="LPH63ABCD",
name="Garden",
device_type="LPH21",
device_type="LPH63",
is_online=True,
is_remote=False,
)
@ -65,8 +65,16 @@ def mock_device_client() -> Generator[AsyncMock]:
autospec=True,
) as mock_device_client:
device_client = mock_device_client.return_value
device_client.device_model_code = "LPH21"
device_client.device_model_name = "LetPot Air"
device_client.device_features = (
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
| DeviceFeature.NUTRIENT_BUTTON
| DeviceFeature.PUMP_AUTO
| DeviceFeature.PUMP_STATUS
| DeviceFeature.TEMPERATURE
| DeviceFeature.WATER_LEVEL
)
device_client.device_model_code = "LPH63"
device_client.device_model_name = "LetPot Max"
subscribe_callbacks: list[Callable] = []

View File

@ -0,0 +1,185 @@
# serializer version: 1
# name: test_all_entities[switch.garden_alarm_sound-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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.garden_alarm_sound',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Alarm sound',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'alarm_sound',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_alarm_sound',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[switch.garden_alarm_sound-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Alarm sound',
}),
'context': <ANY>,
'entity_id': 'switch.garden_alarm_sound',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[switch.garden_auto_mode-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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.garden_auto_mode',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Auto mode',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'auto_mode',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_auto_mode',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[switch.garden_auto_mode-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Auto mode',
}),
'context': <ANY>,
'entity_id': 'switch.garden_auto_mode',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_all_entities[switch.garden_power-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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.garden_power',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Power',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_power',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[switch.garden_power-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Power',
}),
'context': <ANY>,
'entity_id': 'switch.garden_power',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_all_entities[switch.garden_pump_cycling-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': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'switch.garden_pump_cycling',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Pump cycling',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'pump_cycling',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_pump_cycling',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[switch.garden_pump_cycling-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Pump cycling',
}),
'context': <ANY>,
'entity_id': 'switch.garden_pump_cycling',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -0,0 +1,93 @@
# serializer version: 1
# name: test_all_entities[time.garden_light_off-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'time',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'time.garden_light_off',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Light off',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'light_schedule_end',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_light_schedule_end',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[time.garden_light_off-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Light off',
}),
'context': <ANY>,
'entity_id': 'time.garden_light_off',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '18:00:00',
})
# ---
# name: test_all_entities[time.garden_light_on-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'time',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'time.garden_light_on',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Light on',
'platform': 'letpot',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'light_schedule_start',
'unique_id': 'a1b2c3d4e5f6a1b2c3d4e5f6_LPH63ABCD_light_schedule_start',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[time.garden_light_on-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Garden Light on',
}),
'context': <ANY>,
'entity_id': 'time.garden_light_on',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '08:00:00',
})
# ---

View File

@ -1,17 +1,35 @@
"""Test switch entities for the LetPot integration."""
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from letpot.exceptions import LetPotConnectionException, LetPotException
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from . import setup_integration
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, snapshot_platform
async def test_all_entities(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_client: MagicMock,
mock_device_client: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test switch entities."""
with patch("homeassistant.components.letpot.PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize(

View File

@ -1,18 +1,36 @@
"""Test time entities for the LetPot integration."""
from datetime import time
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from letpot.exceptions import LetPotConnectionException, LetPotException
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.time import SERVICE_SET_VALUE
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
from . import setup_integration
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, snapshot_platform
async def test_all_entities(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_client: MagicMock,
mock_device_client: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test time entities."""
with patch("homeassistant.components.letpot.PLATFORMS", [Platform.TIME]):
await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize(