Browse Source

[supervise] shift dictionary values to index (#30)

Maxime Alves LIRMM@home 4 years ago
parent
commit
6bfb5bba5a
1 changed files with 11 additions and 3 deletions
  1. 11
    3
      pyheatpump/cli.py

+ 11
- 3
pyheatpump/cli.py View File

166
 
166
 
167
     from .models.heatpump import Heatpump
167
     from .models.heatpump import Heatpump
168
 
168
 
169
+    def shift_dict(d):
170
+        d_k = list(d.keys())
171
+        d_k.sort()
172
+        offset = d_k[0]-1
173
+        return {
174
+            (k - offset): d[k]
175
+            for k in d_k
176
+        }
169
 
177
 
170
     if not since:
178
     if not since:
171
         last_update = 0
179
         last_update = 0
207
 
215
 
208
     for packet in post_packets:
216
     for packet in post_packets:
209
         try:
217
         try:
210
-            logger.debug(json.dumps(packet))
218
+            logger.debug(json.dumps(shift_dict(packet)))
211
         except Exception as e:
219
         except Exception as e:
212
             print(e)
220
             print(e)
213
             sys.exit(1)
221
             sys.exit(1)
214
 
222
 
215
 
223
 
216
     for packet in post_packets:
224
     for packet in post_packets:
217
-        logger.debug('Will send %s', packet)
225
+        logger.debug('Will send %s', shift_dict(packet))
218
         post_resp = requests.post(
226
         post_resp = requests.post(
219
             url=build_url(post_url),
227
             url=build_url(post_url),
220
-            json=packet,
228
+            json=shift_dict(packet),
221
             verify=False
229
             verify=False
222
         )
230
         )
223
         if post_resp.status_code == 200:
231
         if post_resp.status_code == 200:

Loading…
Cancel
Save