emerald-hws 0.0.3__tar.gz → 0.0.5__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.
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/PKG-INFO +1 -1
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/pyproject.toml +1 -1
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws/emeraldhws.py +50 -16
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/PKG-INFO +1 -1
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/LICENSE +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/README.md +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/setup.cfg +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws/__assets__/SFSRootCAG2.pem +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws/__init__.py +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/SOURCES.txt +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/dependency_links.txt +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/requires.txt +0 -0
- {emerald_hws-0.0.3 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: emerald_hws
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
import requests
|
3
3
|
import os
|
4
|
-
|
4
|
+
import logging
|
5
5
|
import boto3
|
6
6
|
import random
|
7
7
|
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
|
@@ -30,6 +30,8 @@ class EmeraldHWS():
|
|
30
30
|
self.password = password
|
31
31
|
self.token = ""
|
32
32
|
self.properties = {}
|
33
|
+
self.logger = logging.getLogger()
|
34
|
+
self.logger.setLevel(logging.DEBUG)
|
33
35
|
|
34
36
|
def getLoginToken(self):
|
35
37
|
""" Performs an API request to get a token from the API
|
@@ -52,6 +54,7 @@ class EmeraldHWS():
|
|
52
54
|
post_response_json = post_response.json()
|
53
55
|
if post_response_json.get("code") == 200:
|
54
56
|
self.token = post_response_json.get("token")
|
57
|
+
return True
|
55
58
|
else:
|
56
59
|
raise Exception("Failed to log into Emerald API with supplied credentials")
|
57
60
|
|
@@ -70,31 +73,42 @@ class EmeraldHWS():
|
|
70
73
|
post_response_json = post_response.json()
|
71
74
|
|
72
75
|
if post_response_json.get("code") == 200:
|
76
|
+
self.logger.debug("Successfully logged into Emerald API")
|
73
77
|
self.properties = post_response_json.get("info").get("property")
|
74
78
|
else:
|
75
79
|
raise Exception("Unable to fetch properties from Emerald API")
|
76
80
|
|
77
|
-
def
|
78
|
-
"""
|
81
|
+
def getTemporaryCreds(self):
|
82
|
+
""" Returns temporary credentials for IoT Core
|
79
83
|
"""
|
80
84
|
|
81
|
-
cert_path = os.path.join(os.path.dirname(__file__), '__assets__', 'SFSRootCAG2.pem')
|
82
|
-
|
83
|
-
# Cognito auth
|
84
85
|
identityPoolID = self.COGNITO_IDENTITY_POOL_ID
|
85
86
|
region = self.MQTT_HOST.split('.')[2]
|
86
87
|
cognitoIdentityClient = boto3.client('cognito-identity', region_name=region)
|
87
88
|
|
88
89
|
temporaryIdentityId = cognitoIdentityClient.get_id(IdentityPoolId=identityPoolID)
|
89
90
|
identityID = temporaryIdentityId["IdentityId"]
|
91
|
+
self.logger.debug("AWS IoT IdentityID: {}".format(identityID))
|
90
92
|
|
91
93
|
temporaryCredentials = cognitoIdentityClient.get_credentials_for_identity(IdentityId=identityID)
|
92
|
-
|
93
|
-
|
94
|
-
|
94
|
+
self.logger.debug("Got new temporary credentials for AWS")
|
95
|
+
self.identityID = identityID
|
96
|
+
self.temporaryCredentials = temporaryCredentials
|
97
|
+
|
98
|
+
|
99
|
+
def connectMQTT(self):
|
100
|
+
""" Establishes a connection to Amazon IOT core's MQTT service
|
101
|
+
"""
|
102
|
+
|
103
|
+
cert_path = os.path.join(os.path.dirname(__file__), '__assets__', 'SFSRootCAG2.pem')
|
104
|
+
self.getTemporaryCreds()
|
105
|
+
|
106
|
+
AccessKeyId = self.temporaryCredentials["Credentials"]["AccessKeyId"]
|
107
|
+
SecretKey = self.temporaryCredentials["Credentials"]["SecretKey"]
|
108
|
+
SessionToken = self.temporaryCredentials["Credentials"]["SessionToken"]
|
95
109
|
|
96
110
|
# Init AWSIoTMQTTClient
|
97
|
-
myAWSIoTMQTTClient = AWSIoTMQTTClient(identityID, useWebsocket=True)
|
111
|
+
myAWSIoTMQTTClient = AWSIoTMQTTClient(self.identityID, useWebsocket=True)
|
98
112
|
|
99
113
|
# AWSIoTMQTTClient configuration
|
100
114
|
myAWSIoTMQTTClient.configureEndpoint(self.MQTT_HOST, 443)
|
@@ -105,7 +119,8 @@ class EmeraldHWS():
|
|
105
119
|
myAWSIoTMQTTClient.configureDrainingFrequency(2) # Draining: 2 Hz
|
106
120
|
myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10) # 10 sec
|
107
121
|
myAWSIoTMQTTClient.configureMQTTOperationTimeout(10) # 10 sec
|
108
|
-
|
122
|
+
myAWSIoTMQTTClient.onOffline = self.on_offline
|
123
|
+
myAWSIoTMQTTClient.onOnline = self.on_online
|
109
124
|
# Connect and subscribe to AWS IoT
|
110
125
|
myAWSIoTMQTTClient.connect()
|
111
126
|
|
@@ -126,14 +141,28 @@ class EmeraldHWS():
|
|
126
141
|
self.updateHWSState(hws_id, key, json_payload[1][key])
|
127
142
|
|
128
143
|
def mqttCallback(self, client, userdata, message):
|
129
|
-
|
130
|
-
|
131
|
-
# print("from topic: ")
|
132
|
-
# print(message.topic)
|
133
|
-
# print("--------------\n\n")
|
144
|
+
""" Calls decode update for received message
|
145
|
+
"""
|
134
146
|
|
147
|
+
self.logger.debug("Received message from MQTT topic {}: {}".format(message.topic,message.payload.decode("utf-8")))
|
135
148
|
self.mqttDecodeUpdate(message.topic, message.payload)
|
136
149
|
|
150
|
+
def on_offline(self):
|
151
|
+
""" Reconfigures temporary credentials
|
152
|
+
"""
|
153
|
+
|
154
|
+
self.logger.debug("AWS IoT offline")
|
155
|
+
self.getTemporaryCreds()
|
156
|
+
AccessKeyId = self.temporaryCredentials["Credentials"]["AccessKeyId"]
|
157
|
+
SecretKey = self.temporaryCredentials["Credentials"]["SecretKey"]
|
158
|
+
SessionToken = self.temporaryCredentials["Credentials"]["SessionToken"]
|
159
|
+
self.myAWSIoTMQTTClient.configureIAMCredentials(AccessKeyId, SecretKey, SessionToken)
|
160
|
+
|
161
|
+
def on_online(self):
|
162
|
+
""" Logs online state
|
163
|
+
"""
|
164
|
+
self.logger.debug("AWS IoT online")
|
165
|
+
|
137
166
|
def updateHWSState(self, id, key, value):
|
138
167
|
""" Updates the specified value for the supplied key in the HWS id specified
|
139
168
|
:param id: ID of the HWS
|
@@ -200,30 +229,35 @@ class EmeraldHWS():
|
|
200
229
|
""" Turns the specified HWS on
|
201
230
|
:param id: The UUID of the HWS to turn on
|
202
231
|
"""
|
232
|
+
self.logger.debug("Sending control message: turn on")
|
203
233
|
self.sendControlMessage(id, {"switch":1})
|
204
234
|
|
205
235
|
def turnOff(self, id):
|
206
236
|
""" Turns the specified HWS off
|
207
237
|
:param id: The UUID of the HWS to turn off
|
208
238
|
"""
|
239
|
+
self.logger.debug("Sending control message: turn off")
|
209
240
|
self.sendControlMessage(id, {"switch":0})
|
210
241
|
|
211
242
|
def setNormalMode(self, id):
|
212
243
|
""" Sets the specified HWS to normal (not Boost or Quiet) mode
|
213
244
|
:param id: The UUID of the HWS to set to normal mode
|
214
245
|
"""
|
246
|
+
self.logger.debug("Sending control message: normal mode")
|
215
247
|
self.sendControlMessage(id, {"mode":1})
|
216
248
|
|
217
249
|
def setBoostMode(self, id):
|
218
250
|
""" Sets the specified HWS to boost (high power) mode
|
219
251
|
:param id: The UUID of the HWS to set to boost mode
|
220
252
|
"""
|
253
|
+
self.logger.debug("Sending control message: boost mode")
|
221
254
|
self.sendControlMessage(id, {"mode":0})
|
222
255
|
|
223
256
|
def setQuietMode(self, id):
|
224
257
|
""" Sets the specified HWS to quiet (low power) mode
|
225
258
|
:param id: The UUID of the HWS to set to quiet mode
|
226
259
|
"""
|
260
|
+
self.logger.debug("Sending control message: quiet mode")
|
227
261
|
self.sendControlMessage(id, {"mode":2})
|
228
262
|
|
229
263
|
def isOn(self, id):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: emerald_hws
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|