emerald-hws 0.0.7__py3-none-any.whl → 0.0.8__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.
emerald_hws/emeraldhws.py CHANGED
@@ -4,6 +4,7 @@ import os
4
4
  import logging
5
5
  import boto3
6
6
  import random
7
+ import threading
7
8
  from awsiot import mqtt5_client_builder, mqtt_connection_builder
8
9
  from awscrt import mqtt5, http, auth, io
9
10
 
@@ -21,10 +22,11 @@ class EmeraldHWS():
21
22
  MQTT_HOST = "a13v32g67itvz9-ats.iot.ap-southeast-2.amazonaws.com"
22
23
  COGNITO_IDENTITY_POOL_ID = "ap-southeast-2:f5bbb02c-c00e-4f10-acb3-e7d1b05268e8"
23
24
 
24
- def __init__(self, email, password):
25
+ def __init__(self, email, password, update_callback=None):
25
26
  """ Initialise the API client
26
27
  :param email: The email address for logging into the Emerald app
27
28
  :param password: The password for the supplied user account
29
+ :param update_callback: Optional callback function to be called when an update is available
28
30
  """
29
31
 
30
32
  self.email = email
@@ -32,6 +34,7 @@ class EmeraldHWS():
32
34
  self.token = ""
33
35
  self.properties = {}
34
36
  self.logger = logging.getLogger()
37
+ self.update_callback = update_callback
35
38
 
36
39
  def getLoginToken(self):
37
40
  """ Performs an API request to get a token from the API
@@ -78,6 +81,15 @@ class EmeraldHWS():
78
81
  else:
79
82
  raise Exception("Unable to fetch properties from Emerald API")
80
83
 
84
+ def reconnectMQTT(self):
85
+ """ Stops an existing MQTT connection and creates a new one
86
+ """
87
+
88
+ self.logger.debug("emeraldhws: awsiot: Tearing down and reconnecting to prevent stale connection")
89
+ self.mqttClient.stop()
90
+ self.connectMQTT()
91
+ self.subscribeAllHWS()
92
+
81
93
  def connectMQTT(self):
82
94
  """ Establishes a connection to Amazon IOT core's MQTT service
83
95
  """
@@ -113,6 +125,7 @@ class EmeraldHWS():
113
125
 
114
126
  client.start()
115
127
  self.mqttClient = client
128
+ threading.Timer(43200.0, self.reconnectMQTT).start() # 12 hours
116
129
 
117
130
  def mqttDecodeUpdate(self, topic, payload):
118
131
  """ Attempt to decode a received MQTT message and direct appropriately
@@ -188,6 +201,8 @@ class EmeraldHWS():
188
201
  for heat_pump in heat_pumps:
189
202
  if heat_pump['id'] == id:
190
203
  heat_pump['last_state'][key] = value
204
+ if self.update_callback != None:
205
+ self.update_callback()
191
206
 
192
207
  def subscribeForUpdates(self, id):
193
208
  """ Subscribes to the MQTT topics for the supplied HWS
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: emerald_hws
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: A package to manipulate and monitor Emerald Heat Pump Hot Water Systems
5
5
  Author-email: Ross Williamson <ross@inertia.net.nz>
6
6
  Project-URL: Homepage, https://github.com/ross-w/emerald_hws_py
@@ -0,0 +1,8 @@
1
+ emerald_hws/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
2
+ emerald_hws/emeraldhws.py,sha256=tsTBTs0ZrBgAkvERT6FqYI8iNqFEkg4LvLijnsWp3eY,13892
3
+ emerald_hws/__assets__/SFSRootCAG2.pem,sha256=hw9W0AnYrrlbcWsOewAgIl1ULEsoO57Ylu35dCjWcS4,1424
4
+ emerald_hws-0.0.8.dist-info/LICENSE,sha256=zzMi56JX7OO-epbXNfe_oFW6sfZHSlO7Yxm0Oh0V014,1072
5
+ emerald_hws-0.0.8.dist-info/METADATA,sha256=4AvoaGEg0ITTsgGTW24_mbDu83ECe-ovrE0c5VQgKms,688
6
+ emerald_hws-0.0.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ emerald_hws-0.0.8.dist-info/top_level.txt,sha256=ZCiUmnBkDr2n4QVkTet1s_AKiGJjuz3heuCR5w5ZqLY,12
8
+ emerald_hws-0.0.8.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- emerald_hws/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
2
- emerald_hws/emeraldhws.py,sha256=0qbkwKatdNqf8UP6STo3mlIG-X5ZNuLNyqerQVuUgOQ,13251
3
- emerald_hws/__assets__/SFSRootCAG2.pem,sha256=hw9W0AnYrrlbcWsOewAgIl1ULEsoO57Ylu35dCjWcS4,1424
4
- emerald_hws-0.0.7.dist-info/LICENSE,sha256=zzMi56JX7OO-epbXNfe_oFW6sfZHSlO7Yxm0Oh0V014,1072
5
- emerald_hws-0.0.7.dist-info/METADATA,sha256=UjewZVJkndoOV--3AIHOXPjwvnaDo35E0kHkLmi74hI,688
6
- emerald_hws-0.0.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
- emerald_hws-0.0.7.dist-info/top_level.txt,sha256=ZCiUmnBkDr2n4QVkTet1s_AKiGJjuz3heuCR5w5ZqLY,12
8
- emerald_hws-0.0.7.dist-info/RECORD,,