Browse Source

[models] fixed some variable names and remove Digital address offsets

Maxime Alves LIRMM@home 3 years ago
parent
commit
a37da79028
3 changed files with 27 additions and 10 deletions
  1. 11
    2
      pyheatpump/models/heatpump.py
  2. 6
    6
      pyheatpump/models/variable.py
  3. 10
    2
      pyheatpump/models/variable_type.py

+ 11
- 2
pyheatpump/models/heatpump.py View File

@@ -6,6 +6,9 @@ from .variable_type import VariableType
6 6
 from .variable import Variable
7 7
 from .variable_value import VariableValue
8 8
 
9
+from pyheatpump.logger import logger_init
10
+logger = logger_init()
11
+
9 12
 class Heatpump:
10 13
     mac_address: str
11 14
     var_types: Dict
@@ -42,8 +45,14 @@ class Heatpump:
42 45
         return r
43 46
 
44 47
     def control(self, data):
45
-        if data['mac_address'] != self.mac_address:
46
-            logger.warn(f'Orders are not for the current heatpump ({self.mac_address} != {data["mac_address"]})')
48
+        logger.warn('Received orders data :')
49
+        logger.warn(data)
50
+        if 'macAddress' not in data.keys():
51
+            logger.info(f'No orders')
52
+            return True
53
+
54
+        if data['macAddress'] != self.macformat:
55
+            logger.warn(f'Orders are not for the current heatpump ({self.mac_address} != {data["macAddress"]})')
47 56
             raise Exception('Wrong mac_address')
48 57
 
49 58
         for label, var_type in self.var_types.items():

+ 6
- 6
pyheatpump/models/variable.py View File

@@ -68,19 +68,19 @@ class Variable(RowClass):
68 68
 
69 69
     @staticmethod
70 70
     def getall_values_of_type(type: VariableType) -> dict:
71
-        return Variable.getall_values_of_type_since(type, 0) 
71
+        return Variable.getall_values_of_type_since(type, 0)
72 72
 
73 73
 
74 74
     @staticmethod
75 75
     def getall_values_of_type_since(type: VariableType, since: int) -> dict:
76
-        floatcast = type
77
-        cast_fct = floatcast if type.slabel == 'F' else lambda x: x
76
+        floatcast = lambda x: round(float(x) / 10, 2)
77
+        cast_fct = floatcast if type.slabel == 'A' else lambda x: x
78 78
 
79
-        offset = 10000 if (type.slabel == 'D') else 0
79
+        #offset = 10000 if (type.slabel == 'D') else 0
80 80
         return dict([
81 81
             (row['address'], cast_fct(row['value']))
82 82
             for row in sql(
83
-            """SELECT (var.address + {}) as address, val.value
83
+            """SELECT var.address as address, val.value
84 84
             FROM variable var
85 85
             LEFT JOIN var_value val ON
86 86
                 var.type = val.type
@@ -91,7 +91,7 @@ class Variable(RowClass):
91 91
                 AND var.address >= {}
92 92
                 AND var.address <= {}
93 93
                 AND var.last_update > {}""".format(
94
-            offset, type, type.start_address, type.end_address, since))
94
+            type, type.start_address, type.end_address, since))
95 95
         ])
96 96
 
97 97
 

+ 10
- 2
pyheatpump/models/variable_type.py View File

@@ -64,8 +64,14 @@ class VariableType(RowClass):
64 64
         return Variable.getall_values_of_type_since(self, since)
65 65
 
66 66
     def control(self, data):
67
+        from .variable import Variable
68
+        from .variable_value import VariableValue
69
+
67 70
         for s_address, s_value in data.items():
68 71
             address = int(s_address)
72
+            if self.slabel == 'I':
73
+                # For integers, we have to respect the offset to get the address
74
+                address = address + self.start_address - 1
69 75
 
70 76
             # All values are stored in strings that represent floats
71 77
             # We have to convert them
@@ -80,10 +86,12 @@ class VariableType(RowClass):
80 86
             if address not in range(self.start_address, self.end_address + 1):
81 87
                 continue
82 88
 
83
-            if not Variable(self, address).exists():
89
+            if not Variable(**{
90
+                    'type': self,
91
+                    'address': address}).exists():
84 92
                 continue
85 93
 
86
-            new_var_value = VariableValue({
94
+            new_var_value = VariableValue(**{
87 95
                 'type': self,
88 96
                 'address': address,
89 97
                 'value': value})

Loading…
Cancel
Save