Skip to content

Commit 4c39936

Browse files
authored
Matter valve Open command doesn't support TargetLevel=0 (#150922)
1 parent d90590b commit 4c39936

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

homeassistant/components/matter/valve.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ async def async_close_valve(self) -> None:
5252

5353
async def async_set_valve_position(self, position: int) -> None:
5454
"""Move the valve to a specific position."""
55-
await self.send_device_command(
56-
ValveConfigurationAndControl.Commands.Open(targetLevel=position)
57-
)
55+
if position > 0:
56+
await self.send_device_command(
57+
ValveConfigurationAndControl.Commands.Open(targetLevel=position)
58+
)
59+
return
60+
await self.send_device_command(ValveConfigurationAndControl.Commands.Close())
5861

5962
@callback
6063
def _update_from_device(self) -> None:

tests/components/matter/test_valve.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,22 @@ async def test_valve(
133133
command=clusters.ValveConfigurationAndControl.Commands.Open(targetLevel=100),
134134
)
135135
matter_client.send_device_command.reset_mock()
136+
137+
# test using set_position action to close valve
138+
await hass.services.async_call(
139+
"valve",
140+
"set_valve_position",
141+
{
142+
"entity_id": entity_id,
143+
"position": 0,
144+
},
145+
blocking=True,
146+
)
147+
148+
assert matter_client.send_device_command.call_count == 1
149+
assert matter_client.send_device_command.call_args == call(
150+
node_id=matter_node.node_id,
151+
endpoint_id=1,
152+
command=clusters.ValveConfigurationAndControl.Commands.Close(),
153+
)
154+
matter_client.send_device_command.reset_mock()

0 commit comments

Comments
 (0)