|
@@ -31,7 +31,8 @@ default_config = {
|
31
|
31
|
'interval': 10000,
|
32
|
32
|
'auth': 'None',
|
33
|
33
|
'initialization': str(datetime.now()),
|
34
|
|
- 'heatpump_id': 'None'
|
|
34
|
+ 'heatpump_id': 'None',
|
|
35
|
+ 'last_update': 0
|
35
|
36
|
},
|
36
|
37
|
'api': {
|
37
|
38
|
'host': '127.0.0.1',
|
|
@@ -136,6 +137,42 @@ async def mac_route(request, *args, **kwargs):
|
136
|
137
|
', New -> ', mac_address)))
|
137
|
138
|
|
138
|
139
|
|
|
140
|
+def get_last_update():
|
|
141
|
+ return config.get('supervisor', 'last_update')
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+def set_last_update(last_update: int=0):
|
|
145
|
+ global config
|
|
146
|
+ config.set('supervisor', 'last_update', last_update)
|
|
147
|
+ save_config()
|
|
148
|
+ return get_last_update()
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+async def last_update_route(request, *args, **kwargs):
|
|
152
|
+ """
|
|
153
|
+ last_update :
|
|
154
|
+ == 0 : since current date - interval
|
|
155
|
+ < 0 : since current_date + last_update - interval
|
|
156
|
+ > 0 : since current_data - last_update - interval (same behaviour as < 0)
|
|
157
|
+ """
|
|
158
|
+ global config
|
|
159
|
+ if request['method'] == 'GET':
|
|
160
|
+ return PlainTextResponse(get_last_update())
|
|
161
|
+
|
|
162
|
+ elif request['method'] == 'POST':
|
|
163
|
+ body = await request.body()
|
|
164
|
+ last_update = int(body.decode() or 0)
|
|
165
|
+ if int(body.decode() or 0):
|
|
166
|
+ last_update = int(datetime.now().strftime('%s'))
|
|
167
|
+ elif last_update <= 0:
|
|
168
|
+ last_update = int(datetime.now().strftime('%s')) + last_update
|
|
169
|
+ else:
|
|
170
|
+ last_update = int(datetime.now().strftime('%s')) - last_update
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+ return PlainTextResponse(str(set_last_update(last_update)))
|
|
174
|
+
|
|
175
|
+
|
139
|
176
|
ROUTES=[
|
140
|
177
|
Route('/', config_route, methods=['GET', 'POST']),
|
141
|
178
|
Route('/mac', mac_route, methods=['GET', 'POST'])
|