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
 from .variable import Variable
6
 from .variable import Variable
7
 from .variable_value import VariableValue
7
 from .variable_value import VariableValue
8
 
8
 
9
+from pyheatpump.logger import logger_init
10
+logger = logger_init()
11
+
9
 class Heatpump:
12
 class Heatpump:
10
     mac_address: str
13
     mac_address: str
11
     var_types: Dict
14
     var_types: Dict
42
         return r
45
         return r
43
 
46
 
44
     def control(self, data):
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
             raise Exception('Wrong mac_address')
56
             raise Exception('Wrong mac_address')
48
 
57
 
49
         for label, var_type in self.var_types.items():
58
         for label, var_type in self.var_types.items():

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

68
 
68
 
69
     @staticmethod
69
     @staticmethod
70
     def getall_values_of_type(type: VariableType) -> dict:
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
     @staticmethod
74
     @staticmethod
75
     def getall_values_of_type_since(type: VariableType, since: int) -> dict:
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
         return dict([
80
         return dict([
81
             (row['address'], cast_fct(row['value']))
81
             (row['address'], cast_fct(row['value']))
82
             for row in sql(
82
             for row in sql(
83
-            """SELECT (var.address + {}) as address, val.value
83
+            """SELECT var.address as address, val.value
84
             FROM variable var
84
             FROM variable var
85
             LEFT JOIN var_value val ON
85
             LEFT JOIN var_value val ON
86
                 var.type = val.type
86
                 var.type = val.type
91
                 AND var.address >= {}
91
                 AND var.address >= {}
92
                 AND var.address <= {}
92
                 AND var.address <= {}
93
                 AND var.last_update > {}""".format(
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
         return Variable.getall_values_of_type_since(self, since)
64
         return Variable.getall_values_of_type_since(self, since)
65
 
65
 
66
     def control(self, data):
66
     def control(self, data):
67
+        from .variable import Variable
68
+        from .variable_value import VariableValue
69
+
67
         for s_address, s_value in data.items():
70
         for s_address, s_value in data.items():
68
             address = int(s_address)
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
             # All values are stored in strings that represent floats
76
             # All values are stored in strings that represent floats
71
             # We have to convert them
77
             # We have to convert them
80
             if address not in range(self.start_address, self.end_address + 1):
86
             if address not in range(self.start_address, self.end_address + 1):
81
                 continue
87
                 continue
82
 
88
 
83
-            if not Variable(self, address).exists():
89
+            if not Variable(**{
90
+                    'type': self,
91
+                    'address': address}).exists():
84
                 continue
92
                 continue
85
 
93
 
86
-            new_var_value = VariableValue({
94
+            new_var_value = VariableValue(**{
87
                 'type': self,
95
                 'type': self,
88
                 'address': address,
96
                 'address': address,
89
                 'value': value})
97
                 'value': value})

Loading…
Cancel
Save