Browse Source

[heatpump] fix fonction de correction des adresses

Maxime Alves LIRMM@home 4 years ago
parent
commit
7fa312397f
3 changed files with 30 additions and 27 deletions
  1. 1
    26
      pyheatpump/cli.py
  2. 2
    1
      pyheatpump/heatpump.py
  3. 27
    0
      pyheatpump/lib.py

+ 1
- 26
pyheatpump/cli.py View File

14
 
14
 
15
 from pyheatpump.logger import logger_init
15
 from pyheatpump.logger import logger_init
16
 from pyheatpump.models import *
16
 from pyheatpump.models import *
17
+from pyheatpump.lib import shift_response
17
 
18
 
18
 CONTEXT_SETTINGS={
19
 CONTEXT_SETTINGS={
19
     'default_map':{'run': {}}
20
     'default_map':{'run': {}}
166
 
167
 
167
     from .models.heatpump import Heatpump
168
     from .models.heatpump import Heatpump
168
 
169
 
169
-    def shift_response(d):
170
-        def shift_dict(d):
171
-            d_k = list(map(int, d.keys()))
172
-            if not len(d_k):
173
-                return d
174
-
175
-            d_k.sort()
176
-            offset = d_k[0]-1
177
-            return {
178
-                str(k - offset): d[str(k)]
179
-                for k in d_k
180
-                if str(k) in d
181
-            }
182
-
183
-        if 'Analog' in d.keys():
184
-            d.update({"Analog": shift_dict(d['Analog'])})
185
-
186
-        if 'Integer' in d.keys():
187
-            d.update({"Integer": shift_dict(d['Integer'])})
188
-
189
-        if 'Digital' in d.keys():
190
-            d.update({"Digital": shift_dict(d['Digital'])})
191
-
192
-        return d
193
-
194
-
195
     if not since:
170
     if not since:
196
         last_update = 0
171
         last_update = 0
197
     else:
172
     else:

+ 2
- 1
pyheatpump/heatpump.py View File

3
 from starlette.routing import Router, Route
3
 from starlette.routing import Router, Route
4
 from starlette.responses import JSONResponse
4
 from starlette.responses import JSONResponse
5
 from .config import config
5
 from .config import config
6
+from .lib import shift_response
6
 
7
 
7
 from pyheatpump.models import *
8
 from pyheatpump.models import *
8
 
9
 
14
         time = datetime.fromisoformat(request.params['time'])
15
         time = datetime.fromisoformat(request.params['time'])
15
         h = Heatpump(config.get('heatpump', 'mac_address'), request.params['time'])
16
         h = Heatpump(config.get('heatpump', 'mac_address'), request.params['time'])
16
 
17
 
17
-    return JSONResponse(h.__dict__())
18
+    return JSONResponse(shift_response(h.__dict__()))
18
 
19
 
19
 
20
 
20
 ROUTES=[
21
 ROUTES=[

+ 27
- 0
pyheatpump/lib.py View File

1
+def shift_response(d):
2
+    def shift_dict(d_):
3
+        d_k = list(map(int, d_.keys()))
4
+        if not len(d_k):
5
+            return d_
6
+
7
+        d_k.sort()
8
+        offset = d_k[0]-1
9
+
10
+        d_res = {
11
+            str(k - offset): d_[k]
12
+            for k in d_k
13
+            if (k in d_ and isinstance(d_[k], int))
14
+        }
15
+
16
+        return d_res
17
+
18
+    if 'Analog' in d.keys():
19
+        d.update({"Analog": shift_dict(d['Analog'])})
20
+
21
+    if 'Integer' in d.keys():
22
+        d.update({"Integer": shift_dict(d['Integer'])})
23
+
24
+    if 'Digital' in d.keys():
25
+        d.update({"Digital": shift_dict(d['Digital'])})
26
+
27
+    return d

Loading…
Cancel
Save