diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index be8dd322426c..e43caf3c0be3 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -32,6 +32,7 @@ from homematicip.device import ( TiltVibrationSensor, WallMountedThermostatPro, WaterSensor, + WaterSupplyStop, WeatherSensor, WeatherSensorPlus, WeatherSensorPro, @@ -230,6 +231,20 @@ WALL_THERMOSTAT_DESCRIPTIONS: tuple[ ), ) +WATER_SUPPLY_STOP_DESCRIPTIONS: tuple[ + HmipBinarySensorDescription[WaterSupplyStop], + ..., +] = ( + HmipBinarySensorDescription( + key="water_alarm", + translation_key="water_alarm", + device_class=BinarySensorDeviceClass.SAFETY, + channel_value_fn=lambda channel: channel.waterAlarmActive, + channel=1, + channel_type=FunctionalChannelType.WATER_SUPPLY_STOP_CHANNEL, + ), +) + BATTERY_SENSOR_DESCRIPTION = HmipBinarySensorDescription[Device]( key="battery", device_class=BinarySensorDeviceClass.BATTERY, @@ -252,6 +267,7 @@ SIMPLE_BINARY_SENSOR_DESCRIPTIONS: dict[ (RainSensor, WeatherSensorPlus, WeatherSensorPro): RAIN_SENSOR_DESCRIPTIONS, (PluggableMainsFailureSurveillance,): MAINS_FAILURE_SENSOR_DESCRIPTIONS, (WallMountedThermostatPro,): WALL_THERMOSTAT_DESCRIPTIONS, + (WaterSupplyStop,): WATER_SUPPLY_STOP_DESCRIPTIONS, } diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index 635645e0d4f1..9ee6fa006312 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -38,6 +38,7 @@ from homematicip.device import ( TiltVibrationSensor, UltrasonicDistanceSensor, WateringActuator, + WaterSupplyStop, WeatherSensor, WeatherSensorPlus, WeatherSensorPro, @@ -448,6 +449,19 @@ HEIGHT_DESC = HmipSensorDescription[Device]( ) +WATER_FLOW_DESC = HmipSensorDescription[Device]( + key="water_flow", + translation_key="water_flow", + device_class=SensorDeviceClass.VOLUME_FLOW_RATE, + native_unit_of_measurement=UnitOfVolumeFlowRate.LITERS_PER_MINUTE, + state_class=SensorStateClass.MEASUREMENT, + suggested_display_precision=1, + channel_value_fn=lambda channel: channel.waterFlow, + channel=1, + channel_type=FunctionalChannelType.WATER_SUPPLY_STOP_CHANNEL, +) + + # Keys must not subclass each other so each device matches one key; the setup # loop breaks after the first match (enforced by # test_simple_sensor_descriptions_no_overlap). @@ -488,6 +502,7 @@ SENSOR_DESCRIPTIONS_BY_DEVICE: dict[ ), TiltVibrationSensor: (TILT_ANGLE_DESC, TILT_TEMPERATURE_DESC), UltrasonicDistanceSensor: (DISTANCE_DESC, HEIGHT_DESC), + WaterSupplyStop: (WATER_FLOW_DESC,), WeatherSensor: ( TEMPERATURE_DESC, HUMIDITY_DESC, diff --git a/homeassistant/components/homematicip_cloud/strings.json b/homeassistant/components/homematicip_cloud/strings.json index af09dc11e520..affde32111c8 100644 --- a/homeassistant/components/homematicip_cloud/strings.json +++ b/homeassistant/components/homematicip_cloud/strings.json @@ -48,6 +48,9 @@ }, "raining": { "name": "Raining" + }, + "water_alarm": { + "name": "Water alarm" } }, "event": { @@ -125,6 +128,9 @@ "today_rain": { "name": "Today rain" }, + "water_flow": { + "name": "Water flow" + }, "window_state": { "name": "Window state", "state": { diff --git a/homeassistant/components/homematicip_cloud/valve.py b/homeassistant/components/homematicip_cloud/valve.py index e70272f916c3..5d41932fdef5 100644 --- a/homeassistant/components/homematicip_cloud/valve.py +++ b/homeassistant/components/homematicip_cloud/valve.py @@ -2,6 +2,7 @@ from typing import override +from homematicip.base.enums import WaterSupplyState from homematicip.base.functionalChannels import FunctionalChannelType from homematicip.device import Device @@ -24,12 +25,18 @@ async def async_setup_entry( ) -> None: """Set up the HomematicIP valves from a config entry.""" hap = config_entry.runtime_data - entities = [ + entities: list[ValveEntity] = [ HomematicipWateringValve(hap, device, ch.index) for device in hap.home.devices for ch in device.functionalChannels if ch.functionalChannelType == FunctionalChannelType.WATERING_ACTUATOR_CHANNEL ] + entities.extend( + HomematicipWaterSupplyValve(hap, device, ch.index) + for device in hap.home.devices + for ch in device.functionalChannels + if ch.functionalChannelType == FunctionalChannelType.WATER_SUPPLY_STOP_CHANNEL + ) async_add_entities(entities) @@ -70,3 +77,42 @@ class HomematicipWateringValve(HomematicipGenericEntity, ValveEntity): """Return if the valve is closed.""" channel = self.get_channel_or_raise() return channel.wateringActive is False + + +class HomematicipWaterSupplyValve(HomematicipGenericEntity, ValveEntity): + """Representation of a HomematicIP water supply stop valve.""" + + _attr_reports_position = False + _attr_supported_features = ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE + _attr_device_class = ValveDeviceClass.WATER + + def __init__(self, hap: HomematicipHAP, device: Device, channel: int) -> None: + """Initialize the valve.""" + super().__init__( + hap, + device=device, + channel=channel, + channel_real_index=channel, + feature_id="water_supply", + ) + + @override + async def async_open_valve(self) -> None: + """Open the valve.""" + channel = self.get_channel_or_raise() + await channel.set_water_supply_state_async(WaterSupplyState.FULL_OPENED) + + @override + async def async_close_valve(self) -> None: + """Close the valve.""" + channel = self.get_channel_or_raise() + await channel.set_water_supply_state_async(WaterSupplyState.NO_WATERFLOW) + + @property + @override + def is_closed(self) -> bool | None: + """Return if the valve is closed.""" + state = self.get_channel_or_raise().waterSupplyState + if state in (None, WaterSupplyState.UNKNOWN): + return None + return state == WaterSupplyState.NO_WATERFLOW diff --git a/tests/components/homematicip_cloud/fixtures/homematicip_cloud.json b/tests/components/homematicip_cloud/fixtures/homematicip_cloud.json index d7675c9cc262..6c9327495598 100644 --- a/tests/components/homematicip_cloud/fixtures/homematicip_cloud.json +++ b/tests/components/homematicip_cloud/fixtures/homematicip_cloud.json @@ -9890,6 +9890,95 @@ "type": "ULTRASONIC_DISTANCE_SENSOR", "updateState": "UP_TO_DATE" }, + "3014F7110000000000000WSS": { + "availableFirmwareVersion": "0.0.0", + "connectionType": "HMIP_RF", + "deviceArchetype": "HMIP", + "firmwareVersion": "1.0.14", + "firmwareVersionInteger": 65550, + "functionalChannels": { + "0": { + "coProFaulty": false, + "coProRestartNeeded": false, + "coProUpdateFailure": false, + "configPending": false, + "deviceCanBusError": false, + "deviceId": "3014F7110000000000000WSS", + "deviceOverheated": false, + "deviceOverloaded": false, + "deviceUndervoltage": false, + "dutyCycle": false, + "functionalChannelType": "DEVICE_OPERATIONLOCK", + "groupIndex": 0, + "groups": [], + "index": 0, + "label": "", + "lowBat": false, + "operationLockActive": false, + "routerModuleEnabled": false, + "routerModuleSupported": false, + "rssiDeviceValue": -45, + "rssiPeerValue": -54, + "supportedOptionalFeatures": { + "IFeatureDevicePowerFailure": true, + "IFeatureRssiValue": true, + "IOptionalFeatureDeviceCanBusError": true, + "IOptionalFeatureDeviceValveError": true, + "IOptionalFeatureDutyCycle": true, + "IOptionalFeatureLowBat": true, + "IOptionalFeatureNotRechargeableBattery": true + }, + "temperatureOutOfRange": false, + "unreach": false, + "valveFlowError": false, + "valveWaterError": null + }, + "1": { + "canbusSensorUsages": ["WATER_FLOW"], + "channelRole": "WATER_SUPPLY", + "deviceId": "3014F7110000000000000WSS", + "externalSensorMode": "INACTIVE", + "flushReminderInterval": 0, + "functionalChannelType": "WATER_SUPPLY_STOP_CHANNEL", + "groupIndex": 1, + "groups": [], + "index": 1, + "label": "", + "lastFlushReminderTimestamp": 1785676204873, + "lastFlushTimestamp": 1785676204873, + "processing": false, + "vacationEndTime": null, + "vacationStartTime": null, + "waterAlarmActive": false, + "waterAlarmGroupId": "00000000-0000-0000-0000-0000000000WA", + "waterFlow": 0, + "waterFlowDurationExceeded": false, + "waterFlowErrorDuration": 60, + "waterFlowErrorDurationAction": "NOTIFICATION_AND_CLOSE_VALVE", + "waterFlowErrorThreshold": 37, + "waterFlowErrorThresholdAction": "NOTIFICATION_AND_CLOSE_VALVE", + "waterFlowThresholdExceeded": true, + "waterPressure": null, + "waterSupplyState": "FULL_OPENED", + "waterSupplyVacationModeActive": false + } + }, + "homeId": "00000000-0000-0000-0000-000000000001", + "id": "3014F7110000000000000WSS", + "label": "Wasserstopp", + "lastStatusUpdate": 1790082161197, + "liveUpdateState": "LIVE_UPDATE_NOT_SUPPORTED", + "manuallyUpdateForced": false, + "manufacturerCode": 11, + "measuredAttributes": {}, + "modelId": 609, + "modelType": "HmIP-WSS-GB", + "oem": "eQ-3", + "permanentlyReachable": true, + "serializedGlobalTradeItemNumber": "3014F7110000000000000WSS", + "type": "WATER_SUPPLY_STOP", + "updateState": "UP_TO_DATE" + }, "3014F71100000000000DRBL4": { "availableFirmwareVersion": "1.8.2", "connectionType": "HMIP_WIRED", diff --git a/tests/components/homematicip_cloud/snapshots/test_binary_sensor.ambr b/tests/components/homematicip_cloud/snapshots/test_binary_sensor.ambr index 56c1401ab144..67ddde86307b 100644 --- a/tests/components/homematicip_cloud/snapshots/test_binary_sensor.ambr +++ b/tests/components/homematicip_cloud/snapshots/test_binary_sensor.ambr @@ -214,3 +214,164 @@ 'state': 'on', }) # --- +# name: test_hmip_water_alarm_sensor[binary_sensor.home_cloud_connection-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.home_cloud_connection', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Cloud connection', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': 'mdi:access-point-network', + 'original_name': 'Cloud connection', + 'platform': 'homematicip_cloud', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'cloud_connection', + 'unique_id': '00000000-0000-0000-0000-000000000001_cloud_connection', + 'unit_of_measurement': None, + }) +# --- +# name: test_hmip_water_alarm_sensor[binary_sensor.home_cloud_connection-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'Home Cloud connection', + : 'mdi:access-point-network', + }), + 'context': , + 'entity_id': 'binary_sensor.home_cloud_connection', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_hmip_water_alarm_sensor[binary_sensor.wasserstopp_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.wasserstopp_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery', + 'platform': 'homematicip_cloud', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '3014F7110000000000000WSS_0_battery', + 'unit_of_measurement': None, + }) +# --- +# name: test_hmip_water_alarm_sensor[binary_sensor.wasserstopp_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'connection_type': , + : 'battery', + : 'Wasserstopp Battery', + 'id': '3014F7110000000000000WSS', + 'is_group': False, + 'model_type': 'HmIP-WSS-GB', + }), + 'context': , + 'entity_id': 'binary_sensor.wasserstopp_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_hmip_water_alarm_sensor[binary_sensor.wasserstopp_water_alarm-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.wasserstopp_water_alarm', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Water alarm', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Water alarm', + 'platform': 'homematicip_cloud', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'water_alarm', + 'unique_id': '3014F7110000000000000WSS_1_water_alarm', + 'unit_of_measurement': None, + }) +# --- +# name: test_hmip_water_alarm_sensor[binary_sensor.wasserstopp_water_alarm-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'connection_type': , + : 'safety', + : 'Wasserstopp Water alarm', + 'id': '3014F7110000000000000WSS', + 'is_group': False, + 'model_type': 'HmIP-WSS-GB', + }), + 'context': , + 'entity_id': 'binary_sensor.wasserstopp_water_alarm', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- diff --git a/tests/components/homematicip_cloud/snapshots/test_button.ambr b/tests/components/homematicip_cloud/snapshots/test_button.ambr index cccfba4909c5..7ca13018817f 100644 --- a/tests/components/homematicip_cloud/snapshots/test_button.ambr +++ b/tests/components/homematicip_cloud/snapshots/test_button.ambr @@ -7,7 +7,7 @@ 'area_id': None, 'capabilities': None, 'config_entry_id': , - 'config_subentry_id': , + 'config_subentry_id': None, 'device_class': None, 'device_id': , 'disabled_by': None, diff --git a/tests/components/homematicip_cloud/snapshots/test_sensor.ambr b/tests/components/homematicip_cloud/snapshots/test_sensor.ambr index 6cef0cb4caf5..a9de8cbe2e6d 100644 --- a/tests/components/homematicip_cloud/snapshots/test_sensor.ambr +++ b/tests/components/homematicip_cloud/snapshots/test_sensor.ambr @@ -60,3 +60,65 @@ 'state': '3158.0', }) # --- +# name: test_hmip_water_supply_stop_water_flow[sensor.wasserstopp_water_flow-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.wasserstopp_water_flow', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Water flow', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 1, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Water flow', + 'platform': 'homematicip_cloud', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'water_flow', + 'unique_id': '3014F7110000000000000WSS_1_water_flow', + 'unit_of_measurement': , + }) +# --- +# name: test_hmip_water_supply_stop_water_flow[sensor.wasserstopp_water_flow-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'connection_type': , + : 'volume_flow_rate', + : 'Wasserstopp Water flow', + 'id': '3014F7110000000000000WSS', + 'is_group': False, + 'model_type': 'HmIP-WSS-GB', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.wasserstopp_water_flow', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- diff --git a/tests/components/homematicip_cloud/snapshots/test_valve.ambr b/tests/components/homematicip_cloud/snapshots/test_valve.ambr new file mode 100644 index 000000000000..7229fd3f6da2 --- /dev/null +++ b/tests/components/homematicip_cloud/snapshots/test_valve.ambr @@ -0,0 +1,58 @@ +# serializer version: 1 +# name: test_water_supply_valve[valve.wasserstopp-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'valve', + 'entity_category': None, + 'entity_id': 'valve.wasserstopp', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': None, + 'platform': 'homematicip_cloud', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + 'translation_key': None, + 'unique_id': '3014F7110000000000000WSS_1_water_supply', + 'unit_of_measurement': None, + }) +# --- +# name: test_water_supply_valve[valve.wasserstopp-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'connection_type': , + : 'water', + : 'Wasserstopp', + 'id': '3014F7110000000000000WSS', + : False, + 'is_group': False, + 'model_type': 'HmIP-WSS-GB', + : , + }), + 'context': , + 'entity_id': 'valve.wasserstopp', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'open', + }) +# --- diff --git a/tests/components/homematicip_cloud/test_binary_sensor.py b/tests/components/homematicip_cloud/test_binary_sensor.py index 7e4ac4979a38..aee9a110d35b 100644 --- a/tests/components/homematicip_cloud/test_binary_sensor.py +++ b/tests/components/homematicip_cloud/test_binary_sensor.py @@ -626,6 +626,31 @@ async def test_hmip_motion_detector_switch_outdoor( assert hass.states.get(entity_id).state == STATE_ON +async def test_hmip_water_alarm_sensor( + hass: HomeAssistant, + default_mock_hap_factory: HomeFactory, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test the water alarm of a water supply stop.""" + entity_id = "binary_sensor.wasserstopp_water_alarm" + with patch( + "homeassistant.components.homematicip_cloud.hap.PLATFORMS", + [Platform.BINARY_SENSOR], + ): + mock_hap = await default_mock_hap_factory.async_get_mock_hap( + test_devices=["Wasserstopp"], test_groups=[] + ) + + await snapshot_platform( + hass, entity_registry, snapshot, mock_hap.config_entry.entry_id + ) + + hmip_device = mock_hap.hmip_device_by_entity_id[entity_id] + await async_manipulate_test_data(hass, hmip_device, "waterAlarmActive", True) + assert hass.states.get(entity_id).state == STATE_ON + + async def test_hmip_rain_sensor( hass: HomeAssistant, default_mock_hap_factory: HomeFactory ) -> None: diff --git a/tests/components/homematicip_cloud/test_device.py b/tests/components/homematicip_cloud/test_device.py index cef8f0767f7b..7732f0956988 100644 --- a/tests/components/homematicip_cloud/test_device.py +++ b/tests/components/homematicip_cloud/test_device.py @@ -24,7 +24,7 @@ async def test_hmip_load_all_supported_devices( test_devices=None, test_groups=None ) - assert len(mock_hap.hmip_device_by_entity_id) == 411 + assert len(mock_hap.hmip_device_by_entity_id) == 415 async def test_hmip_remove_device( diff --git a/tests/components/homematicip_cloud/test_sensor.py b/tests/components/homematicip_cloud/test_sensor.py index 179f7de7f016..0e4d7c862397 100644 --- a/tests/components/homematicip_cloud/test_sensor.py +++ b/tests/components/homematicip_cloud/test_sensor.py @@ -962,6 +962,31 @@ async def test_hmip_water_valve_current_water_flow( assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT +async def test_hmip_water_supply_stop_water_flow( + hass: HomeAssistant, + default_mock_hap_factory: HomeFactory, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test the water flow of a water supply stop.""" + entity_id = "sensor.wasserstopp_water_flow" + with patch( + "homeassistant.components.homematicip_cloud.hap.PLATFORMS", + [Platform.SENSOR], + ): + mock_hap = await default_mock_hap_factory.async_get_mock_hap( + test_devices=["Wasserstopp"], test_groups=[] + ) + + await snapshot_platform( + hass, entity_registry, snapshot, mock_hap.config_entry.entry_id + ) + + hmip_device = mock_hap.hmip_device_by_entity_id[entity_id] + await async_manipulate_test_data(hass, hmip_device, "waterFlow", 11.55) + assert hass.states.get(entity_id).state == "11.55" + + async def test_hmip_water_valve_water_volume( hass: HomeAssistant, default_mock_hap_factory: HomeFactory ) -> None: diff --git a/tests/components/homematicip_cloud/test_valve.py b/tests/components/homematicip_cloud/test_valve.py index 4f945483bfe3..e827443fb8d8 100644 --- a/tests/components/homematicip_cloud/test_valve.py +++ b/tests/components/homematicip_cloud/test_valve.py @@ -1,11 +1,20 @@ """Test HomematicIP Cloud valve entities.""" +from unittest.mock import patch + +from homematicip.base.enums import WaterSupplyState +from pytest_homeassistant.common import snapshot_platform +from syrupy.assertion import SnapshotAssertion + from homeassistant.components.valve import ( DOMAIN as VALVE_DOMAIN, + SERVICE_CLOSE_VALVE, SERVICE_OPEN_VALVE, ValveState, ) +from homeassistant.const import STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics @@ -36,3 +45,53 @@ async def test_watering_valve( ) ha_state = hass.states.get(entity_id) assert ha_state.state == ValveState.OPEN + + +async def test_water_supply_valve( + hass: HomeAssistant, + default_mock_hap_factory: HomeFactory, + entity_registry: er.EntityRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test HomematicIP water supply stop valve.""" + entity_id = "valve.wasserstopp" + with patch( + "homeassistant.components.homematicip_cloud.hap.PLATFORMS", + [Platform.VALVE], + ): + mock_hap = await default_mock_hap_factory.async_get_mock_hap( + test_devices=["Wasserstopp"], test_groups=[] + ) + + await snapshot_platform( + hass, entity_registry, snapshot, mock_hap.config_entry.entry_id + ) + + hmip_device = mock_hap.hmip_device_by_entity_id[entity_id] + channel = hmip_device.functionalChannels[1] + + await hass.services.async_call( + VALVE_DOMAIN, SERVICE_CLOSE_VALVE, {"entity_id": entity_id}, blocking=True + ) + assert channel.mock_calls[-1][0] == "set_water_supply_state_async" + assert channel.mock_calls[-1][1] == (WaterSupplyState.NO_WATERFLOW,) + await async_manipulate_test_data( + hass, hmip_device, "waterSupplyState", WaterSupplyState.NO_WATERFLOW + ) + assert hass.states.get(entity_id).state == ValveState.CLOSED + + await hass.services.async_call( + VALVE_DOMAIN, SERVICE_OPEN_VALVE, {"entity_id": entity_id}, blocking=True + ) + assert channel.mock_calls[-1][0] == "set_water_supply_state_async" + assert channel.mock_calls[-1][1] == (WaterSupplyState.FULL_OPENED,) + + await async_manipulate_test_data( + hass, hmip_device, "waterSupplyState", WaterSupplyState.REDUCED_WATERFLOW + ) + assert hass.states.get(entity_id).state == ValveState.OPEN + + await async_manipulate_test_data( + hass, hmip_device, "waterSupplyState", WaterSupplyState.UNKNOWN + ) + assert hass.states.get(entity_id).state == STATE_UNKNOWN