|
@@ -3,6 +3,7 @@
|
3
|
3
|
import click
|
4
|
4
|
from datetime import datetime
|
5
|
5
|
import importlib
|
|
6
|
+import time
|
6
|
7
|
import json
|
7
|
8
|
import os
|
8
|
9
|
import re
|
|
@@ -162,6 +163,8 @@ def fetch(type):
|
162
|
163
|
def supervise(since):
|
163
|
164
|
logger = logger_init()
|
164
|
165
|
|
|
166
|
+ build_url = lambda d: '{scheme}://{hostname}:{port}{path}'.format(**d)
|
|
167
|
+
|
165
|
168
|
from .config import config, mac_address_init, get_last_update, set_last_update
|
166
|
169
|
mac_address = config.get('heatpump','mac_address')
|
167
|
170
|
if not re.match('^(([0-9a-f]{2}):?){6}$', mac_address, re.I):
|
|
@@ -173,12 +176,6 @@ def supervise(since):
|
173
|
176
|
last_update = 0
|
174
|
177
|
else:
|
175
|
178
|
last_update = get_last_update()
|
176
|
|
-
|
177
|
|
- post_packets = [
|
178
|
|
- Heatpump(mac_address, last_update, ['Analog']).packet,
|
179
|
|
- Heatpump(mac_address, last_update, ['Digital']).packet,
|
180
|
|
- Heatpump(mac_address, last_update, ['Integer']).packet
|
181
|
|
- ]
|
182
|
179
|
|
183
|
180
|
base_url = {
|
184
|
181
|
'scheme':config.get('supervisor', 'scheme'),
|
|
@@ -186,7 +183,35 @@ def supervise(since):
|
186
|
183
|
'port':config.getint('supervisor', 'port')
|
187
|
184
|
}
|
188
|
185
|
|
189
|
|
- build_url = lambda d: '{scheme}://{hostname}:{port}{path}'.format(**d)
|
|
186
|
+ get_path = '/'.join((
|
|
187
|
+ config.get('supervisor', 'get_path'),
|
|
188
|
+ Heatpump(mac_address).macformat
|
|
189
|
+ ))
|
|
190
|
+ get_url = {
|
|
191
|
+ **base_url,
|
|
192
|
+ **{'path': get_path}
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ get_resp = requests.get(
|
|
196
|
+ url=build_url(get_url),
|
|
197
|
+ verify=False
|
|
198
|
+ )
|
|
199
|
+
|
|
200
|
+ control_data = get_resp.json()
|
|
201
|
+ if Heatpump(mac_address).control(control_data):
|
|
202
|
+ logger.info('GET to supervisor succeded : updated values')
|
|
203
|
+ set_last_update(int(datetime.now().strftime('%s')))
|
|
204
|
+ else:
|
|
205
|
+ logger.warn('Unable to set data from supervisor\n{}'.format(control_data))
|
|
206
|
+
|
|
207
|
+ time.sleep(3)
|
|
208
|
+
|
|
209
|
+ post_packets = [
|
|
210
|
+ Heatpump(mac_address, last_update, ['Analog']).packet,
|
|
211
|
+ Heatpump(mac_address, last_update, ['Digital']).packet,
|
|
212
|
+ Heatpump(mac_address, last_update, ['Integer']).packet
|
|
213
|
+ ]
|
|
214
|
+
|
190
|
215
|
|
191
|
216
|
|
192
|
217
|
post_url = {
|
|
@@ -213,23 +238,3 @@ def supervise(since):
|
213
|
238
|
|
214
|
239
|
set_last_update(int(datetime.now().strftime('%s')))
|
215
|
240
|
|
216
|
|
- get_path = '/'.join((
|
217
|
|
- config.get('supervisor', 'get_path'),
|
218
|
|
- Heatpump(mac_address).macformat
|
219
|
|
- ))
|
220
|
|
- get_url = {
|
221
|
|
- **base_url,
|
222
|
|
- **{'path': get_path}
|
223
|
|
- }
|
224
|
|
-
|
225
|
|
- get_resp = requests.get(
|
226
|
|
- url=build_url(get_url),
|
227
|
|
- verify=False
|
228
|
|
- )
|
229
|
|
-
|
230
|
|
- control_data = get_resp.json()
|
231
|
|
- if Heatpump(mac_address).control(control_data):
|
232
|
|
- logger.info('GET to supervisor succeded : updated values')
|
233
|
|
- set_last_update(int(datetime.now().strftime('%s')))
|
234
|
|
- else:
|
235
|
|
- logger.warn('Unable to set data from supervisor\n{}'.format(control_data))
|