Skip to content

Commit 0a43bd3

Browse files
authored
Add enum_set and text_set methods (#851)
1 parent 9209cb5 commit 0a43bd3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

aioshelly/rpc_device/device.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ async def blu_trv_clear_boost(self, trv_id: int) -> None:
333333
}
334334
await self.call_rpc("BluTRV.Call", params=params, timeout=BLU_TRV_TIMEOUT)
335335

336+
async def enum_set(self, id_: int, value: str) -> None:
337+
"""Set the value for the enum component."""
338+
params = {
339+
"id": id_,
340+
"value": value,
341+
}
342+
await self.call_rpc("Enum.Set", params=params)
343+
336344
async def number_set(self, id_: int, value: float) -> None:
337345
"""Set the value for the number component."""
338346
params = {
@@ -341,6 +349,14 @@ async def number_set(self, id_: int, value: float) -> None:
341349
}
342350
await self.call_rpc("Number.Set", params=params)
343351

352+
async def text_set(self, id_: int, value: str) -> None:
353+
"""Set the value for the text component."""
354+
params = {
355+
"id": id_,
356+
"value": value,
357+
}
358+
await self.call_rpc("Text.Set", params=params)
359+
344360
async def update_status(self) -> None:
345361
"""Get device status from 'Shelly.GetStatus'."""
346362
self._status = await self.call_rpc("Shelly.GetStatus")

tests/rpc_device/test_device.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,3 +978,35 @@ async def test_number_set(
978978
"id": 12,
979979
"value": 33.2,
980980
}
981+
982+
983+
@pytest.mark.asyncio
984+
async def test_enum_set(
985+
rpc_device: RpcDevice,
986+
) -> None:
987+
"""Test RpcDevice enum_set() method."""
988+
await rpc_device.enum_set(12, "option 1")
989+
990+
assert rpc_device.call_rpc_multiple.call_count == 1
991+
call_args_list = rpc_device.call_rpc_multiple.call_args_list
992+
assert call_args_list[0][0][0][0][0] == "Enum.Set"
993+
assert call_args_list[0][0][0][0][1] == {
994+
"id": 12,
995+
"value": "option 1",
996+
}
997+
998+
999+
@pytest.mark.asyncio
1000+
async def test_text_set(
1001+
rpc_device: RpcDevice,
1002+
) -> None:
1003+
"""Test RpcDevice text_set() method."""
1004+
await rpc_device.text_set(12, "lorem ipsum")
1005+
1006+
assert rpc_device.call_rpc_multiple.call_count == 1
1007+
call_args_list = rpc_device.call_rpc_multiple.call_args_list
1008+
assert call_args_list[0][0][0][0][0] == "Text.Set"
1009+
assert call_args_list[0][0][0][0][1] == {
1010+
"id": 12,
1011+
"value": "lorem ipsum",
1012+
}

0 commit comments

Comments
 (0)