Browse Source

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

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

+ 24
- 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_response(d):
170
+        def shift_dict(d):
171
+            d_k = list(map(int, d.keys()))
172
+            d_k.sort()
173
+            offset = d_k[0]-1
174
+            return {
175
+                str(k - offset): d[k]
176
+                for k in d_k
177
+            }
178
+
179
+        if 'Analog' in d.keys():
180
+            d.update({"Analog": shift_dict(d['Analog'])})
181
+
182
+        if 'Integer' in d.keys():
183
+            d.update({"Integer": shift_dict(d['Integer'])})
184
+
185
+        if 'Digital' in d.keys():
186
+            d.update({"Digital": shift_dict(d['Digital'])})
187
+
188
+        return d
189
+
169
 
190
 
170
     if not since:
191
     if not since:
171
         last_update = 0
192
         last_update = 0
207
 
228
 
208
     for packet in post_packets:
229
     for packet in post_packets:
209
         try:
230
         try:
210
-            logger.debug(json.dumps(packet))
231
+            logger.debug(json.dumps(shift_response(packet)))
211
         except Exception as e:
232
         except Exception as e:
212
             print(e)
233
             print(e)
213
             sys.exit(1)
234
             sys.exit(1)
214
 
235
 
215
 
236
 
216
     for packet in post_packets:
237
     for packet in post_packets:
217
-        logger.debug('Will send %s', packet)
238
+        logger.debug('Will send %s', shift_response(packet))
218
         post_resp = requests.post(
239
         post_resp = requests.post(
219
             url=build_url(post_url),
240
             url=build_url(post_url),
220
-            json=packet,
241
+            json=shift_response(packet),
221
             verify=False
242
             verify=False
222
         )
243
         )
223
         if post_resp.status_code == 200:
244
         if post_resp.status_code == 200:

Loading…
Cancel
Save