Skip to content

Commit 6370901

Browse files
committed
Added support to send multiple commands to multiple devices at once
1 parent dd31be3 commit 6370901

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pyoverkiz/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
UnknownUserException,
7070
)
7171
from pyoverkiz.models import (
72+
Action,
7273
Command,
7374
Device,
7475
Event,
@@ -735,6 +736,28 @@ async def execute_commands(
735736
response: dict = await self.__post("exec/apply", payload)
736737
return cast(str, response["execId"])
737738

739+
@backoff.on_exception(
740+
backoff.expo,
741+
(NotAuthenticatedException, ServerDisconnectedError, ClientConnectorError),
742+
max_tries=2,
743+
on_backoff=relogin,
744+
)
745+
async def execute_actions(
746+
self,
747+
actions: list[Action],
748+
label: str | None = "python-overkiz-api",
749+
) -> str:
750+
"""Send several commands to different devices in one call"""
751+
payload = {
752+
"label": label,
753+
"actions": [
754+
{"deviceURL": action.device_url, "commands": action.commands}
755+
for action in actions
756+
],
757+
}
758+
response: dict = await self.__post("exec/apply", payload)
759+
return cast(str, response["execId"])
760+
738761
@backoff.on_exception(
739762
backoff.expo,
740763
(NotAuthenticatedException, ServerDisconnectedError, ClientConnectorError),

pyoverkiz/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ def __init__(
430430
dict.__init__(self, name=name, parameters=parameters)
431431

432432

433+
@define(init=False)
434+
class Action:
435+
"""Represents OverKiz Action (multiple commands for specific device URL)."""
436+
437+
device_url: str
438+
commands: list[Command]
439+
440+
def __init__(self, device_url: str, commands: list[Command]):
441+
self.device_url = device_url
442+
self.commands = commands
443+
444+
433445
@define(init=False, kw_only=True)
434446
class Event:
435447
name: EventName

0 commit comments

Comments
 (0)