Skip to content

Commit f28d09a

Browse files
committed
Add support for chaining multiple actions into a single API call
1 parent 23688d8 commit f28d09a

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

wmspro/action.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
)
77

88

9+
class ActionList(list):
10+
def __init__(self, control) -> None:
11+
super().__init__()
12+
self._control = control
13+
14+
async def __call__(
15+
self, responseType=WMS_WebControl_pro_API_responseType.Instant
16+
) -> Any:
17+
if len(self) == 0:
18+
raise ValueError("ActionList is empty")
19+
return await self._control._action(
20+
actions=self,
21+
responseType=responseType,
22+
)
23+
24+
925
class Action:
1026
def __init__(
1127
self, dest, id: int, actionType: int, actionDescription: int, **kwargs
@@ -62,17 +78,20 @@ def __getattr__(self, name: str) -> Any:
6278
def __getitem__(self, name: str) -> Any:
6379
return self._params.get(name)
6480

81+
def prep(self, **kwargs) -> ActionList:
82+
actionList = ActionList(self._dest._control)
83+
actionList.append({
84+
"destinationId": self._dest.id,
85+
"actionId": self.id,
86+
"parameters": kwargs,
87+
})
88+
return actionList
89+
6590
async def __call__(
6691
self, responseType=WMS_WebControl_pro_API_responseType.Instant, **kwargs
6792
) -> Any:
6893
return await self._dest._control._action(
69-
actions=[
70-
{
71-
"destinationId": self._dest.id,
72-
"actionId": self.id,
73-
"parameters": kwargs,
74-
}
75-
],
94+
actions=[self.prep(**kwargs)],
7695
responseType=responseType,
7796
)
7897

wmspro/webcontrol.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ async def async_main_test():
159159
)
160160
print(response)
161161

162+
action_list = action.prep(percentage=100)
163+
action_list += action.prep(percentage=0)
164+
print(action_list)
165+
response = await action_list(
166+
responseType=WMS_WebControl_pro_API_responseType.Detailed
167+
)
168+
print(response)
169+
162170
pprint.pprint(control.diag())
163171

164172

0 commit comments

Comments
 (0)