diff --git a/tests/components/yardian/snapshots/test_switch.ambr b/tests/components/yardian/snapshots/test_switch.ambr new file mode 100644 index 00000000000..585dcc6cfef --- /dev/null +++ b/tests/components/yardian/snapshots/test_switch.ambr @@ -0,0 +1,97 @@ +# serializer version: 1 +# name: test_all_entities[switch.yardian_smart_sprinkler_zone_1-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.yardian_smart_sprinkler_zone_1', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Zone 1', + 'platform': 'yardian', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'switch', + 'unique_id': 'yid123-0', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[switch.yardian_smart_sprinkler_zone_1-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Yardian Smart Sprinkler Zone 1', + }), + 'context': , + 'entity_id': 'switch.yardian_smart_sprinkler_zone_1', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_all_entities[switch.yardian_smart_sprinkler_zone_2-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.yardian_smart_sprinkler_zone_2', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Zone 2', + 'platform': 'yardian', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'switch', + 'unique_id': 'yid123-1', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[switch.yardian_smart_sprinkler_zone_2-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Yardian Smart Sprinkler Zone 2', + }), + 'context': , + 'entity_id': 'switch.yardian_smart_sprinkler_zone_2', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unavailable', + }) +# --- diff --git a/tests/components/yardian/test_switch.py b/tests/components/yardian/test_switch.py new file mode 100644 index 00000000000..eb648eae007 --- /dev/null +++ b/tests/components/yardian/test_switch.py @@ -0,0 +1,73 @@ +"""Validate Yardian switch behavior.""" + +from __future__ import annotations + +from unittest.mock import AsyncMock, patch + +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN +from homeassistant.const import ( + ATTR_ENTITY_ID, + SERVICE_TURN_OFF, + SERVICE_TURN_ON, + Platform, +) +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from . import setup_integration + +from tests.common import MockConfigEntry, snapshot_platform + + +async def test_all_entities( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + mock_yardian_client: AsyncMock, + mock_config_entry: MockConfigEntry, + entity_registry: er.EntityRegistry, +) -> None: + """Test all entities.""" + with patch("homeassistant.components.yardian.PLATFORMS", [Platform.SWITCH]): + await setup_integration(hass, mock_config_entry) + + await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) + + +async def test_turn_on_switch( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + mock_yardian_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test turning on a switch.""" + await setup_integration(hass, mock_config_entry) + + entity_id = "switch.yardian_smart_sprinkler_zone_1" + await hass.services.async_call( + SWITCH_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: entity_id}, + blocking=True, + ) + mock_yardian_client.start_irrigation.assert_called_once_with(0, 6) + + +async def test_turn_off_switch( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + mock_yardian_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test turning off a switch.""" + await setup_integration(hass, mock_config_entry) + + entity_id = "switch.yardian_smart_sprinkler_zone_1" + await hass.services.async_call( + SWITCH_DOMAIN, + SERVICE_TURN_OFF, + {ATTR_ENTITY_ID: entity_id}, + blocking=True, + ) + mock_yardian_client.stop_irrigation.assert_called_once()