pyephember2 0.4.2__tar.gz → 0.4.4__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.
- {pyephember2-0.4.2 → pyephember2-0.4.4}/PKG-INFO +2 -2
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2/pyephember2.py +400 -117
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/PKG-INFO +2 -2
- {pyephember2-0.4.2 → pyephember2-0.4.4}/setup.py +2 -2
- {pyephember2-0.4.2 → pyephember2-0.4.4}/LICENSE.txt +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/README.md +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2/__init__.py +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/SOURCES.txt +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/dependency_links.txt +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/not-zip-safe +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/requires.txt +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/pyephember2.egg-info/top_level.txt +0 -0
- {pyephember2-0.4.2 → pyephember2-0.4.4}/setup.cfg +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: pyephember2
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Python library to work with ember from EPH Controls
|
|
5
5
|
Home-page: https://github.com/roberty99/pyephember2
|
|
6
|
-
Download-URL: https://github.com/roberty99/pyephember2/archive/0.4.
|
|
6
|
+
Download-URL: https://github.com/roberty99/pyephember2/archive/0.4.3.tar.gz
|
|
7
7
|
Author: Robert Young
|
|
8
8
|
Author-email: youngro@tcd.ie
|
|
9
9
|
License: MIT
|
|
@@ -10,6 +10,7 @@ import time
|
|
|
10
10
|
import collections
|
|
11
11
|
|
|
12
12
|
from enum import Enum
|
|
13
|
+
from typing import OrderedDict
|
|
13
14
|
|
|
14
15
|
import requests
|
|
15
16
|
import paho.mqtt.client as mqtt
|
|
@@ -19,6 +20,7 @@ class ZoneMode(Enum):
|
|
|
19
20
|
"""
|
|
20
21
|
Modes that a zone can be set too
|
|
21
22
|
"""
|
|
23
|
+
|
|
22
24
|
# pylint: disable=invalid-name
|
|
23
25
|
AUTO = 0
|
|
24
26
|
ALL_DAY = 1
|
|
@@ -26,10 +28,57 @@ class ZoneMode(Enum):
|
|
|
26
28
|
OFF = 3
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
def GetPointIndex(zone, pointIndex) -> int:
|
|
32
|
+
assert isinstance(pointIndex, PointIndex)
|
|
33
|
+
match pointIndex:
|
|
34
|
+
case PointIndex.ADVANCE_ACTIVE:
|
|
35
|
+
return 4
|
|
36
|
+
case PointIndex.CURRENT_TEMP:
|
|
37
|
+
return 5
|
|
38
|
+
case PointIndex.TARGET_TEMP:
|
|
39
|
+
match zone["deviceType"]:
|
|
40
|
+
case 773:
|
|
41
|
+
return 12
|
|
42
|
+
case _:
|
|
43
|
+
return 6
|
|
44
|
+
case PointIndex.MODE:
|
|
45
|
+
match zone['deviceType']:
|
|
46
|
+
case 514 | 773:
|
|
47
|
+
return 11
|
|
48
|
+
case 2 | 4:
|
|
49
|
+
return 7
|
|
50
|
+
case _:
|
|
51
|
+
return 7
|
|
52
|
+
case PointIndex.BOOST_HOURS:
|
|
53
|
+
match zone["deviceType"]:
|
|
54
|
+
case 514 | 773:
|
|
55
|
+
# Returns 0 if boost is OFF and 1 if ON
|
|
56
|
+
return 13
|
|
57
|
+
case _:
|
|
58
|
+
return 8
|
|
59
|
+
case PointIndex.BOOST_TIME:
|
|
60
|
+
return 9
|
|
61
|
+
case PointIndex.BOILER_STATE:
|
|
62
|
+
return 10
|
|
63
|
+
case PointIndex.BOOST_TEMP:
|
|
64
|
+
return 14
|
|
65
|
+
case PointIndex.CTR_15_ABAB:
|
|
66
|
+
return 15
|
|
67
|
+
case PointIndex.XXX_16_0000:
|
|
68
|
+
return 16
|
|
69
|
+
case PointIndex.CTR_17_ABAB:
|
|
70
|
+
return 17
|
|
71
|
+
case PointIndex.CTR_18_0AB7:
|
|
72
|
+
return 18
|
|
73
|
+
case _:
|
|
74
|
+
RuntimeError('Unknown PointIndex:' + pointIndex)
|
|
75
|
+
|
|
76
|
+
|
|
29
77
|
class PointIndex(Enum):
|
|
30
78
|
"""
|
|
31
79
|
Point indices for pointData returned by API
|
|
32
80
|
"""
|
|
81
|
+
|
|
33
82
|
ADVANCE_ACTIVE = 4
|
|
34
83
|
CURRENT_TEMP = 5
|
|
35
84
|
TARGET_TEMP = 6
|
|
@@ -47,10 +96,10 @@ class PointIndex(Enum):
|
|
|
47
96
|
# """
|
|
48
97
|
# Named tuple to hold a command to write data to a zone
|
|
49
98
|
# """
|
|
50
|
-
ZoneCommand = collections.namedtuple('ZoneCommand', ['name', 'value'])
|
|
99
|
+
ZoneCommand = collections.namedtuple('ZoneCommand', ['name', 'value', 'index'])
|
|
51
100
|
|
|
52
101
|
|
|
53
|
-
def zone_command_to_ints(command):
|
|
102
|
+
def zone_command_to_ints(zone, command):
|
|
54
103
|
"""
|
|
55
104
|
Convert a ZoneCommand to an array of integers to send
|
|
56
105
|
"""
|
|
@@ -73,9 +122,13 @@ def zone_command_to_ints(command):
|
|
|
73
122
|
"Cannot write to read-only value "
|
|
74
123
|
"{}".format(command.name)
|
|
75
124
|
)
|
|
76
|
-
|
|
125
|
+
|
|
77
126
|
command_type = writable_command_types[command.name]
|
|
78
|
-
|
|
127
|
+
|
|
128
|
+
if command.index is not None:
|
|
129
|
+
command_index = command.index
|
|
130
|
+
else:
|
|
131
|
+
command_index = GetPointIndex(zone, PointIndex[command.name])
|
|
79
132
|
|
|
80
133
|
# command header: [0, index, type_id]
|
|
81
134
|
int_array = [0, command_index, type_data[command_type]['id']]
|
|
@@ -115,7 +168,15 @@ def zone_advance_active(zone):
|
|
|
115
168
|
"""
|
|
116
169
|
Check if zone has advance active
|
|
117
170
|
"""
|
|
118
|
-
|
|
171
|
+
match zone["deviceType"]:
|
|
172
|
+
case 773:
|
|
173
|
+
# Mode not supported
|
|
174
|
+
return False
|
|
175
|
+
case 514:
|
|
176
|
+
# Need to fix, point index or value is not right
|
|
177
|
+
return False
|
|
178
|
+
case _:
|
|
179
|
+
return zone_pointdata_value(zone, PointIndex.ADVANCE_ACTIVE) != 0
|
|
119
180
|
|
|
120
181
|
|
|
121
182
|
def boiler_state(zone):
|
|
@@ -124,8 +185,88 @@ def boiler_state(zone):
|
|
|
124
185
|
Probable interpretation:
|
|
125
186
|
0 => FIXME, 1 => flame off, 2 => flame on
|
|
126
187
|
"""
|
|
127
|
-
return zone_pointdata_value(zone,
|
|
188
|
+
return zone_pointdata_value(zone, PointIndex.BOILER_STATE)
|
|
189
|
+
|
|
190
|
+
def lastKey(dict):
|
|
191
|
+
return list(dict.keys())[-1]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def firstKey(dict):
|
|
195
|
+
return list(dict.keys())[0]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def try_parse_int(value):
|
|
199
|
+
try:
|
|
200
|
+
return int(value), True
|
|
201
|
+
except ValueError:
|
|
202
|
+
return None, False
|
|
203
|
+
|
|
204
|
+
def scheduletime_to_time(dict, key_name):
|
|
205
|
+
"""
|
|
206
|
+
Convert a schedule start/end time (an integer) to a Python time
|
|
207
|
+
For example, x = 173 is converted to 17:30
|
|
208
|
+
"""
|
|
209
|
+
if dict.get(key_name) is None:
|
|
210
|
+
return None
|
|
211
|
+
stime = dict[key_name]
|
|
212
|
+
if stime is None:
|
|
213
|
+
return None
|
|
214
|
+
return datetime.time(int(str(stime)[:-1]), 10 * int(str(stime)[-1:]))
|
|
215
|
+
|
|
216
|
+
def getZoneTime(zone):
|
|
217
|
+
tstamp = time.gmtime(zone["timestamp"] / 1000)
|
|
218
|
+
ts_time = datetime.time(tstamp.tm_hour, tstamp.tm_min)
|
|
219
|
+
ts_wday = tstamp.tm_wday + 1
|
|
220
|
+
if ts_wday == 7:
|
|
221
|
+
ts_wday = 0
|
|
222
|
+
return [ts_time, ts_wday]
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def zone_get_running_day(zone):
|
|
226
|
+
todaysDay = zone["days"][getZoneTime(zone)[1]]
|
|
227
|
+
return todaysDay
|
|
228
|
+
|
|
229
|
+
def zone_get_running_program(zone):
|
|
230
|
+
mode = zone_mode(zone)
|
|
231
|
+
ts_time = getZoneTime(zone)[0]
|
|
232
|
+
|
|
233
|
+
todaysDay = zone_get_running_day(zone)
|
|
234
|
+
if todaysDay is None:
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
if mode == ZoneMode.AUTO:
|
|
238
|
+
for key in todaysDay["programs"]:
|
|
239
|
+
program = todaysDay["programs"][key]
|
|
240
|
+
start_time = scheduletime_to_time(program, "startTime")
|
|
241
|
+
end_time = scheduletime_to_time(program, "endTime")
|
|
242
|
+
p_time = scheduletime_to_time(program, "time")
|
|
243
|
+
if (
|
|
244
|
+
start_time is not None
|
|
245
|
+
and end_time is not None
|
|
246
|
+
and start_time <= ts_time <= end_time
|
|
247
|
+
):
|
|
248
|
+
return program
|
|
249
|
+
elif p_time is not None and p_time >= ts_time:
|
|
250
|
+
# some devices using different programm logic
|
|
251
|
+
# P1 contains only activation time and target temp, need to find currently running program by searching previous programm.
|
|
252
|
+
# Ex: Today is Day 2 9:00am, P1 in that day starts at 10am, current programm is last P from Day 1
|
|
253
|
+
runningProgram = program["Prev"]
|
|
254
|
+
return [runningProgram, program]
|
|
255
|
+
# program not found in that day
|
|
256
|
+
# last program active
|
|
257
|
+
lastProg = todaysDay["programs"][lastKey(todaysDay["programs"])]
|
|
258
|
+
|
|
259
|
+
if lastProg.get("time") is None:
|
|
260
|
+
return lastProg
|
|
261
|
+
else:
|
|
262
|
+
return [lastProg, lastProg["Next"]]
|
|
263
|
+
|
|
264
|
+
elif mode == ZoneMode.ALL_DAY:
|
|
265
|
+
startProgram = todaysDay["programs"][firstKey(todaysDay["programs"])]
|
|
266
|
+
endProgram = todaysDay["programs"][lastKey(todaysDay["programs"])]
|
|
267
|
+
return [startProgram, endProgram]
|
|
128
268
|
|
|
269
|
+
return None
|
|
129
270
|
|
|
130
271
|
def zone_is_scheduled_on(zone):
|
|
131
272
|
"""
|
|
@@ -138,32 +279,43 @@ def zone_is_scheduled_on(zone):
|
|
|
138
279
|
if mode == ZoneMode.ON:
|
|
139
280
|
return True
|
|
140
281
|
|
|
141
|
-
|
|
142
|
-
"""
|
|
143
|
-
Convert a schedule start/end time (an integer) to a Python time
|
|
144
|
-
For example, x = 173 is converted to 17:30
|
|
145
|
-
"""
|
|
146
|
-
return datetime.time(int(str(stime)[:-1]), 10*int(str(stime)[-1:]))
|
|
282
|
+
ts_time = getZoneTime(zone)[0]
|
|
147
283
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
284
|
+
if mode == ZoneMode.AUTO:
|
|
285
|
+
runningPrograms = zone_get_running_program(zone)
|
|
286
|
+
if runningPrograms is None:
|
|
287
|
+
return False
|
|
288
|
+
elif type(runningPrograms) is list:
|
|
289
|
+
# some devices using different programm logic
|
|
290
|
+
# P1 contains only activation time and target temp, need to find currently running program by searching previous programm.
|
|
291
|
+
# Ex: Today is Day 2 9:00am, P1 in that day starts at 10am, current programm is last P from Day 1
|
|
292
|
+
currentTemp = zone_current_temperature(zone)
|
|
293
|
+
targetTemp = runningPrograms[0]["temperature"] / 10
|
|
294
|
+
|
|
295
|
+
# Current program found, check if current temp ( minus offset 0.3->0.7 deg after temp was reached) < target temp
|
|
296
|
+
# NB! Some devices like eTrv have settings to adjust turn on/off temperature offcet (not available in Ember app).
|
|
297
|
+
if currentTemp + 0.3 < targetTemp:
|
|
298
|
+
return True
|
|
299
|
+
else:
|
|
300
|
+
return False
|
|
301
|
+
else:
|
|
302
|
+
start_time = scheduletime_to_time(runningPrograms, "startTime")
|
|
303
|
+
end_time = scheduletime_to_time(runningPrograms, "endTime")
|
|
304
|
+
if (
|
|
305
|
+
start_time is not None
|
|
306
|
+
and end_time is not None
|
|
307
|
+
and start_time <= ts_time <= end_time
|
|
308
|
+
):
|
|
309
|
+
return True
|
|
153
310
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
elif mode == ZoneMode.ALL_DAY:
|
|
163
|
-
start_time = scheduletime_to_time(day['p1']['startTime'])
|
|
164
|
-
end_time = scheduletime_to_time(day['p3']['endTime'])
|
|
165
|
-
if start_time <= ts_time <= end_time:
|
|
166
|
-
return True
|
|
311
|
+
elif mode == ZoneMode.ALL_DAY:
|
|
312
|
+
runningPrograms = zone_get_running_program(zone)
|
|
313
|
+
first_start_time = scheduletime_to_time(runningPrograms[0], "startTime")
|
|
314
|
+
last_end_time = scheduletime_to_time(runningPrograms[1], "endTime")
|
|
315
|
+
if first_start_time is None or last_end_time is None:
|
|
316
|
+
return False
|
|
317
|
+
if first_start_time <= ts_time <= last_end_time:
|
|
318
|
+
return True
|
|
167
319
|
|
|
168
320
|
return False
|
|
169
321
|
|
|
@@ -186,53 +338,61 @@ def zone_boost_hours(zone):
|
|
|
186
338
|
"""
|
|
187
339
|
Return zone boost hours
|
|
188
340
|
"""
|
|
189
|
-
return zone_pointdata_value(zone,
|
|
341
|
+
return zone_pointdata_value(zone, PointIndex.BOOST_HOURS)
|
|
190
342
|
|
|
191
343
|
|
|
192
344
|
def zone_boost_timestamp(zone):
|
|
193
345
|
"""
|
|
194
346
|
Return zone boost hours
|
|
195
347
|
"""
|
|
196
|
-
return zone_pointdata_value(zone,
|
|
348
|
+
return zone_pointdata_value(zone, PointIndex.BOOST_TIME)
|
|
197
349
|
|
|
198
350
|
|
|
199
351
|
def zone_temperature(zone, label):
|
|
200
352
|
"""
|
|
201
353
|
Return temperature (float) from the PointIndex value for label (str)
|
|
202
354
|
"""
|
|
203
|
-
|
|
204
|
-
|
|
355
|
+
if zone["deviceType"] == 773:
|
|
356
|
+
# in auto mode need to find program target temp.
|
|
357
|
+
if zone_mode(zone) == ZoneMode.AUTO and label == PointIndex.TARGET_TEMP:
|
|
358
|
+
programs = zone_get_running_program(zone)
|
|
359
|
+
if programs is not None:
|
|
360
|
+
return programs[0]["temperature"] / 10
|
|
361
|
+
else:
|
|
362
|
+
return None
|
|
363
|
+
else:
|
|
364
|
+
return zone_pointdata_value(zone, PointIndex(label)) / 10
|
|
365
|
+
else:
|
|
366
|
+
return zone_pointdata_value(zone, PointIndex(label)) / 10
|
|
205
367
|
|
|
206
368
|
def zone_target_temperature(zone):
|
|
207
369
|
"""
|
|
208
370
|
Get target temperature for this zone
|
|
209
371
|
"""
|
|
210
|
-
return zone_temperature(zone,
|
|
211
|
-
|
|
372
|
+
return zone_temperature(zone, PointIndex.TARGET_TEMP)
|
|
212
373
|
|
|
213
374
|
def zone_boost_temperature(zone):
|
|
214
375
|
"""
|
|
215
376
|
Get target temperature for this zone
|
|
216
377
|
"""
|
|
217
|
-
return zone_temperature(zone,
|
|
378
|
+
return zone_temperature(zone, PointIndex.BOOST_TEMP)
|
|
218
379
|
|
|
219
380
|
|
|
220
381
|
def zone_current_temperature(zone):
|
|
221
382
|
"""
|
|
222
383
|
Get current temperature for this zone
|
|
223
384
|
"""
|
|
224
|
-
return zone_temperature(zone,
|
|
385
|
+
return zone_temperature(zone, PointIndex.CURRENT_TEMP)
|
|
225
386
|
|
|
226
387
|
|
|
227
|
-
def zone_pointdata_value(zone,
|
|
388
|
+
def zone_pointdata_value(zone, pointIndex):
|
|
228
389
|
"""
|
|
229
390
|
Get value of given index for this zone, as an integer
|
|
230
391
|
index can be either an integer index, or a string label
|
|
231
392
|
from the PointIndex enum: 'ADVANCE_ACTIVE', 'CURRENT_TEMP', etc
|
|
232
393
|
"""
|
|
233
394
|
# pylint: disable=unsubscriptable-object
|
|
234
|
-
|
|
235
|
-
index = PointIndex[index].value
|
|
395
|
+
index = GetPointIndex(zone, pointIndex)
|
|
236
396
|
|
|
237
397
|
for datum in zone['pointDataList']:
|
|
238
398
|
if datum['pointIndex'] == index:
|
|
@@ -244,8 +404,70 @@ def zone_pointdata_value(zone, index):
|
|
|
244
404
|
def zone_mode(zone):
|
|
245
405
|
"""
|
|
246
406
|
Get mode for this zone
|
|
407
|
+
Default settings based on next known devices
|
|
408
|
+
deviceTypes 2 | 4:
|
|
409
|
+
AUTO = 0
|
|
410
|
+
ALL_DAY = 1
|
|
411
|
+
ON = 2
|
|
412
|
+
OFF = 3
|
|
413
|
+
|
|
414
|
+
deviceTypes 773:
|
|
415
|
+
AUTO = 0
|
|
416
|
+
ON/Manual = 1
|
|
417
|
+
BOOST = 0 ? Could be another point index
|
|
418
|
+
OFF = 4
|
|
419
|
+
|
|
420
|
+
deviceTypes 514:
|
|
421
|
+
AUTO = 0
|
|
422
|
+
ADVANCE = 0 ? Could be another point index
|
|
423
|
+
ALL_DAY = 9
|
|
424
|
+
ON/Manual = 10
|
|
425
|
+
BOOST = 0 ? Could be another point index
|
|
426
|
+
OFF = 4
|
|
247
427
|
"""
|
|
248
|
-
|
|
428
|
+
|
|
429
|
+
modeValue = zone_pointdata_value(zone, PointIndex.MODE)
|
|
430
|
+
match modeValue:
|
|
431
|
+
case 0:
|
|
432
|
+
return ZoneMode.AUTO
|
|
433
|
+
case 1 | 9:
|
|
434
|
+
match zone["deviceType"]:
|
|
435
|
+
case 773:
|
|
436
|
+
return ZoneMode.ON
|
|
437
|
+
case _:
|
|
438
|
+
return ZoneMode.ALL_DAY
|
|
439
|
+
case 2 | 10:
|
|
440
|
+
return ZoneMode.ON
|
|
441
|
+
case 3 | 4:
|
|
442
|
+
return ZoneMode.OFF
|
|
443
|
+
|
|
444
|
+
def get_zone_mode_value(zone, mode) -> int:
|
|
445
|
+
if mode == ZoneMode.AUTO:
|
|
446
|
+
return 0
|
|
447
|
+
|
|
448
|
+
match zone['deviceType']:
|
|
449
|
+
case 773:
|
|
450
|
+
match mode:
|
|
451
|
+
case ZoneMode.ON:
|
|
452
|
+
return 1
|
|
453
|
+
case ZoneMode.OFF:
|
|
454
|
+
return 4
|
|
455
|
+
case 514:
|
|
456
|
+
match mode:
|
|
457
|
+
case ZoneMode.ALL_DAY:
|
|
458
|
+
return 9
|
|
459
|
+
case ZoneMode.ON:
|
|
460
|
+
return 10
|
|
461
|
+
case ZoneMode.OFF:
|
|
462
|
+
return 4
|
|
463
|
+
case _:
|
|
464
|
+
match mode:
|
|
465
|
+
case ZoneMode.ALL_DAY:
|
|
466
|
+
return 1
|
|
467
|
+
case ZoneMode.ON:
|
|
468
|
+
return 2
|
|
469
|
+
case ZoneMode.OFF:
|
|
470
|
+
return 3
|
|
249
471
|
|
|
250
472
|
|
|
251
473
|
class EphMessenger:
|
|
@@ -258,8 +480,8 @@ class EphMessenger:
|
|
|
258
480
|
Send a base64-encoded MQTT command to a zone
|
|
259
481
|
Returns true if the command was published within the timeout
|
|
260
482
|
"""
|
|
261
|
-
product_id =
|
|
262
|
-
uid =
|
|
483
|
+
product_id = zone["productId"]
|
|
484
|
+
uid = zone["uid"]
|
|
263
485
|
|
|
264
486
|
msg = json.dumps(
|
|
265
487
|
{
|
|
@@ -355,17 +577,13 @@ class EphMessenger:
|
|
|
355
577
|
if isinstance(commands, ZoneCommand):
|
|
356
578
|
commands = [commands]
|
|
357
579
|
|
|
358
|
-
ints_cmd = [
|
|
359
|
-
x for cmd in commands
|
|
360
|
-
for x in zone_command_to_ints(cmd)
|
|
361
|
-
]
|
|
580
|
+
ints_cmd = [x for cmd in commands for x in zone_command_to_ints(zone, cmd)]
|
|
362
581
|
|
|
363
582
|
return self._zone_command_b64(
|
|
364
583
|
zone, ints_to_b64_cmd(ints_cmd), stop_mqtt, timeout
|
|
365
584
|
)
|
|
366
585
|
|
|
367
586
|
def __init__(self, parent):
|
|
368
|
-
|
|
369
587
|
self.api_url = 'eu-base-mqtt.topband-cloud.com'
|
|
370
588
|
self.api_port = 18883
|
|
371
589
|
|
|
@@ -527,7 +745,7 @@ class EphEmber:
|
|
|
527
745
|
def _set_zone_target_temperature(self, zone, target_temperature):
|
|
528
746
|
return self.messenger.send_zone_commands(
|
|
529
747
|
zone,
|
|
530
|
-
ZoneCommand('TARGET_TEMP', target_temperature)
|
|
748
|
+
ZoneCommand('TARGET_TEMP', target_temperature, GetPointIndex(zone, PointIndex.TARGET_TEMP))
|
|
531
749
|
)
|
|
532
750
|
|
|
533
751
|
def _set_zone_boost_temperature(self, zone, target_temperature):
|
|
@@ -568,9 +786,9 @@ class EphEmber:
|
|
|
568
786
|
cmds.append(ZoneCommand('BOOST_TIME', timestamp))
|
|
569
787
|
return self.messenger.send_zone_commands(zone, cmds)
|
|
570
788
|
|
|
571
|
-
def _set_zone_mode(self, zone, mode_num):
|
|
789
|
+
def _set_zone_mode(self, zone, mode_num, index):
|
|
572
790
|
return self.messenger.send_zone_commands(
|
|
573
|
-
zone, ZoneCommand('MODE', mode_num)
|
|
791
|
+
zone, ZoneCommand('MODE', mode_num, index)
|
|
574
792
|
)
|
|
575
793
|
|
|
576
794
|
# Public interface
|
|
@@ -633,47 +851,107 @@ class EphEmber:
|
|
|
633
851
|
self._home_details = home_details['data']
|
|
634
852
|
|
|
635
853
|
return home_details["data"]
|
|
636
|
-
# ["homes"]
|
|
637
854
|
|
|
638
|
-
def
|
|
855
|
+
def lastKey(dict):
|
|
856
|
+
return list(dict.keys())[-1]
|
|
857
|
+
|
|
858
|
+
def firstKey(dict):
|
|
859
|
+
return list(dict.keys())[0]
|
|
860
|
+
|
|
861
|
+
# ["homes"]
|
|
862
|
+
def get_homes(self):
|
|
639
863
|
"""
|
|
640
864
|
Get the data about a home (API call: homesVT/zoneProgram).
|
|
641
|
-
If no gateway_id is passed, the first gateway found is used.
|
|
642
865
|
"""
|
|
643
|
-
if gateway_id is None:
|
|
644
|
-
if not self._homes:
|
|
645
|
-
self._homes = self.list_homes()
|
|
646
|
-
gateway_id = self._get_first_gateway_id()
|
|
647
866
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
)
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
status = home.get('status', 1)
|
|
656
|
-
if status != 0:
|
|
657
|
-
raise RuntimeError(
|
|
658
|
-
"Error getting zones from home: {}".format(status))
|
|
867
|
+
if (
|
|
868
|
+
self.NextHomeUpdateDaytime is None
|
|
869
|
+
or datetime.datetime.now() > self.NextHomeUpdateDaytime
|
|
870
|
+
):
|
|
871
|
+
self._homes = self.list_homes()
|
|
872
|
+
else:
|
|
873
|
+
return self._homes
|
|
659
874
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if "timestamp" not in home:
|
|
664
|
-
raise RuntimeError(
|
|
665
|
-
"Error getting zones from home: no timestamp found")
|
|
875
|
+
for home in self._homes:
|
|
876
|
+
home["zones"] = []
|
|
877
|
+
gateway_id = home["gatewayid"]
|
|
666
878
|
|
|
667
|
-
|
|
668
|
-
|
|
879
|
+
response = self._http(
|
|
880
|
+
"homesVT/zoneProgram", send_token=True, data={"gateWayId": gateway_id}
|
|
881
|
+
)
|
|
669
882
|
|
|
670
|
-
|
|
883
|
+
homezones = response.json()
|
|
884
|
+
|
|
885
|
+
status = homezones.get("status", 1)
|
|
886
|
+
if status != 0:
|
|
887
|
+
raise RuntimeError("Error getting zones from home: {}".format(status))
|
|
888
|
+
|
|
889
|
+
if "data" not in homezones:
|
|
890
|
+
raise RuntimeError("Error getting zones from home: no data found")
|
|
891
|
+
if "timestamp" not in homezones:
|
|
892
|
+
raise RuntimeError("Error getting zones from home: no timestamp found")
|
|
893
|
+
|
|
894
|
+
for zone in homezones["data"]:
|
|
895
|
+
# build programs
|
|
896
|
+
zone["days"] = {}
|
|
897
|
+
prevProgramm = None
|
|
898
|
+
for day in sorted(
|
|
899
|
+
zone["deviceDays"], key=lambda x: x["dayType"], reverse=False
|
|
900
|
+
):
|
|
901
|
+
day["programs"] = {}
|
|
902
|
+
keys = day.keys()
|
|
903
|
+
for key in keys:
|
|
904
|
+
if key.startswith("p"):
|
|
905
|
+
tryGetId = try_parse_int(key[1:])
|
|
906
|
+
if tryGetId[1]:
|
|
907
|
+
programm = day[key]
|
|
908
|
+
if programm is not None:
|
|
909
|
+
if prevProgramm is not None:
|
|
910
|
+
programm["Prev"] = prevProgramm
|
|
911
|
+
programm["Count"] = tryGetId[0]
|
|
912
|
+
prevProgramm = programm
|
|
913
|
+
day["programs"][tryGetId[0]] = programm
|
|
914
|
+
zone["days"][day["dayType"]] = day
|
|
915
|
+
# reverse loop to connect all Prev programs
|
|
916
|
+
lastProgramm = None
|
|
917
|
+
firstProgramm = None
|
|
918
|
+
for day in OrderedDict(sorted(zone["days"].items(), reverse=True)):
|
|
919
|
+
if lastProgramm is not None:
|
|
920
|
+
firstProgramm = zone["days"][day]["programs"][
|
|
921
|
+
lastKey(zone["days"][day]["programs"])
|
|
922
|
+
]
|
|
923
|
+
lastProgramm["Prev"] = firstProgramm
|
|
924
|
+
lastProgramm = zone["days"][day]["programs"][
|
|
925
|
+
firstKey(zone["days"][day]["programs"])
|
|
926
|
+
]
|
|
927
|
+
|
|
928
|
+
lastProgramm["Prev"] = firstProgramm
|
|
929
|
+
|
|
930
|
+
firstDayPrograms = zone["days"][firstKey(zone["days"])]["programs"]
|
|
931
|
+
firstProgram = firstDayPrograms[firstKey(firstDayPrograms)]
|
|
932
|
+
nextProgram = firstProgram
|
|
933
|
+
for day in OrderedDict(sorted(zone["days"].items(), reverse=True)):
|
|
934
|
+
orderedProgs = OrderedDict(
|
|
935
|
+
sorted(zone["days"][day]["programs"].items(), reverse=True)
|
|
936
|
+
)
|
|
937
|
+
for progNum in orderedProgs:
|
|
938
|
+
program = zone["days"][day]["programs"][progNum]
|
|
939
|
+
program["Next"] = nextProgram
|
|
940
|
+
nextProgram = program
|
|
941
|
+
|
|
942
|
+
zone["timestamp"] = homezones["timestamp"]
|
|
943
|
+
home["zones"].append(zone)
|
|
944
|
+
|
|
945
|
+
self.NextHomeUpdateDaytime = datetime.datetime.now() + datetime.timedelta(
|
|
946
|
+
seconds=10
|
|
947
|
+
)
|
|
948
|
+
return self._homes
|
|
671
949
|
|
|
672
950
|
def get_zones(self):
|
|
673
951
|
"""
|
|
674
952
|
Get all zones
|
|
675
953
|
"""
|
|
676
|
-
home_data = self.
|
|
954
|
+
home_data = self.get_homes()
|
|
677
955
|
if not home_data:
|
|
678
956
|
return []
|
|
679
957
|
|
|
@@ -689,107 +967,108 @@ class EphEmber:
|
|
|
689
967
|
|
|
690
968
|
return zone_names
|
|
691
969
|
|
|
692
|
-
def get_zone(self,
|
|
970
|
+
def get_zone(self, zoneid):
|
|
693
971
|
"""
|
|
694
972
|
Get the information about a particular zone
|
|
695
973
|
"""
|
|
696
|
-
for
|
|
697
|
-
|
|
698
|
-
|
|
974
|
+
for home in self.get_zones():
|
|
975
|
+
for zone in home['zones']:
|
|
976
|
+
if zoneid == zone['zoneid']:
|
|
977
|
+
return zone
|
|
699
978
|
|
|
700
|
-
raise RuntimeError("Unknown zone: %s" %
|
|
979
|
+
raise RuntimeError("Unknown zone: %s" % zoneid)
|
|
701
980
|
|
|
702
|
-
def is_zone_active(self,
|
|
981
|
+
def is_zone_active(self, zoneid):
|
|
703
982
|
"""
|
|
704
983
|
Check if a zone is active
|
|
705
984
|
"""
|
|
706
|
-
zone = self.get_zone(
|
|
985
|
+
zone = self.get_zone(zoneid)
|
|
707
986
|
return zone_is_active(zone)
|
|
708
987
|
|
|
709
|
-
def is_zone_boiler_on(self,
|
|
988
|
+
def is_zone_boiler_on(self, zoneid):
|
|
710
989
|
"""
|
|
711
990
|
Check if the named zone's boiler is on and burning fuel (experimental)
|
|
712
991
|
"""
|
|
713
|
-
zone = self.get_zone(
|
|
992
|
+
zone = self.get_zone(zoneid)
|
|
714
993
|
return boiler_state(zone) == 2
|
|
715
994
|
|
|
716
|
-
def get_zone_temperature(self,
|
|
995
|
+
def get_zone_temperature(self, zoneid):
|
|
717
996
|
"""
|
|
718
997
|
Get the temperature for a zone
|
|
719
998
|
"""
|
|
720
|
-
zone = self.get_zone(
|
|
999
|
+
zone = self.get_zone(zoneid)
|
|
721
1000
|
return zone_current_temperature(zone)
|
|
722
1001
|
|
|
723
|
-
def get_zone_target_temperature(self,
|
|
1002
|
+
def get_zone_target_temperature(self, zoneid):
|
|
724
1003
|
"""
|
|
725
1004
|
Get the temperature for a zone
|
|
726
1005
|
"""
|
|
727
|
-
zone = self.get_zone(
|
|
1006
|
+
zone = self.get_zone(zoneid)
|
|
728
1007
|
return zone_target_temperature(zone)
|
|
729
1008
|
|
|
730
|
-
def get_zone_boost_temperature(self,
|
|
1009
|
+
def get_zone_boost_temperature(self, zoneid):
|
|
731
1010
|
"""
|
|
732
1011
|
Get the boost target temperature for a zone
|
|
733
1012
|
"""
|
|
734
|
-
zone = self.get_zone(
|
|
1013
|
+
zone = self.get_zone(zoneid)
|
|
735
1014
|
return zone_boost_temperature(zone)
|
|
736
1015
|
|
|
737
|
-
def is_boost_active(self,
|
|
1016
|
+
def is_boost_active(self, zoneid):
|
|
738
1017
|
"""
|
|
739
1018
|
Check if boost is active for a zone
|
|
740
1019
|
"""
|
|
741
|
-
zone = self.get_zone(
|
|
1020
|
+
zone = self.get_zone(zoneid)
|
|
742
1021
|
return zone_is_boost_active(zone)
|
|
743
1022
|
|
|
744
|
-
def boost_hours(self,
|
|
1023
|
+
def boost_hours(self, zoneid):
|
|
745
1024
|
"""
|
|
746
1025
|
Get the boost duration for a zone, in hours
|
|
747
1026
|
"""
|
|
748
|
-
zone = self.get_zone(
|
|
1027
|
+
zone = self.get_zone(zoneid)
|
|
749
1028
|
return zone_boost_hours(zone)
|
|
750
1029
|
|
|
751
|
-
def boost_timestamp(self,
|
|
1030
|
+
def boost_timestamp(self, zoneid):
|
|
752
1031
|
"""
|
|
753
1032
|
Get the timestamp recorded for the boost
|
|
754
1033
|
"""
|
|
755
|
-
zone = self.get_zone(
|
|
1034
|
+
zone = self.get_zone(zoneid)
|
|
756
1035
|
return datetime.datetime.fromtimestamp(zone_boost_timestamp(zone))
|
|
757
1036
|
|
|
758
|
-
def is_target_temperature_reached(self,
|
|
1037
|
+
def is_target_temperature_reached(self, zoneid):
|
|
759
1038
|
"""
|
|
760
1039
|
Check if a zone temperature has reached the target temperature
|
|
761
1040
|
"""
|
|
762
|
-
zone = self.get_zone(
|
|
1041
|
+
zone = self.get_zone(zoneid)
|
|
763
1042
|
return zone_current_temperature(zone) >= zone_target_temperature(zone)
|
|
764
1043
|
|
|
765
|
-
def set_zone_target_temperature(self,
|
|
1044
|
+
def set_zone_target_temperature(self, zoneid, target_temperature):
|
|
766
1045
|
"""
|
|
767
1046
|
Set the target temperature for a named zone
|
|
768
1047
|
"""
|
|
769
|
-
zone = self.get_zone(
|
|
1048
|
+
zone = self.get_zone(zoneid)
|
|
770
1049
|
return self._set_zone_target_temperature(
|
|
771
1050
|
zone, target_temperature
|
|
772
1051
|
)
|
|
773
1052
|
|
|
774
|
-
def set_zone_boost_temperature(self,
|
|
1053
|
+
def set_zone_boost_temperature(self, zoneid, target_temperature):
|
|
775
1054
|
"""
|
|
776
1055
|
Set the boost target temperature for a named zone
|
|
777
1056
|
"""
|
|
778
|
-
zone = self.get_zone(
|
|
1057
|
+
zone = self.get_zone(zoneid)
|
|
779
1058
|
return self._set_zone_boost_temperature(
|
|
780
1059
|
zone, target_temperature
|
|
781
1060
|
)
|
|
782
1061
|
|
|
783
|
-
def set_zone_advance(self,
|
|
1062
|
+
def set_zone_advance(self, zoneid, advance_state=True):
|
|
784
1063
|
"""
|
|
785
1064
|
Set the advance state for a named zone
|
|
786
1065
|
"""
|
|
787
|
-
zone = self.get_zone(
|
|
1066
|
+
zone = self.get_zone(zoneid)
|
|
788
1067
|
return self._set_zone_advance(
|
|
789
1068
|
zone, advance_state
|
|
790
1069
|
)
|
|
791
1070
|
|
|
792
|
-
def activate_zone_boost(self,
|
|
1071
|
+
def activate_zone_boost(self, zoneid, boost_temperature=None,
|
|
793
1072
|
num_hours=1, timestamp=0):
|
|
794
1073
|
"""
|
|
795
1074
|
Turn on boost for a named zone
|
|
@@ -803,7 +1082,7 @@ class EphEmber:
|
|
|
803
1082
|
|
|
804
1083
|
"""
|
|
805
1084
|
return self._set_zone_boost(
|
|
806
|
-
self.get_zone(
|
|
1085
|
+
self.get_zone(zoneid), boost_temperature,
|
|
807
1086
|
num_hours, timestamp=timestamp
|
|
808
1087
|
)
|
|
809
1088
|
|
|
@@ -813,25 +1092,27 @@ class EphEmber:
|
|
|
813
1092
|
"""
|
|
814
1093
|
return self.activate_zone_boost(zone, num_hours=0, timestamp=None)
|
|
815
1094
|
|
|
816
|
-
def set_zone_mode(self,
|
|
1095
|
+
def set_zone_mode(self, zoneid, mode):
|
|
817
1096
|
"""
|
|
818
1097
|
Set the mode by using the name of the zone
|
|
819
1098
|
Supported zones are available in the enum ZoneMode
|
|
820
1099
|
"""
|
|
821
|
-
if isinstance(mode, int):
|
|
822
|
-
mode = ZoneMode(mode)
|
|
823
1100
|
|
|
824
1101
|
assert isinstance(mode, ZoneMode)
|
|
825
1102
|
|
|
1103
|
+
zone = self.get_zone(zoneid)
|
|
1104
|
+
modevalue = get_zone_mode_value(zone, mode)
|
|
1105
|
+
modeindex = GetPointIndex(zone, PointIndex.MODE)
|
|
1106
|
+
|
|
826
1107
|
return self._set_zone_mode(
|
|
827
|
-
self.get_zone(
|
|
1108
|
+
self.get_zone(zoneid), modevalue, modeindex
|
|
828
1109
|
)
|
|
829
1110
|
|
|
830
|
-
def get_zone_mode(self,
|
|
1111
|
+
def get_zone_mode(self, zoneid):
|
|
831
1112
|
"""
|
|
832
1113
|
Get the mode for a zone
|
|
833
1114
|
"""
|
|
834
|
-
zone = self.get_zone(
|
|
1115
|
+
zone = self.get_zone(zoneid)
|
|
835
1116
|
return zone_mode(zone)
|
|
836
1117
|
|
|
837
1118
|
def reset_login(self):
|
|
@@ -859,6 +1140,8 @@ class EphEmber:
|
|
|
859
1140
|
|
|
860
1141
|
self._home_details = None
|
|
861
1142
|
|
|
1143
|
+
self.NextHomeUpdateDaytime = None
|
|
1144
|
+
|
|
862
1145
|
self._refresh_token_validity_seconds = 1800
|
|
863
1146
|
|
|
864
1147
|
self.http_api_base = 'https://eu-https.topband-cloud.com/ember-back/'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: pyephember2
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Python library to work with ember from EPH Controls
|
|
5
5
|
Home-page: https://github.com/roberty99/pyephember2
|
|
6
|
-
Download-URL: https://github.com/roberty99/pyephember2/archive/0.4.
|
|
6
|
+
Download-URL: https://github.com/roberty99/pyephember2/archive/0.4.3.tar.gz
|
|
7
7
|
Author: Robert Young
|
|
8
8
|
Author-email: youngro@tcd.ie
|
|
9
9
|
License: MIT
|
|
@@ -2,14 +2,14 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='pyephember2',
|
|
5
|
-
version='0.4.
|
|
5
|
+
version='0.4.4',
|
|
6
6
|
description='Python library to work with ember from EPH Controls',
|
|
7
7
|
keywords='ephember',
|
|
8
8
|
author='Robert Young',
|
|
9
9
|
author_email='youngro@tcd.ie',
|
|
10
10
|
license='MIT',
|
|
11
11
|
url='https://github.com/roberty99/pyephember2',
|
|
12
|
-
download_url='https://github.com/roberty99/pyephember2/archive/0.4.
|
|
12
|
+
download_url='https://github.com/roberty99/pyephember2/archive/0.4.3.tar.gz',
|
|
13
13
|
platforms=["any"],
|
|
14
14
|
packages=find_packages(),
|
|
15
15
|
zip_safe=False,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|