teleco-daisy 0.1.0__tar.gz
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.
- teleco_daisy-0.1.0/LICENSE +21 -0
- teleco_daisy-0.1.0/PKG-INFO +26 -0
- teleco_daisy-0.1.0/README.md +11 -0
- teleco_daisy-0.1.0/pyproject.toml +18 -0
- teleco_daisy-0.1.0/teleco_daisy.py +334 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Andreas Nüßlein
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: teleco-daisy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Your Name
|
|
6
|
+
Author-email: you@example.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# teleco_daisy
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
small library to talk to the Teleco Automation Daisy.
|
|
19
|
+
|
|
20
|
+
this is alpha. currently supported are:
|
|
21
|
+
|
|
22
|
+
- pergola slats
|
|
23
|
+
- pergola rgb light
|
|
24
|
+
|
|
25
|
+
if anybody stumbles over this and has different hardware, let me know and we try to integrate it together.
|
|
26
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# teleco_daisy
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
small library to talk to the Teleco Automation Daisy.
|
|
5
|
+
|
|
6
|
+
this is alpha. currently supported are:
|
|
7
|
+
|
|
8
|
+
- pergola slats
|
|
9
|
+
- pergola rgb light
|
|
10
|
+
|
|
11
|
+
if anybody stumbles over this and has different hardware, let me know and we try to integrate it together.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "teleco-daisy"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = ""
|
|
5
|
+
authors = ["Your Name <you@example.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = "^3.10"
|
|
10
|
+
requests = "*"
|
|
11
|
+
|
|
12
|
+
[tool.poetry.group.dev.dependencies]
|
|
13
|
+
black = "^24.1.1"
|
|
14
|
+
icecream = "^2.1.3"
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["poetry-core"]
|
|
18
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from time import sleep
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
base_url = "https://tmate.telecoautomation.com/"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class DaisyStatus:
|
|
12
|
+
idInstallationDeviceStatusitem: int
|
|
13
|
+
idDevicetypeStatusitemModel: int
|
|
14
|
+
statusitemCode: str
|
|
15
|
+
statusItem: str
|
|
16
|
+
statusValue: str
|
|
17
|
+
lowlevelStatusitem: None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class DaisyInstallation:
|
|
22
|
+
activetimer: str
|
|
23
|
+
firmwareVersion: str
|
|
24
|
+
idInstallation: int
|
|
25
|
+
idInstallationDevice: int
|
|
26
|
+
instCode: str
|
|
27
|
+
instDescription: str
|
|
28
|
+
installationOrder: int
|
|
29
|
+
latitude: float
|
|
30
|
+
longitude: float
|
|
31
|
+
weekend: str # list[str]
|
|
32
|
+
workdays: str # list[str]
|
|
33
|
+
|
|
34
|
+
client: "TelecoDaisy"
|
|
35
|
+
|
|
36
|
+
def status(self):
|
|
37
|
+
return self.client.get_installation_is_active(self)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class DaisyDevice:
|
|
42
|
+
activetimer: str
|
|
43
|
+
deviceCode: str
|
|
44
|
+
deviceIndex: int
|
|
45
|
+
deviceOrder: int
|
|
46
|
+
directOnly: None
|
|
47
|
+
favorite: str
|
|
48
|
+
feedback: str
|
|
49
|
+
idDevicemodel: int
|
|
50
|
+
idDevicetype: int
|
|
51
|
+
idInstallationDevice: int
|
|
52
|
+
label: str
|
|
53
|
+
remoteControlCode: str
|
|
54
|
+
|
|
55
|
+
client: "TelecoDaisy"
|
|
56
|
+
installation: DaisyInstallation
|
|
57
|
+
|
|
58
|
+
def update_state(self) -> list[DaisyStatus]:
|
|
59
|
+
return self.client.status_device_list(self.installation, self)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class DaisyCover(DaisyDevice):
|
|
63
|
+
position: int | None = None
|
|
64
|
+
is_closed: bool | None = None
|
|
65
|
+
|
|
66
|
+
def update_state(self):
|
|
67
|
+
stati = super().update_state()
|
|
68
|
+
for status in stati:
|
|
69
|
+
if status.statusitemCode == "OPEN_CLOSE":
|
|
70
|
+
if status.statusValue == "CLOSE":
|
|
71
|
+
self.is_closed = True
|
|
72
|
+
elif status.statusValue == "OPEN":
|
|
73
|
+
self.is_closed = False
|
|
74
|
+
else:
|
|
75
|
+
self.is_closed = None
|
|
76
|
+
if status.statusitemCode == "LEVEL":
|
|
77
|
+
self.position = int(status.statusValue)
|
|
78
|
+
|
|
79
|
+
def open_cover(self, percent: Literal["33", "66", "100"] = None):
|
|
80
|
+
if percent == "100":
|
|
81
|
+
return self._open_stop_close("open")
|
|
82
|
+
self._control_cover(percent)
|
|
83
|
+
|
|
84
|
+
def stop_cover(self):
|
|
85
|
+
self._open_stop_close("stop")
|
|
86
|
+
|
|
87
|
+
def close_cover(self):
|
|
88
|
+
self._open_stop_close("close")
|
|
89
|
+
|
|
90
|
+
def _open_stop_close(self, open_stop_close: Literal["open", "stop", "close"]):
|
|
91
|
+
osc_map = {
|
|
92
|
+
"open": ["OPEN", 94, "CH4"],
|
|
93
|
+
"stop": ["STOP", 95, "CH7"],
|
|
94
|
+
"close": ["CLOSE", 96, "CH1"],
|
|
95
|
+
}
|
|
96
|
+
c_param, c_id, c_ll = osc_map[open_stop_close]
|
|
97
|
+
return self.client.feed_the_commands(
|
|
98
|
+
installation=self.installation,
|
|
99
|
+
commandsList=[
|
|
100
|
+
{
|
|
101
|
+
"deviceCode": str(self.deviceIndex),
|
|
102
|
+
"idInstallationDevice": self.idInstallationDevice,
|
|
103
|
+
"commandAction": "OPEN_STOP_CLOSE",
|
|
104
|
+
"commandId": c_id,
|
|
105
|
+
"commandParam": c_param,
|
|
106
|
+
"lowlevelCommand": c_ll,
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def _control_cover(self, percent: Literal["33", "66", "100"]):
|
|
112
|
+
percent_map = {
|
|
113
|
+
"33": ["LEV2", 97, "CH2"],
|
|
114
|
+
"66": ["LEV3", 98, "CH3"],
|
|
115
|
+
"100": ["LEV4", 99, "CH4"],
|
|
116
|
+
}
|
|
117
|
+
c_param, c_id, c_ll = percent_map[percent]
|
|
118
|
+
|
|
119
|
+
return self.client.feed_the_commands(
|
|
120
|
+
installation=self.installation,
|
|
121
|
+
commandsList=[
|
|
122
|
+
{
|
|
123
|
+
"deviceCode": str(self.deviceIndex),
|
|
124
|
+
"idInstallationDevice": self.idInstallationDevice,
|
|
125
|
+
"commandAction": "LEVEL",
|
|
126
|
+
"commandId": c_id,
|
|
127
|
+
"commandParam": c_param,
|
|
128
|
+
"lowlevelCommand": c_ll,
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class DaisyLight(DaisyDevice):
|
|
135
|
+
is_on: bool | None = None
|
|
136
|
+
brightness: int | None = None # from 0 to 100
|
|
137
|
+
rgb: tuple[int, int, int] | None = None
|
|
138
|
+
|
|
139
|
+
def update_state(self):
|
|
140
|
+
stati = super().update_state()
|
|
141
|
+
for status in stati:
|
|
142
|
+
if status.statusitemCode == "POWER":
|
|
143
|
+
self.is_on = status.statusValue == "ON"
|
|
144
|
+
if status.statusitemCode == "COLOR":
|
|
145
|
+
val = status.statusValue
|
|
146
|
+
self.brightness = int(val[1:4])
|
|
147
|
+
self.rgb = (int(val[5:8]), int(val[9:12]), int(val[13:16]))
|
|
148
|
+
|
|
149
|
+
def set_rgb_and_brightness(
|
|
150
|
+
self, rgb: tuple[int, int, int] = None, brightness: int = None
|
|
151
|
+
):
|
|
152
|
+
if brightness is None:
|
|
153
|
+
brightness = self.brightness or 0
|
|
154
|
+
if 0 > brightness or brightness > 100:
|
|
155
|
+
raise ValueError("Brightness must be between 0 and 100")
|
|
156
|
+
if rgb is None:
|
|
157
|
+
rgb = self.rgb or (255, 255, 255)
|
|
158
|
+
if any((c < 0 or c > 255) for c in rgb):
|
|
159
|
+
raise ValueError("Color must be between 0 and 255")
|
|
160
|
+
|
|
161
|
+
v = f"A{brightness:03d}R{rgb[0]:03d}G{rgb[1]:03d}B{rgb[2]:03d}"
|
|
162
|
+
return self.client.feed_the_commands(
|
|
163
|
+
installation=self.installation,
|
|
164
|
+
commandsList=[
|
|
165
|
+
{
|
|
166
|
+
"commandAction": "COLOR",
|
|
167
|
+
"commandId": 137,
|
|
168
|
+
"commandParam": v,
|
|
169
|
+
"deviceCode": str(self.deviceIndex),
|
|
170
|
+
"idInstallationDevice": self.idInstallationDevice,
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def turn_off(self):
|
|
176
|
+
return self.client.feed_the_commands(
|
|
177
|
+
installation=self.installation,
|
|
178
|
+
commandsList=[
|
|
179
|
+
{
|
|
180
|
+
"commandAction": "POWER",
|
|
181
|
+
"commandId": 138,
|
|
182
|
+
"commandParam": "OFF",
|
|
183
|
+
"deviceCode": str(self.deviceIndex),
|
|
184
|
+
"idInstallationDevice": self.idInstallationDevice,
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@dataclass
|
|
191
|
+
class DaisyRoom:
|
|
192
|
+
idInstallationRoom: int
|
|
193
|
+
idRoomtype: int
|
|
194
|
+
roomDescription: str
|
|
195
|
+
roomOrder: int
|
|
196
|
+
deviceList: list[DaisyDevice]
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class TelecoDaisy:
|
|
200
|
+
idAccount: int | None = None
|
|
201
|
+
idSession: str | None = None
|
|
202
|
+
|
|
203
|
+
def __init__(self, email, password):
|
|
204
|
+
self.s = requests.Session()
|
|
205
|
+
self.s.auth = ("teleco", "tmate20")
|
|
206
|
+
self.email = email
|
|
207
|
+
self.password = password
|
|
208
|
+
|
|
209
|
+
def login(self):
|
|
210
|
+
login = self.s.post(
|
|
211
|
+
base_url + "teleco/services/account-login",
|
|
212
|
+
json={"email": self.email, "pwd": self.password},
|
|
213
|
+
)
|
|
214
|
+
login_json = login.json()
|
|
215
|
+
if login_json["codEsito"] != "S":
|
|
216
|
+
raise Exception(login_json)
|
|
217
|
+
|
|
218
|
+
self.idAccount = login_json["valRisultato"]["idAccount"]
|
|
219
|
+
self.idSession = login_json["valRisultato"]["idSession"]
|
|
220
|
+
|
|
221
|
+
def get_account_installation_list(self) -> list[DaisyInstallation]:
|
|
222
|
+
req = self.s.post(
|
|
223
|
+
base_url + "teleco/services/account-installation-list",
|
|
224
|
+
json={"idSession": self.idSession, "idAccount": self.idAccount},
|
|
225
|
+
)
|
|
226
|
+
req_json = req.json()
|
|
227
|
+
if req_json["codEsito"] != "S":
|
|
228
|
+
raise Exception(req_json)
|
|
229
|
+
|
|
230
|
+
installations = []
|
|
231
|
+
for inst in req_json["valRisultato"]["installationList"]:
|
|
232
|
+
installations += [DaisyInstallation(**inst, client=self)]
|
|
233
|
+
return installations
|
|
234
|
+
|
|
235
|
+
def get_installation_is_active(self, installation: DaisyInstallation):
|
|
236
|
+
req = self.s.post(
|
|
237
|
+
base_url + "teleco/services/tmate20/nodestatus",
|
|
238
|
+
json={
|
|
239
|
+
"idSession": self.idSession,
|
|
240
|
+
"idInstallation": installation.idInstallation,
|
|
241
|
+
},
|
|
242
|
+
)
|
|
243
|
+
req_json = req.json()
|
|
244
|
+
return req_json["nodeActive"]
|
|
245
|
+
|
|
246
|
+
def get_room_list(self, installation: DaisyInstallation) -> list[DaisyRoom]:
|
|
247
|
+
req = self.s.post(
|
|
248
|
+
base_url + "teleco/services/room-list",
|
|
249
|
+
json={
|
|
250
|
+
"idSession": self.idSession,
|
|
251
|
+
"idAccount": self.idAccount,
|
|
252
|
+
"idInstallation": installation.idInstallation,
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
req_json = req.json()
|
|
256
|
+
if req_json["codEsito"] != "S":
|
|
257
|
+
raise Exception(req_json)
|
|
258
|
+
|
|
259
|
+
rooms = []
|
|
260
|
+
for room in req_json["valRisultato"]["roomList"]:
|
|
261
|
+
devices = []
|
|
262
|
+
for device in room.pop("deviceList"):
|
|
263
|
+
if device["idDevicetype"] == 23:
|
|
264
|
+
devices += [
|
|
265
|
+
DaisyLight(**device, client=self, installation=installation)
|
|
266
|
+
]
|
|
267
|
+
elif device["idDevicetype"] == 24:
|
|
268
|
+
devices += [
|
|
269
|
+
DaisyCover(**device, client=self, installation=installation)
|
|
270
|
+
]
|
|
271
|
+
rooms += [DaisyRoom(**room, deviceList=devices)]
|
|
272
|
+
return rooms
|
|
273
|
+
|
|
274
|
+
def status_device_list(
|
|
275
|
+
self, installation: DaisyInstallation, device: DaisyDevice
|
|
276
|
+
) -> list[DaisyStatus]:
|
|
277
|
+
req = self.s.post(
|
|
278
|
+
base_url + "teleco/services/status-device-list",
|
|
279
|
+
json={
|
|
280
|
+
"idSession": self.idSession,
|
|
281
|
+
"idAccount": self.idAccount,
|
|
282
|
+
"idInstallation": installation.idInstallation,
|
|
283
|
+
"idInstallationDevice": device.idInstallationDevice,
|
|
284
|
+
},
|
|
285
|
+
)
|
|
286
|
+
req_json = req.json()
|
|
287
|
+
if req_json["codEsito"] != "S":
|
|
288
|
+
raise Exception(req_json)
|
|
289
|
+
|
|
290
|
+
return [DaisyStatus(**x) for x in req_json["valRisultato"]["statusitemList"]]
|
|
291
|
+
|
|
292
|
+
def feed_the_commands(
|
|
293
|
+
self,
|
|
294
|
+
installation: DaisyInstallation,
|
|
295
|
+
commandsList: list[dict],
|
|
296
|
+
ignore_ack=False,
|
|
297
|
+
):
|
|
298
|
+
req = self.s.post(
|
|
299
|
+
base_url + "teleco/services/tmate20/feedthecommands/",
|
|
300
|
+
json={
|
|
301
|
+
"commandsList": commandsList,
|
|
302
|
+
"idInstallation": installation.instCode,
|
|
303
|
+
"idSession": self.idSession,
|
|
304
|
+
"idScenario": 0,
|
|
305
|
+
"isScenario": False,
|
|
306
|
+
},
|
|
307
|
+
)
|
|
308
|
+
req_json = req.json()
|
|
309
|
+
|
|
310
|
+
if req_json["MessageID"] != "WS-000":
|
|
311
|
+
raise Exception(req_json)
|
|
312
|
+
|
|
313
|
+
if ignore_ack:
|
|
314
|
+
return {"success": None}
|
|
315
|
+
|
|
316
|
+
return self._get_ack(installation, req_json["ActionReference"])
|
|
317
|
+
|
|
318
|
+
def _get_ack(self, installation: DaisyInstallation, action_reference: str):
|
|
319
|
+
req = self.s.post(
|
|
320
|
+
base_url + "teleco/services/tmate20/getackcommand/",
|
|
321
|
+
json={
|
|
322
|
+
"id": action_reference,
|
|
323
|
+
"idInstallation": installation.instCode,
|
|
324
|
+
"idSession": self.idSession,
|
|
325
|
+
},
|
|
326
|
+
)
|
|
327
|
+
req_json = req.json()
|
|
328
|
+
assert req_json["MessageID"] == "WS-300"
|
|
329
|
+
if req_json["MessageText"] == "RCV":
|
|
330
|
+
sleep(0.5)
|
|
331
|
+
return self._get_ack(installation, action_reference)
|
|
332
|
+
if req_json["MessageText"] == "PROC":
|
|
333
|
+
return {"success": True}
|
|
334
|
+
return {"success": False}
|