Skip to content

Commit 45a452b

Browse files
authored
Add scenarios support (#13)
1 parent de8fe93 commit 45a452b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

tahoma_api/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from aiohttp import ClientResponse
88

99
from tahoma_api.exceptions import BadCredentialsException, TooManyRequestsException
10-
from tahoma_api.models import Command, CommandMode, Device, State
10+
from tahoma_api.models import Command, CommandMode, Device, Scenario, State
1111

1212
JSON = Union[Dict[str, Any], List[Dict[str, Any]]]
1313

@@ -141,6 +141,16 @@ async def get_current_executions(self) -> List[Any]:
141141

142142
return response
143143

144+
async def get_scenarios(self) -> List[Scenario]:
145+
""" List the scenarios """
146+
response = await self.__get("actionGroups")
147+
return [Scenario(**scenario) for scenario in response]
148+
149+
async def execute_scenario(self, oid: str) -> str:
150+
""" Execute a scenario """
151+
response = await self.__post(f"exec/{oid}")
152+
return response["execId"]
153+
144154
async def __get(self, endpoint: str) -> Any:
145155
""" Make a GET request to the TaHoma API """
146156
async with self.session.get(f"{self.api_url}{endpoint}") as response:

tahoma_api/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,11 @@ class CommandMode(Enum):
126126
high_priority = ("highPriority",)
127127
geolocated = ("geolocated",)
128128
internal = "internal"
129+
130+
131+
class Scenario:
132+
__slots__ = ("label", "oid")
133+
134+
def __init__(self, label: str, oid: str, **_: Any):
135+
self.label = label
136+
self.oid = oid

0 commit comments

Comments
 (0)