pyephember2 0.4.1__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.
@@ -0,0 +1,5 @@
1
+ """
2
+ PyEphEmber interface implementation for https://ember.ephcontrols.com/
3
+ """
4
+
5
+ __all__ = ['pyephember2']
@@ -0,0 +1,869 @@
1
+ """
2
+ PyEphEmber interface implementation for https://ember.ephcontrols.com/
3
+ """
4
+ # pylint: disable=consider-using-f-string
5
+
6
+ import base64
7
+ import datetime
8
+ import json
9
+ import time
10
+ import collections
11
+
12
+ from enum import Enum
13
+
14
+ import requests
15
+ import paho.mqtt.client as mqtt
16
+
17
+
18
+ class ZoneMode(Enum):
19
+ """
20
+ Modes that a zone can be set too
21
+ """
22
+ # pylint: disable=invalid-name
23
+ AUTO = 0
24
+ ALL_DAY = 1
25
+ ON = 2
26
+ OFF = 3
27
+
28
+
29
+ class PointIndex(Enum):
30
+ """
31
+ Point indices for pointData returned by API
32
+ """
33
+ ADVANCE_ACTIVE = 4
34
+ CURRENT_TEMP = 5
35
+ TARGET_TEMP = 6
36
+ MODE = 7
37
+ BOOST_HOURS = 8
38
+ BOOST_TIME = 9
39
+ BOILER_STATE = 10
40
+ BOOST_TEMP = 14
41
+ CTR_15_ABAB = 15
42
+ XXX_16_0000 = 16
43
+ CTR_17_ABAB = 17
44
+ CTR_18_0AB7 = 18
45
+
46
+
47
+ # """
48
+ # Named tuple to hold a command to write data to a zone
49
+ # """
50
+ ZoneCommand = collections.namedtuple('ZoneCommand', ['name', 'value'])
51
+
52
+
53
+ def zone_command_to_ints(command):
54
+ """
55
+ Convert a ZoneCommand to an array of integers to send
56
+ """
57
+ type_data = {
58
+ 'SMALL_INT': {'id': 1, 'byte_len': 1},
59
+ 'TEMP_RO': {'id': 2, 'byte_len': 2},
60
+ 'TEMP_RW': {'id': 4, 'byte_len': 2},
61
+ 'TIMESTAMP': {'id': 5, 'byte_len': 4}
62
+ }
63
+ writable_command_types = {
64
+ 'ADVANCE_ACTIVE': 'SMALL_INT',
65
+ 'TARGET_TEMP': 'TEMP_RW',
66
+ 'MODE': 'SMALL_INT',
67
+ 'BOOST_HOURS': 'SMALL_INT',
68
+ 'BOOST_TIME': 'TIMESTAMP',
69
+ 'BOOST_TEMP': 'TEMP_RW'
70
+ }
71
+ if command.name not in writable_command_types:
72
+ raise ValueError(
73
+ "Cannot write to read-only value "
74
+ "{}".format(command.name)
75
+ )
76
+
77
+ command_type = writable_command_types[command.name]
78
+ command_index = PointIndex[command.name].value
79
+
80
+ # command header: [0, index, type_id]
81
+ int_array = [0, command_index, type_data[command_type]['id']]
82
+
83
+ # now encode and append the value
84
+ send_value = command.value
85
+ if command_type == 'TEMP_RW':
86
+ # The thermostat uses tenths of a degree;
87
+ # send_value is given in degrees, so we convert.
88
+ send_value = int(10*send_value)
89
+ elif command_type == 'TIMESTAMP':
90
+ # send_value can be either an int representing a Unix timestamp,
91
+ # or a datetime. Convert if a datetime.
92
+ if isinstance(command.value, datetime.datetime):
93
+ send_value = int(command.value.timestamp())
94
+
95
+ for byte_value in send_value.to_bytes(
96
+ type_data[command_type]['byte_len'], 'big'):
97
+ int_array.append(int(byte_value))
98
+
99
+ return int_array
100
+
101
+
102
+ def zone_is_active(zone):
103
+ """
104
+ Check if the zone is on.
105
+ This is a bit of a hack as the new API doesn't have a currently
106
+ active variable
107
+ """
108
+ if zone_is_scheduled_on(zone):
109
+ return True
110
+ # not sure how reliable the next tests are
111
+ return zone_boost_hours(zone) > 0 or zone_advance_active(zone)
112
+
113
+
114
+ def zone_advance_active(zone):
115
+ """
116
+ Check if zone has advance active
117
+ """
118
+ return zone_pointdata_value(zone, 'ADVANCE_ACTIVE') != 0
119
+
120
+
121
+ def boiler_state(zone):
122
+ """
123
+ Return the boiler state for a zone, as given by the API
124
+ Probable interpretation:
125
+ 0 => FIXME, 1 => flame off, 2 => flame on
126
+ """
127
+ return zone_pointdata_value(zone, 'BOILER_STATE')
128
+
129
+
130
+ def zone_is_scheduled_on(zone):
131
+ """
132
+ Check if zone is scheduled to be on
133
+ """
134
+ mode = zone_mode(zone)
135
+ if mode == ZoneMode.OFF:
136
+ return False
137
+
138
+ if mode == ZoneMode.ON:
139
+ return True
140
+
141
+ def scheduletime_to_time(stime):
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:]))
147
+
148
+ tstamp = time.gmtime(zone['timestamp']/1000)
149
+ ts_time = datetime.time(tstamp.tm_hour, tstamp.tm_min)
150
+ ts_wday = tstamp.tm_wday + 1
151
+ if ts_wday == 7:
152
+ ts_wday = 0
153
+
154
+ for day in zone['deviceDays']:
155
+ if day['dayType'] == ts_wday:
156
+ if mode == ZoneMode.AUTO:
157
+ for period in ['p1', 'p2', 'p3']:
158
+ start_time = scheduletime_to_time(day[period]['startTime'])
159
+ end_time = scheduletime_to_time(day[period]['endTime'])
160
+ if start_time <= ts_time <= end_time:
161
+ return True
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
167
+
168
+ return False
169
+
170
+
171
+ def zone_name(zone):
172
+ """
173
+ Get zone name
174
+ """
175
+ return zone["name"]
176
+
177
+
178
+ def zone_is_boost_active(zone):
179
+ """
180
+ Is the boost active for the zone
181
+ """
182
+ return zone_boost_hours(zone) > 0
183
+
184
+
185
+ def zone_boost_hours(zone):
186
+ """
187
+ Return zone boost hours
188
+ """
189
+ return zone_pointdata_value(zone, 'BOOST_HOURS')
190
+
191
+
192
+ def zone_boost_timestamp(zone):
193
+ """
194
+ Return zone boost hours
195
+ """
196
+ return zone_pointdata_value(zone, 'BOOST_TIME')
197
+
198
+
199
+ def zone_temperature(zone, label):
200
+ """
201
+ Return temperature (float) from the PointIndex value for label (str)
202
+ """
203
+ return zone_pointdata_value(zone, label)/10
204
+
205
+
206
+ def zone_target_temperature(zone):
207
+ """
208
+ Get target temperature for this zone
209
+ """
210
+ return zone_temperature(zone, 'TARGET_TEMP')
211
+
212
+
213
+ def zone_boost_temperature(zone):
214
+ """
215
+ Get target temperature for this zone
216
+ """
217
+ return zone_temperature(zone, 'BOOST_TEMP')
218
+
219
+
220
+ def zone_current_temperature(zone):
221
+ """
222
+ Get current temperature for this zone
223
+ """
224
+ return zone_temperature(zone, 'CURRENT_TEMP')
225
+
226
+
227
+ def zone_pointdata_value(zone, index):
228
+ """
229
+ Get value of given index for this zone, as an integer
230
+ index can be either an integer index, or a string label
231
+ from the PointIndex enum: 'ADVANCE_ACTIVE', 'CURRENT_TEMP', etc
232
+ """
233
+ # pylint: disable=unsubscriptable-object
234
+ if hasattr(PointIndex, index):
235
+ index = PointIndex[index].value
236
+
237
+ for datum in zone['pointDataList']:
238
+ if datum['pointIndex'] == index:
239
+ return int(datum['value'])
240
+
241
+ return None
242
+
243
+
244
+ def zone_mode(zone):
245
+ """
246
+ Get mode for this zone
247
+ """
248
+ return ZoneMode(zone_pointdata_value(zone, 'MODE'))
249
+
250
+
251
+ class EphMessenger:
252
+ """
253
+ MQTT interface to the EphEmber API
254
+ """
255
+
256
+ def _zone_command_b64(self, zone, cmd, stop_mqtt=True, timeout=1):
257
+ """
258
+ Send a base64-encoded MQTT command to a zone
259
+ Returns true if the command was published within the timeout
260
+ """
261
+ product_id = self.parent.get_home_details()['homes']['productId']
262
+ uid = self.parent.get_home_details()['homes']['uid']
263
+
264
+ msg = json.dumps(
265
+ {
266
+ "common": {
267
+ "serial": 7870,
268
+ "productId": product_id,
269
+ "uid": uid,
270
+ "timestamp": str(int(1000*time.time()))
271
+ },
272
+ "data": {
273
+ "mac": zone['mac'],
274
+ "pointData": cmd
275
+ }
276
+ }
277
+ )
278
+
279
+ started_locally = False
280
+ if not self.client or not self.client.is_connected():
281
+ started_locally = True
282
+ self.start()
283
+
284
+ pub = self.client.publish(
285
+ "/".join([product_id, uid, "download/pointdata"]), msg, 0
286
+ )
287
+ pub.wait_for_publish(timeout=timeout)
288
+
289
+ if started_locally and stop_mqtt:
290
+ self.stop()
291
+
292
+ return pub.is_published()
293
+
294
+ # Public interface
295
+
296
+ def start(self, callbacks=None, loop_start=False):
297
+ """
298
+ Start MQTT client
299
+ """
300
+ credentials = self.parent.messenging_credentials()
301
+ self.client_id = '{}_{}'.format(
302
+ credentials['user_id'], str(int(1000*time.time()))
303
+ )
304
+ token = credentials['token']
305
+
306
+ mclient = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, self.client_id)
307
+ mclient.tls_set()
308
+ self.client = mclient
309
+
310
+ user_name = "app/{}".format(token)
311
+ mclient.username_pw_set(user_name, token)
312
+
313
+ if callbacks is not None:
314
+ for key in callbacks.keys():
315
+ setattr(mclient, key, callbacks[key])
316
+
317
+ mclient.connect(self.api_url, self.api_port)
318
+
319
+ if loop_start:
320
+ mclient.loop_start()
321
+
322
+ return mclient
323
+
324
+ def stop(self):
325
+ """
326
+ Disconnect MQTT client if connected
327
+ """
328
+ if not self.client:
329
+ return False
330
+ if self.client.is_connected():
331
+ self.client.disconnect()
332
+ return True
333
+
334
+ def send_zone_commands(self, zone, commands, stop_mqtt=True, timeout=1):
335
+ """
336
+ Bundles the given array of ZoneCommand objects
337
+ to a single MQTT command and sends to the named zone.
338
+
339
+ If a single ZoneCommand is given, send just that.
340
+
341
+ Returns true if the bundled command was published within the timeout.
342
+
343
+ For example, to set target temperature to 19:
344
+
345
+ send_zone_command("Zone_name", ZoneCommand('TARGET_TEMP', 19))
346
+
347
+ """
348
+ def ints_to_b64_cmd(int_array):
349
+ """
350
+ Convert an array of integers to a byte array and
351
+ return its base64 string in ascii
352
+ """
353
+ return base64.b64encode(bytes(int_array)).decode("ascii")
354
+
355
+ if isinstance(commands, ZoneCommand):
356
+ commands = [commands]
357
+
358
+ ints_cmd = [
359
+ x for cmd in commands
360
+ for x in zone_command_to_ints(cmd)
361
+ ]
362
+
363
+ return self._zone_command_b64(
364
+ zone, ints_to_b64_cmd(ints_cmd), stop_mqtt, timeout
365
+ )
366
+
367
+ def __init__(self, parent):
368
+
369
+ self.api_url = 'eu-base-mqtt.topband-cloud.com'
370
+ self.api_port = 18883
371
+
372
+ self.client = None
373
+ self.client_id = None
374
+
375
+ self.parent = parent
376
+
377
+
378
+ class EphEmber:
379
+ """
380
+ Interacts with a EphEmber thermostat via API.
381
+ Example usage: t = EphEmber('me@somewhere.com', 'mypasswd')
382
+ t.get_zone_temperature('myzone') # Get temperature
383
+ """
384
+
385
+ # pylint: disable=too-many-public-methods
386
+
387
+ def _http(self, endpoint, *, method=requests.post, headers=None,
388
+ send_token=False, data=None, timeout=10):
389
+ """
390
+ Send a request to the http API endpoint
391
+ method should be requests.get or requests.post
392
+ """
393
+ if not headers:
394
+ headers = {}
395
+
396
+ if send_token:
397
+ if not self._do_auth():
398
+ raise RuntimeError("Unable to login")
399
+ headers["Authorization"] = self._login_data["data"]["token"]
400
+
401
+ headers["Content-Type"] = "application/json"
402
+ headers["Accept"] = "application/json"
403
+
404
+ url = "{}{}".format(self.http_api_base, endpoint)
405
+
406
+ if data and isinstance(data, dict):
407
+ data = json.dumps(data)
408
+
409
+ response = method(url, data=data, headers=headers, timeout=timeout)
410
+
411
+ if response.status_code != 200:
412
+ raise RuntimeError(
413
+ "{} response code".format(response.status_code)
414
+ )
415
+
416
+ return response
417
+
418
+ def _requires_refresh_token(self):
419
+ """
420
+ Check if a refresh of the token is needed
421
+ """
422
+ expires_on = self._login_data["last_refresh"] + \
423
+ datetime.timedelta(seconds=self._refresh_token_validity_seconds)
424
+ refresh = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
425
+ return expires_on < refresh
426
+
427
+ def _request_token(self, force=False):
428
+ """
429
+ Request a new auth token
430
+ """
431
+ if self._login_data is None:
432
+ raise RuntimeError("Don't have a token to refresh")
433
+
434
+ if not force:
435
+ if not self._requires_refresh_token():
436
+ # no need to refresh as token is valid
437
+ return True
438
+
439
+ response = self._http(
440
+ "appLogin/refreshAccessToken",
441
+ method=requests.get,
442
+ headers={'Authorization':
443
+ self._login_data['data']['refresh_token']}
444
+ )
445
+
446
+ refresh_data = response.json()
447
+
448
+ if 'token' not in refresh_data.get('data', {}):
449
+ return False
450
+
451
+ self._login_data['data'] = refresh_data['data']
452
+ self._login_data['last_refresh'] = datetime.datetime.utcnow()
453
+
454
+ return True
455
+
456
+ def _login(self):
457
+ """
458
+ Login using username / password and get the first auth token
459
+ """
460
+ self._login_data = None
461
+
462
+ response = self._http(
463
+ "appLogin/login",
464
+ data={
465
+ 'userName': self._user['username'],
466
+ 'password': self._user['password']
467
+ }
468
+ )
469
+
470
+ self._login_data = response.json()
471
+ if self._login_data['status'] != 0:
472
+ self._login_data = None
473
+ return False
474
+ self._login_data["last_refresh"] = datetime.datetime.utcnow()
475
+
476
+ if ('data' in self._login_data
477
+ and 'token' in self._login_data['data']):
478
+ return True
479
+
480
+ self._login_data = None
481
+ return False
482
+
483
+ def _do_auth(self):
484
+ """
485
+ Do authentication to the system (if required)
486
+ """
487
+ if self._login_data is None:
488
+ return self._login()
489
+
490
+ return self._request_token()
491
+
492
+ def _get_user_details(self):
493
+ """
494
+ Get user details [user/selectUser]
495
+ """
496
+ response = self._http(
497
+ "user/selectUser", method=requests.get,
498
+ send_token=True
499
+ )
500
+ user_details = response.json()
501
+ if user_details['status'] != 0:
502
+ return {}
503
+ return user_details
504
+
505
+ def _get_user_id(self, force=False):
506
+ """
507
+ Get user ID
508
+ """
509
+ if not force and self._user['user_id']:
510
+ return self._user['user_id']
511
+
512
+ user_details = self._get_user_details()
513
+ data = user_details.get('data', {})
514
+ if 'id' not in data:
515
+ raise RuntimeError("Cannot get user ID")
516
+ self._user['user_id'] = str(data['id'])
517
+ return self._user['user_id']
518
+
519
+ def _get_first_gateway_id(self):
520
+ """
521
+ Get the first gatewayid associated with the account
522
+ """
523
+ if not self._homes:
524
+ raise RuntimeError("Cannot get gateway id from list of homes.")
525
+ return self._homes[0]['gatewayid']
526
+
527
+ def _set_zone_target_temperature(self, zone, target_temperature):
528
+ return self.messenger.send_zone_commands(
529
+ zone,
530
+ ZoneCommand('TARGET_TEMP', target_temperature)
531
+ )
532
+
533
+ def _set_zone_boost_temperature(self, zone, target_temperature):
534
+ return self.messenger.send_zone_commands(
535
+ zone,
536
+ ZoneCommand('BOOST_TEMP', target_temperature)
537
+ )
538
+
539
+ def _set_zone_advance(self, zone, advance=True):
540
+ if advance:
541
+ advance = 1
542
+ else:
543
+ advance = 0
544
+ return self.messenger.send_zone_commands(
545
+ zone,
546
+ ZoneCommand('ADVANCE_ACTIVE', advance)
547
+ )
548
+
549
+ def _set_zone_boost(self, zone, boost_temperature, num_hours, timestamp=0):
550
+ """
551
+ Internal method to set zone boost
552
+
553
+ num_hours should be 0, 1, 2 or 3
554
+
555
+ If boost_temperature is not None, send that
556
+
557
+ If timestamp is 0 (or omitted), use current timestamp
558
+
559
+ If timestamp is None, do not send timestamp at all.
560
+ (maybe results in permanent boost?)
561
+ """
562
+ cmds = [ZoneCommand('BOOST_HOURS', num_hours)]
563
+ if boost_temperature is not None:
564
+ cmds.append(ZoneCommand('BOOST_TEMP', boost_temperature))
565
+ if timestamp is not None:
566
+ if timestamp == 0:
567
+ timestamp = int(datetime.datetime.now().timestamp())
568
+ cmds.append(ZoneCommand('BOOST_TIME', timestamp))
569
+ return self.messenger.send_zone_commands(zone, cmds)
570
+
571
+ def _set_zone_mode(self, zone, mode_num):
572
+ return self.messenger.send_zone_commands(
573
+ zone, ZoneCommand('MODE', mode_num)
574
+ )
575
+
576
+ # Public interface
577
+
578
+ def messenging_credentials(self):
579
+ """
580
+ Credentials required by EphMessenger
581
+ """
582
+ if not self._do_auth():
583
+ raise RuntimeError("Unable to login")
584
+
585
+ return {
586
+ 'user_id': self._get_user_id(),
587
+ 'token': self._login_data["data"]["token"]
588
+ }
589
+
590
+ def list_homes(self):
591
+ """
592
+ List the homes available for this user
593
+ """
594
+ response = self._http(
595
+ "homes/list", method=requests.get, send_token=True
596
+ )
597
+ homes = response.json()
598
+ status = homes.get('status', 1)
599
+ if status != 0:
600
+ raise RuntimeError("Error getting home: {}".format(status))
601
+
602
+ return homes.get("data", [])
603
+
604
+ def get_home_details(self, gateway_id=None, force=False):
605
+ """
606
+ Get the details about a home (API call: homes/detail)
607
+ If no gateway_id is passed, the first gateway found is used.
608
+ """
609
+ if self._home_details and not force:
610
+ return self._home_details
611
+
612
+ if gateway_id is None:
613
+ if not self._homes:
614
+ self._homes = self.list_homes()
615
+ gateway_id = self._get_first_gateway_id()
616
+
617
+ response = self._http(
618
+ "homes/detail", send_token=True,
619
+ data={"gateWayId": gateway_id}
620
+ )
621
+
622
+ home_details = response.json()
623
+
624
+ status = home_details.get('status', 1)
625
+ if status != 0:
626
+ raise RuntimeError(
627
+ "Error getting details from home: {}".format(status))
628
+
629
+ if "data" not in home_details or "homes" not in home_details["data"]:
630
+ raise RuntimeError(
631
+ "Error getting details from home: no home data found")
632
+
633
+ self._home_details = home_details['data']
634
+
635
+ return home_details["data"]
636
+ # ["homes"]
637
+
638
+ def get_home(self, gateway_id=None):
639
+ """
640
+ Get the data about a home (API call: homesVT/zoneProgram).
641
+ If no gateway_id is passed, the first gateway found is used.
642
+ """
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
+
648
+ response = self._http(
649
+ "homesVT/zoneProgram", send_token=True,
650
+ data={"gateWayId": gateway_id}
651
+ )
652
+
653
+ home = response.json()
654
+
655
+ status = home.get('status', 1)
656
+ if status != 0:
657
+ raise RuntimeError(
658
+ "Error getting zones from home: {}".format(status))
659
+
660
+ if "data" not in home:
661
+ raise RuntimeError(
662
+ "Error getting zones from home: no data found")
663
+ if "timestamp" not in home:
664
+ raise RuntimeError(
665
+ "Error getting zones from home: no timestamp found")
666
+
667
+ for zone in home["data"]:
668
+ zone["timestamp"] = home["timestamp"]
669
+
670
+ return home["data"]
671
+
672
+ def get_zones(self):
673
+ """
674
+ Get all zones
675
+ """
676
+ home_data = self.get_home()
677
+ if not home_data:
678
+ return []
679
+
680
+ return home_data
681
+
682
+ def get_zone_names(self):
683
+ """
684
+ Get the name of all zones
685
+ """
686
+ zone_names = []
687
+ for zone in self.get_zones():
688
+ zone_names.append(zone['name'])
689
+
690
+ return zone_names
691
+
692
+ def get_zone(self, name):
693
+ """
694
+ Get the information about a particular zone
695
+ """
696
+ for zone in self.get_zones():
697
+ if name == zone['name']:
698
+ return zone
699
+
700
+ raise RuntimeError("Unknown zone: %s" % name)
701
+
702
+ def is_zone_active(self, name):
703
+ """
704
+ Check if a zone is active
705
+ """
706
+ zone = self.get_zone(name)
707
+ return zone_is_active(zone)
708
+
709
+ def is_zone_boiler_on(self, name):
710
+ """
711
+ Check if the named zone's boiler is on and burning fuel (experimental)
712
+ """
713
+ zone = self.get_zone(name)
714
+ return boiler_state(zone) == 2
715
+
716
+ def get_zone_temperature(self, name):
717
+ """
718
+ Get the temperature for a zone
719
+ """
720
+ zone = self.get_zone(name)
721
+ return zone_current_temperature(zone)
722
+
723
+ def get_zone_target_temperature(self, name):
724
+ """
725
+ Get the temperature for a zone
726
+ """
727
+ zone = self.get_zone(name)
728
+ return zone_target_temperature(zone)
729
+
730
+ def get_zone_boost_temperature(self, name):
731
+ """
732
+ Get the boost target temperature for a zone
733
+ """
734
+ zone = self.get_zone(name)
735
+ return zone_boost_temperature(zone)
736
+
737
+ def is_boost_active(self, name):
738
+ """
739
+ Check if boost is active for a zone
740
+ """
741
+ zone = self.get_zone(name)
742
+ return zone_is_boost_active(zone)
743
+
744
+ def boost_hours(self, name):
745
+ """
746
+ Get the boost duration for a zone, in hours
747
+ """
748
+ zone = self.get_zone(name)
749
+ return zone_boost_hours(zone)
750
+
751
+ def boost_timestamp(self, name):
752
+ """
753
+ Get the timestamp recorded for the boost
754
+ """
755
+ zone = self.get_zone(name)
756
+ return datetime.datetime.fromtimestamp(zone_boost_timestamp(zone))
757
+
758
+ def is_target_temperature_reached(self, name):
759
+ """
760
+ Check if a zone temperature has reached the target temperature
761
+ """
762
+ zone = self.get_zone(name)
763
+ return zone_current_temperature(zone) >= zone_target_temperature(zone)
764
+
765
+ def set_zone_target_temperature(self, name, target_temperature):
766
+ """
767
+ Set the target temperature for a named zone
768
+ """
769
+ zone = self.get_zone(name)
770
+ return self._set_zone_target_temperature(
771
+ zone, target_temperature
772
+ )
773
+
774
+ def set_zone_boost_temperature(self, name, target_temperature):
775
+ """
776
+ Set the boost target temperature for a named zone
777
+ """
778
+ zone = self.get_zone(name)
779
+ return self._set_zone_boost_temperature(
780
+ zone, target_temperature
781
+ )
782
+
783
+ def set_zone_advance(self, name, advance_state=True):
784
+ """
785
+ Set the advance state for a named zone
786
+ """
787
+ zone = self.get_zone(name)
788
+ return self._set_zone_advance(
789
+ zone, advance_state
790
+ )
791
+
792
+ def activate_zone_boost(self, name, boost_temperature=None,
793
+ num_hours=1, timestamp=0):
794
+ """
795
+ Turn on boost for a named zone
796
+
797
+ If boost_temperature is not None, send that
798
+
799
+ If timestamp is 0 (or omitted), use current timestamp
800
+
801
+ If timestamp is None, do not send timestamp at all.
802
+ (maybe results in permanent boost?)
803
+
804
+ """
805
+ return self._set_zone_boost(
806
+ self.get_zone(name), boost_temperature,
807
+ num_hours, timestamp=timestamp
808
+ )
809
+
810
+ def deactivate_zone_boost(self, zone):
811
+ """
812
+ Turn off boost for a named zone
813
+ """
814
+ return self.activate_zone_boost(zone, num_hours=0, timestamp=None)
815
+
816
+ def set_zone_mode(self, name, mode):
817
+ """
818
+ Set the mode by using the name of the zone
819
+ Supported zones are available in the enum ZoneMode
820
+ """
821
+ if isinstance(mode, int):
822
+ mode = ZoneMode(mode)
823
+
824
+ assert isinstance(mode, ZoneMode)
825
+
826
+ return self._set_zone_mode(
827
+ self.get_zone(name), mode.value
828
+ )
829
+
830
+ def get_zone_mode(self, name):
831
+ """
832
+ Get the mode for a zone
833
+ """
834
+ zone = self.get_zone(name)
835
+ return zone_mode(zone)
836
+
837
+ def reset_login(self):
838
+ """
839
+ reset the login data to force a re-login
840
+ """
841
+ self._login_data = None
842
+
843
+ # Ctor
844
+ def __init__(self, username, password, cache_home=False):
845
+ """Performs login and save session cookie."""
846
+
847
+ if cache_home:
848
+ raise RuntimeError("cache_home not implemented")
849
+
850
+ self._login_data = None
851
+ self._user = {
852
+ 'user_id': None,
853
+ 'username': username,
854
+ 'password': password
855
+ }
856
+
857
+ # This is the list of homes / gateways associated with the account.
858
+ self._homes = None
859
+
860
+ self._home_details = None
861
+
862
+ self._refresh_token_validity_seconds = 1800
863
+
864
+ self.http_api_base = 'https://eu-https.topband-cloud.com/ember-back/'
865
+
866
+ self.messenger = EphMessenger(self)
867
+
868
+ if not self._login():
869
+ raise RuntimeError("Unable to login.")
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Thom Troy
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,23 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyephember2
3
+ Version: 0.4.1
4
+ Summary: Python library to work with ember from EPH Controls
5
+ Home-page: https://github.com/roberty99/pyephember2
6
+ Download-URL: https://github.com/roberty99/pyephember2/archive/0.4.1.tar.gz
7
+ Author: Robert Young
8
+ Author-email: youngro@tcd.ie
9
+ License: MIT
10
+ Keywords: eph ember
11
+ Platform: any
12
+ License-File: LICENSE.txt
13
+ Requires-Dist: requests
14
+ Requires-Dist: paho-mqtt
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: download-url
18
+ Dynamic: home-page
19
+ Dynamic: keywords
20
+ Dynamic: license
21
+ Dynamic: platform
22
+ Dynamic: requires-dist
23
+ Dynamic: summary
@@ -0,0 +1,7 @@
1
+ pyephember2/__init__.py,sha256=q4WqeyE3g1Ijz3PqXCf3sgLRHE0A8evBZjDHk0QT4OU,106
2
+ pyephember2/pyephember.py,sha256=PmiEgGCSVO-UG8CkKh3tEWCZobshehd9t6SLT-1_lPY,24415
3
+ pyephember2-0.4.1.dist-info/LICENSE.txt,sha256=MJzeRc3fQG1ksdHpi5sMKqUILbqB3j6kdP39pB_0BSM,1066
4
+ pyephember2-0.4.1.dist-info/METADATA,sha256=xtlAJ4o1HkNnrSrTyThdgotFazDCzO0mUsAcQYHpSZ0,588
5
+ pyephember2-0.4.1.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
6
+ pyephember2-0.4.1.dist-info/top_level.txt,sha256=H_R27Jh1rzunJbgCKqtM8Pwld1saWurmolbFmNrWIfo,12
7
+ pyephember2-0.4.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pyephember2