emerald-hws 0.0.4__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.4 → emerald_hws-0.0.5}/PKG-INFO +1 -1
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/pyproject.toml +1 -1
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws/emeraldhws.py +49 -16
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/PKG-INFO +1 -1
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/LICENSE +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/README.md +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/setup.cfg +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws/__assets__/SFSRootCAG2.pem +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws/__init__.py +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/SOURCES.txt +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/dependency_links.txt +0 -0
- {emerald_hws-0.0.4 → emerald_hws-0.0.5}/src/emerald_hws.egg-info/requires.txt +0 -0
- {emerald_hws-0.0.4 → 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
|
@@ -71,31 +73,42 @@ class EmeraldHWS():
|
|
71
73
|
post_response_json = post_response.json()
|
72
74
|
|
73
75
|
if post_response_json.get("code") == 200:
|
76
|
+
self.logger.debug("Successfully logged into Emerald API")
|
74
77
|
self.properties = post_response_json.get("info").get("property")
|
75
78
|
else:
|
76
79
|
raise Exception("Unable to fetch properties from Emerald API")
|
77
80
|
|
78
|
-
def
|
79
|
-
"""
|
81
|
+
def getTemporaryCreds(self):
|
82
|
+
""" Returns temporary credentials for IoT Core
|
80
83
|
"""
|
81
84
|
|
82
|
-
cert_path = os.path.join(os.path.dirname(__file__), '__assets__', 'SFSRootCAG2.pem')
|
83
|
-
|
84
|
-
# Cognito auth
|
85
85
|
identityPoolID = self.COGNITO_IDENTITY_POOL_ID
|
86
86
|
region = self.MQTT_HOST.split('.')[2]
|
87
87
|
cognitoIdentityClient = boto3.client('cognito-identity', region_name=region)
|
88
88
|
|
89
89
|
temporaryIdentityId = cognitoIdentityClient.get_id(IdentityPoolId=identityPoolID)
|
90
90
|
identityID = temporaryIdentityId["IdentityId"]
|
91
|
+
self.logger.debug("AWS IoT IdentityID: {}".format(identityID))
|
91
92
|
|
92
93
|
temporaryCredentials = cognitoIdentityClient.get_credentials_for_identity(IdentityId=identityID)
|
93
|
-
|
94
|
-
|
95
|
-
|
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"]
|
96
109
|
|
97
110
|
# Init AWSIoTMQTTClient
|
98
|
-
myAWSIoTMQTTClient = AWSIoTMQTTClient(identityID, useWebsocket=True)
|
111
|
+
myAWSIoTMQTTClient = AWSIoTMQTTClient(self.identityID, useWebsocket=True)
|
99
112
|
|
100
113
|
# AWSIoTMQTTClient configuration
|
101
114
|
myAWSIoTMQTTClient.configureEndpoint(self.MQTT_HOST, 443)
|
@@ -106,7 +119,8 @@ class EmeraldHWS():
|
|
106
119
|
myAWSIoTMQTTClient.configureDrainingFrequency(2) # Draining: 2 Hz
|
107
120
|
myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10) # 10 sec
|
108
121
|
myAWSIoTMQTTClient.configureMQTTOperationTimeout(10) # 10 sec
|
109
|
-
|
122
|
+
myAWSIoTMQTTClient.onOffline = self.on_offline
|
123
|
+
myAWSIoTMQTTClient.onOnline = self.on_online
|
110
124
|
# Connect and subscribe to AWS IoT
|
111
125
|
myAWSIoTMQTTClient.connect()
|
112
126
|
|
@@ -127,14 +141,28 @@ class EmeraldHWS():
|
|
127
141
|
self.updateHWSState(hws_id, key, json_payload[1][key])
|
128
142
|
|
129
143
|
def mqttCallback(self, client, userdata, message):
|
130
|
-
|
131
|
-
|
132
|
-
# print("from topic: ")
|
133
|
-
# print(message.topic)
|
134
|
-
# print("--------------\n\n")
|
144
|
+
""" Calls decode update for received message
|
145
|
+
"""
|
135
146
|
|
147
|
+
self.logger.debug("Received message from MQTT topic {}: {}".format(message.topic,message.payload.decode("utf-8")))
|
136
148
|
self.mqttDecodeUpdate(message.topic, message.payload)
|
137
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
|
+
|
138
166
|
def updateHWSState(self, id, key, value):
|
139
167
|
""" Updates the specified value for the supplied key in the HWS id specified
|
140
168
|
:param id: ID of the HWS
|
@@ -201,30 +229,35 @@ class EmeraldHWS():
|
|
201
229
|
""" Turns the specified HWS on
|
202
230
|
:param id: The UUID of the HWS to turn on
|
203
231
|
"""
|
232
|
+
self.logger.debug("Sending control message: turn on")
|
204
233
|
self.sendControlMessage(id, {"switch":1})
|
205
234
|
|
206
235
|
def turnOff(self, id):
|
207
236
|
""" Turns the specified HWS off
|
208
237
|
:param id: The UUID of the HWS to turn off
|
209
238
|
"""
|
239
|
+
self.logger.debug("Sending control message: turn off")
|
210
240
|
self.sendControlMessage(id, {"switch":0})
|
211
241
|
|
212
242
|
def setNormalMode(self, id):
|
213
243
|
""" Sets the specified HWS to normal (not Boost or Quiet) mode
|
214
244
|
:param id: The UUID of the HWS to set to normal mode
|
215
245
|
"""
|
246
|
+
self.logger.debug("Sending control message: normal mode")
|
216
247
|
self.sendControlMessage(id, {"mode":1})
|
217
248
|
|
218
249
|
def setBoostMode(self, id):
|
219
250
|
""" Sets the specified HWS to boost (high power) mode
|
220
251
|
:param id: The UUID of the HWS to set to boost mode
|
221
252
|
"""
|
253
|
+
self.logger.debug("Sending control message: boost mode")
|
222
254
|
self.sendControlMessage(id, {"mode":0})
|
223
255
|
|
224
256
|
def setQuietMode(self, id):
|
225
257
|
""" Sets the specified HWS to quiet (low power) mode
|
226
258
|
:param id: The UUID of the HWS to set to quiet mode
|
227
259
|
"""
|
260
|
+
self.logger.debug("Sending control message: quiet mode")
|
228
261
|
self.sendControlMessage(id, {"mode":2})
|
229
262
|
|
230
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
|