twist-innovation-api 0.0.2__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- twist/TwistAPI.py +2 -6
- twist/TwistCbShutter.py +3 -0
- twist/TwistDevice.py +0 -1
- twist/TwistLight.py +4 -0
- twist/TwistLouvre.py +6 -2
- twist/TwistModel.py +20 -0
- twist/TwistRgb.py +8 -3
- twist/TwistSensor.py +3 -0
- {twist_innovation_api-0.0.2.dist-info → twist_innovation_api-0.0.3.dist-info}/METADATA +3 -2
- twist_innovation_api-0.0.3.dist-info/RECORD +16 -0
- twist_innovation_api-0.0.2.dist-info/RECORD +0 -16
- {twist_innovation_api-0.0.2.dist-info → twist_innovation_api-0.0.3.dist-info}/WHEEL +0 -0
- {twist_innovation_api-0.0.2.dist-info → twist_innovation_api-0.0.3.dist-info}/licenses/LICENSE +0 -0
- {twist_innovation_api-0.0.2.dist-info → twist_innovation_api-0.0.3.dist-info}/top_level.txt +0 -0
twist/TwistAPI.py
CHANGED
|
@@ -15,17 +15,15 @@
|
|
|
15
15
|
import asyncio
|
|
16
16
|
import json
|
|
17
17
|
import random
|
|
18
|
-
from typing import Callable, Awaitable
|
|
19
18
|
|
|
20
19
|
from .TwistDevice import TwistDevice, TwistModel
|
|
21
20
|
from .TwistTypes import DeviceVariant
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
class TwistAPI:
|
|
25
|
-
def __init__(self, installation_id: int
|
|
24
|
+
def __init__(self, installation_id: int):
|
|
26
25
|
self._ext_publish = None
|
|
27
26
|
self._subscribe = None
|
|
28
|
-
self._callback: Callable[[TwistModel], Awaitable[None]] = model_update
|
|
29
27
|
|
|
30
28
|
self.function_map = {
|
|
31
29
|
"context": self._context_msg,
|
|
@@ -92,9 +90,7 @@ class TwistAPI:
|
|
|
92
90
|
|
|
93
91
|
async def _context_msg(self, twist_id, payload, model_id):
|
|
94
92
|
device = next((d for d in self.device_list if d.twist_id == twist_id), None)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await self._callback(model)
|
|
93
|
+
await device.context_msg(model_id, payload)
|
|
98
94
|
|
|
99
95
|
async def _get_board(self, twist_id, payload, model_id=None):
|
|
100
96
|
data = json.loads(payload)
|
twist/TwistCbShutter.py
CHANGED
|
@@ -26,5 +26,8 @@ class TwistCbShutter(TwistModel):
|
|
|
26
26
|
async def context_msg(self, payload: str):
|
|
27
27
|
self.parse_general_context(payload)
|
|
28
28
|
|
|
29
|
+
if self._update_callback is not None:
|
|
30
|
+
await self._update_callback(self)
|
|
31
|
+
|
|
29
32
|
def print_context(self):
|
|
30
33
|
print(f"Cb Shutter Device: {self.parent_device.twist_id}, Model: {self.model_id},")
|
twist/TwistDevice.py
CHANGED
twist/TwistLight.py
CHANGED
|
@@ -44,6 +44,7 @@ class TwistLight(TwistModel):
|
|
|
44
44
|
await self._activate_event(TwistLight.EventIndexes.TOGGLE)
|
|
45
45
|
|
|
46
46
|
async def set_value(self, value: int, fading_time: int | None = None):
|
|
47
|
+
value = value * 655.35
|
|
47
48
|
if fading_time is None:
|
|
48
49
|
await self._activate_event(TwistLight.EventIndexes.VALUE, value)
|
|
49
50
|
else:
|
|
@@ -79,6 +80,9 @@ class TwistLight(TwistModel):
|
|
|
79
80
|
elif index == 7:
|
|
80
81
|
self.current = value[0]
|
|
81
82
|
|
|
83
|
+
if self._update_callback is not None:
|
|
84
|
+
await self._update_callback(self)
|
|
85
|
+
|
|
82
86
|
def print_context(self):
|
|
83
87
|
print(
|
|
84
88
|
f"Light Device: {self.parent_device.twist_id}, Model: {self.model_id}, Actual: {self.actual_state}, "
|
twist/TwistLouvre.py
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# https://www.gnu.org/licenses/gpl-3.0.html
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
|
+
|
|
15
16
|
from typing import TYPE_CHECKING
|
|
16
17
|
|
|
17
18
|
if TYPE_CHECKING:
|
|
@@ -50,6 +51,9 @@ class TwistLouvre(TwistModel):
|
|
|
50
51
|
elif index == 7:
|
|
51
52
|
self.current = value[0]
|
|
52
53
|
|
|
54
|
+
if self._update_callback is not None:
|
|
55
|
+
await self._update_callback(self)
|
|
56
|
+
|
|
53
57
|
async def open(self):
|
|
54
58
|
await self._activate_event(TwistLouvre.EventIndexes.OPEN)
|
|
55
59
|
|
|
@@ -66,10 +70,10 @@ class TwistLouvre(TwistModel):
|
|
|
66
70
|
if fading_time is not None:
|
|
67
71
|
raise NotImplementedError("Fading time can't be used in this model")
|
|
68
72
|
else:
|
|
69
|
-
await self._activate_event(TwistLouvre.EventIndexes.VALUE, value)
|
|
73
|
+
await self._activate_event(TwistLouvre.EventIndexes.VALUE, int(value * 655.35))
|
|
70
74
|
|
|
71
75
|
async def _activate_event(self, index: TwistLouvre.EventIndexes, value: int | None = None,
|
|
72
|
-
|
|
76
|
+
fading_time: int | None = None):
|
|
73
77
|
data = {
|
|
74
78
|
"i": index.value
|
|
75
79
|
}
|
twist/TwistModel.py
CHANGED
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
# https://www.gnu.org/licenses/gpl-3.0.html
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
|
+
|
|
15
16
|
from typing import TYPE_CHECKING
|
|
16
17
|
|
|
17
18
|
if TYPE_CHECKING:
|
|
18
19
|
from TwistDevice import TwistDevice
|
|
19
20
|
|
|
20
21
|
import json
|
|
22
|
+
|
|
23
|
+
from typing import Callable, Awaitable
|
|
21
24
|
from .TwistTypes import ContextErrors
|
|
22
25
|
|
|
23
26
|
|
|
@@ -34,9 +37,13 @@ class TwistModel():
|
|
|
34
37
|
"prio": None
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
self._update_callback: Callable[[TwistModel], Awaitable[None]] | None = None
|
|
41
|
+
|
|
42
|
+
|
|
37
43
|
def print_context(self):
|
|
38
44
|
print("function is not supported")
|
|
39
45
|
|
|
46
|
+
|
|
40
47
|
def parse_general_context(self, payload: str):
|
|
41
48
|
data = json.loads(payload)
|
|
42
49
|
|
|
@@ -54,29 +61,42 @@ class TwistModel():
|
|
|
54
61
|
self.errors["prio"] = value
|
|
55
62
|
return data
|
|
56
63
|
|
|
64
|
+
|
|
57
65
|
def _get_value_from_context(self, ctx: dict):
|
|
58
66
|
return ctx["i"], ctx["vl"]
|
|
59
67
|
|
|
68
|
+
|
|
60
69
|
async def context_msg(self, payload):
|
|
61
70
|
raise NotImplementedError("Function not supported for this model")
|
|
62
71
|
|
|
72
|
+
|
|
63
73
|
async def turn_on(self):
|
|
64
74
|
raise NotImplementedError("Function not supported for this model")
|
|
65
75
|
|
|
76
|
+
|
|
66
77
|
async def turn_off(self):
|
|
67
78
|
raise NotImplementedError("Function not supported for this model")
|
|
68
79
|
|
|
80
|
+
|
|
69
81
|
async def open(self):
|
|
70
82
|
raise NotImplementedError("Function not supported for this model")
|
|
71
83
|
|
|
84
|
+
|
|
72
85
|
async def stop(self):
|
|
73
86
|
raise NotImplementedError("Function not supported for this model")
|
|
74
87
|
|
|
88
|
+
|
|
75
89
|
async def close(self):
|
|
76
90
|
raise NotImplementedError("Function not supported for this model")
|
|
77
91
|
|
|
92
|
+
|
|
78
93
|
async def toggle(self):
|
|
79
94
|
raise NotImplementedError("Function not supported for this model")
|
|
80
95
|
|
|
96
|
+
|
|
81
97
|
async def set_value(self, value: int | list[int, int] | list[int, int, int], fading_time: int | None = None):
|
|
82
98
|
raise NotImplementedError("Function not supported for this model")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def register_update_cb(self, cb: Callable[[TwistModel], Awaitable[None]]):
|
|
102
|
+
self._update_callback = cb
|
twist/TwistRgb.py
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# https://www.gnu.org/licenses/gpl-3.0.html
|
|
13
13
|
|
|
14
14
|
from __future__ import annotations
|
|
15
|
+
|
|
15
16
|
from typing import TYPE_CHECKING
|
|
16
17
|
|
|
17
18
|
if TYPE_CHECKING:
|
|
@@ -57,8 +58,8 @@ class TwistRgb(TwistModel):
|
|
|
57
58
|
else:
|
|
58
59
|
await self._activate_event(TwistRgb.EventIndexes.VALUE_FADING, value, fading_time)
|
|
59
60
|
|
|
60
|
-
async def _activate_event(self, index: TwistRgb.EventIndexes, value:
|
|
61
|
-
|
|
61
|
+
async def _activate_event(self, index: TwistRgb.EventIndexes, value: tuple[int, int, int] | None = None,
|
|
62
|
+
fading_time: int | None = None):
|
|
62
63
|
data = {
|
|
63
64
|
"i": index.value
|
|
64
65
|
}
|
|
@@ -66,8 +67,9 @@ class TwistRgb(TwistModel):
|
|
|
66
67
|
if value is None:
|
|
67
68
|
data["vl"] = []
|
|
68
69
|
elif fading_time is None:
|
|
69
|
-
data["vl"] = value
|
|
70
|
+
data["vl"] = [int(v / 655.35) for v in value]
|
|
70
71
|
else:
|
|
72
|
+
value = list(value)
|
|
71
73
|
value.append(fading_time)
|
|
72
74
|
data["vl"] = value
|
|
73
75
|
|
|
@@ -91,6 +93,9 @@ class TwistRgb(TwistModel):
|
|
|
91
93
|
if index == 6:
|
|
92
94
|
self.operating_time = value[0]
|
|
93
95
|
|
|
96
|
+
if self._update_callback is not None:
|
|
97
|
+
await self._update_callback(self)
|
|
98
|
+
|
|
94
99
|
def print_context(self):
|
|
95
100
|
print(f"Rgb Device: {self.parent_device.twist_id}, Model: {self.model_id}, "
|
|
96
101
|
f"Actual: h{self.actual_h} s{self.actual_s} v{self.actual_v}")
|
twist/TwistSensor.py
CHANGED
|
@@ -27,5 +27,8 @@ class TwistSensor(TwistModel):
|
|
|
27
27
|
async def context_msg(self, payload: str):
|
|
28
28
|
self.parse_general_context(payload)
|
|
29
29
|
|
|
30
|
+
if self._update_callback is not None:
|
|
31
|
+
await self._update_callback(self)
|
|
32
|
+
|
|
30
33
|
def print_context(self):
|
|
31
34
|
print(f"Sensor Device: {self.parent_device.twist_id}, Model: {self.model_id}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: twist-innovation-api
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: Python library to talk to the twist-innovation api
|
|
5
5
|
Home-page: https://github.com/twist-innovation/twist-innovation-api
|
|
6
6
|
Author: Sibrecht Goudsmedt
|
|
@@ -133,12 +133,13 @@ async def main():
|
|
|
133
133
|
asyncio.create_task(listen())
|
|
134
134
|
|
|
135
135
|
# Initialize Twist API with async methods
|
|
136
|
-
twist_api = TwistAPI(8
|
|
136
|
+
twist_api = TwistAPI(8)
|
|
137
137
|
await twist_api.add_mqtt(mqtt_publish, mqtt_subscribe)
|
|
138
138
|
|
|
139
139
|
twist_model_list: list[TwistModel] = await twist_api.search_models()
|
|
140
140
|
|
|
141
141
|
for model in twist_model_list:
|
|
142
|
+
model.register_update_cb(on_model_update)
|
|
142
143
|
print(f"{type(model)} has Model id: {model.model_id}, Device id: {model.parent_device.twist_id}")
|
|
143
144
|
|
|
144
145
|
while True:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
twist/TwistAPI.py,sha256=LBLBGgwY66lVBNSto4VjPEpzj9kmDzXTCwpW9f3OSic,3579
|
|
2
|
+
twist/TwistCbShutter.py,sha256=mWQa4ro30uI8qm0J1rkR8M0KP7IwxlCRfWt0wSyCOLA,1199
|
|
3
|
+
twist/TwistDevice.py,sha256=PoPKnNrbiy1j55MyZJW4nDg9OXtGZI7CgHlxcDEQhqs,1380
|
|
4
|
+
twist/TwistLight.py,sha256=6f-gPfP6v7BgaRJUFt7Q3r990y2L0812d76K_33KSTw,3230
|
|
5
|
+
twist/TwistLouvre.py,sha256=f2ocRjLkf3qC45hbcHdEOboA2mbkaxLaOa15tvkHOHY,3320
|
|
6
|
+
twist/TwistModel.py,sha256=SQHpYmpdV7PfZij69-TIHDa_77QabamZ71f9ZUeyvOk,3179
|
|
7
|
+
twist/TwistRgb.py,sha256=V7YuaqJaLTH3cL8CsQ3xIztfVKfqdMMJ7uyh9UZQDwA,3572
|
|
8
|
+
twist/TwistSensor.py,sha256=6eYrwtZFFFOHmoHS68JHmsyi6FVVzoQy19KooGU0vMI,1192
|
|
9
|
+
twist/TwistTypes.py,sha256=wsp-lnkaU70wNdoKWOWcnsq89vBheBYmM31ZXW3FMRw,2166
|
|
10
|
+
twist/Variants.py,sha256=SFAZ7bSmTRomPspOfU1qNWEW-htRuyhTKuyGKK9Qh54,1369
|
|
11
|
+
twist/__init__.py,sha256=gf8GHc9utiG0vD8GP3IfzLFHAG-ev1TXBIm0XUHxy38,201
|
|
12
|
+
twist_innovation_api-0.0.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
13
|
+
twist_innovation_api-0.0.3.dist-info/METADATA,sha256=aquMRxNsC_ZBZJLCrulRkXUxDfTyG4mxub0WDOgmBXo,4335
|
|
14
|
+
twist_innovation_api-0.0.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
15
|
+
twist_innovation_api-0.0.3.dist-info/top_level.txt,sha256=mkoeBkRPFodjnd-3UDf9YndjTQ6Sriz-EKSI4nQ7brs,6
|
|
16
|
+
twist_innovation_api-0.0.3.dist-info/RECORD,,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
twist/TwistAPI.py,sha256=hXkkxkUM9W9oDczRKwioDJ1SZA0s1K8Ed612YkvtUmk,3797
|
|
2
|
-
twist/TwistCbShutter.py,sha256=Ps_Yvr7pl71wvt0h3BU12MyccUitA6qJMyBP-Yq9qks,1106
|
|
3
|
-
twist/TwistDevice.py,sha256=1wfLNB0BgJHDSUrBYD4gv_Txak7SS4mmHrJ0jcMxfI8,1421
|
|
4
|
-
twist/TwistLight.py,sha256=TrlZ03Aztc8-Qvybv96RYA_21zAke6GLBGHFpk-RznU,3106
|
|
5
|
-
twist/TwistLouvre.py,sha256=wFl8MOMMslKDzSr2FkqArXXoJ5CWvBqMde7-UTlEpgU,3206
|
|
6
|
-
twist/TwistModel.py,sha256=pyaGiw2vpaCsZkp0xC6XDB7HABGZM_2X7aZCqAxhmE0,2925
|
|
7
|
-
twist/TwistRgb.py,sha256=MxAshwe4fczGD-pEgMAXG5847kKR0KFm7WemWKeDKHs,3412
|
|
8
|
-
twist/TwistSensor.py,sha256=C1uHxdVvixnJeijeWAhArSAu5e7Dag7yt-dqqt407lg,1099
|
|
9
|
-
twist/TwistTypes.py,sha256=wsp-lnkaU70wNdoKWOWcnsq89vBheBYmM31ZXW3FMRw,2166
|
|
10
|
-
twist/Variants.py,sha256=SFAZ7bSmTRomPspOfU1qNWEW-htRuyhTKuyGKK9Qh54,1369
|
|
11
|
-
twist/__init__.py,sha256=gf8GHc9utiG0vD8GP3IfzLFHAG-ev1TXBIm0XUHxy38,201
|
|
12
|
-
twist_innovation_api-0.0.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
13
|
-
twist_innovation_api-0.0.2.dist-info/METADATA,sha256=g7LK4ufC35S-4xD1w8me6pb95jbmURlhALaRs7p3yp0,4298
|
|
14
|
-
twist_innovation_api-0.0.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
15
|
-
twist_innovation_api-0.0.2.dist-info/top_level.txt,sha256=mkoeBkRPFodjnd-3UDf9YndjTQ6Sriz-EKSI4nQ7brs,6
|
|
16
|
-
twist_innovation_api-0.0.2.dist-info/RECORD,,
|
|
File without changes
|
{twist_innovation_api-0.0.2.dist-info → twist_innovation_api-0.0.3.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|