-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththing.py
57 lines (46 loc) · 1.54 KB
/
thing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Support for things."""
from __future__ import annotations
from .maveo_box import MaveoBox
class Thing:
"""Represents a thing connected to the maveo box."""
def __init__(
self,
thingid: str,
thingclassId: str,
manufacturer: str,
name: str,
maveoBox: MaveoBox,
) -> None:
"""Init sensor."""
self._id = thingid
self.thingclass_id = thingclassId
self.name = name
self.manufacturer = manufacturer
self.maveoBox = maveoBox
@property
def id(self) -> str:
"""Return ID for thing."""
return self._id
@staticmethod
async def add(maveoBox: MaveoBox):
"""Add all things connected to the maveo box."""
things = maveoBox.send_command("Integrations.GetThings")["params"]["things"]
for thing in things:
params = {}
params["thingClassIds"] = [thing["thingClassId"]]
thingClasses = maveoBox.send_command(
"Integrations.GetThingClasses", params
)["params"]["thingClasses"]
vendors = maveoBox.send_command("Integrations.GetVendors")["params"][
"vendors"
]
vendor = next(x for x in vendors if x["id"] == thingClasses[0]["vendorId"])
maveoBox.things.append(
Thing(
thing["id"],
thing["thingClassId"],
vendor["displayName"],
thing["name"],
maveoBox,
)
)