emerald-hws 0.0.7__tar.gz → 0.0.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: emerald_hws
3
- Version: 0.0.7
3
+ Version: 0.0.9
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
@@ -4,14 +4,9 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "emerald_hws"
7
- version = "0.0.7"
8
- dependencies = [
9
- "boto3",
10
- "awsiotsdk"
11
- ]
12
- authors = [
13
- { name="Ross Williamson", email="ross@inertia.net.nz" },
14
- ]
7
+ version = "0.0.9"
8
+ dependencies = ["boto3", "awsiotsdk"]
9
+ authors = [{ name = "Ross Williamson", email = "ross@inertia.net.nz" }]
15
10
  description = "A package to manipulate and monitor Emerald Heat Pump Hot Water Systems"
16
11
  readme = "README.md"
17
12
  requires-python = ">=3.7"
@@ -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,21 @@ class EmeraldHWS():
78
81
  else:
79
82
  raise Exception("Unable to fetch properties from Emerald API")
80
83
 
84
+ def replaceCallback(self, update_callback):
85
+ """ Replaces the current registered update callback (if any) with the supplied
86
+ """
87
+
88
+ self.update_callback = update_callback
89
+
90
+ def reconnectMQTT(self):
91
+ """ Stops an existing MQTT connection and creates a new one
92
+ """
93
+
94
+ self.logger.debug("emeraldhws: awsiot: Tearing down and reconnecting to prevent stale connection")
95
+ self.mqttClient.stop()
96
+ self.connectMQTT()
97
+ self.subscribeAllHWS()
98
+
81
99
  def connectMQTT(self):
82
100
  """ Establishes a connection to Amazon IOT core's MQTT service
83
101
  """
@@ -113,6 +131,7 @@ class EmeraldHWS():
113
131
 
114
132
  client.start()
115
133
  self.mqttClient = client
134
+ threading.Timer(43200.0, self.reconnectMQTT).start() # 12 hours
116
135
 
117
136
  def mqttDecodeUpdate(self, topic, payload):
118
137
  """ Attempt to decode a received MQTT message and direct appropriately
@@ -188,6 +207,8 @@ class EmeraldHWS():
188
207
  for heat_pump in heat_pumps:
189
208
  if heat_pump['id'] == id:
190
209
  heat_pump['last_state'][key] = value
210
+ if self.update_callback != None:
211
+ self.update_callback()
191
212
 
192
213
  def subscribeForUpdates(self, id):
193
214
  """ 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.9
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
File without changes
File without changes
File without changes