Browse Source

fix type variable assignation

Maxime Alves LIRMM@home 4 years ago
parent
commit
a2d3b15138
2 changed files with 7 additions and 4 deletions
  1. 3
    2
      pyheatpump/models/variable.py
  2. 4
    2
      pyheatpump/models/variable_value.py

+ 3
- 2
pyheatpump/models/variable.py View File

77
     def getall_values_of_type_since(type: VariableType, since: int) -> dict:
77
     def getall_values_of_type_since(type: VariableType, since: int) -> dict:
78
         floatcast = lambda x: round(float(x) / 10, 2)
78
         floatcast = lambda x: round(float(x) / 10, 2)
79
         cast_fct = floatcast if type.slabel == 'A' else lambda x: x
79
         cast_fct = floatcast if type.slabel == 'A' else lambda x: x
80
-        type.__dict__.update({'since': since})
80
+        params = type.__dict__.copy()
81
+        params.update({'since': since})
81
 
82
 
82
         return {
83
         return {
83
             row['address']: cast_fct(row['value'])
84
             row['address']: cast_fct(row['value'])
94
                 AND var.address >= :start_address
95
                 AND var.address >= :start_address
95
                 AND var.address <= :end_address
96
                 AND var.address <= :end_address
96
                 AND var.last_update > :since""",
97
                 AND var.last_update > :since""",
97
-            type.__dict__)
98
+            params)
98
 
99
 
99
             if row['address'] and row['value']
100
             if row['address'] and row['value']
100
         }
101
         }

+ 4
- 2
pyheatpump/models/variable_value.py View File

40
             pass
40
             pass
41
 
41
 
42
         try:
42
         try:
43
+            params = self.__dict__.copy()
44
+            params.update({'type': str(params['type'])})
43
             DB.sql(
45
             DB.sql(
44
                 """INSERT INTO var_value
46
                 """INSERT INTO var_value
45
                 (type, address, value)
47
                 (type, address, value)
46
                 VALUES
48
                 VALUES
47
                 (:type, :address, :value)""",
49
                 (:type, :address, :value)""",
48
-                self.__dict__
50
+                params
49
             )
51
             )
50
             return True
52
             return True
51
         except Exception as e:
53
         except Exception as e:
78
                 AND time <= :time
80
                 AND time <= :time
79
             ORDER BY time DESC
81
             ORDER BY time DESC
80
             LIMIT 1""", {
82
             LIMIT 1""", {
81
-                'type':type, 'address':address, 'time':int(time.strftime('%s'))+1
83
+                'type':str(type), 'address':address, 'time':int(time.strftime('%s'))+1
82
             }))
84
             }))
83
             return VariableValue(**dict(row))
85
             return VariableValue(**dict(row))
84
         except StopIteration as e:
86
         except StopIteration as e:

Loading…
Cancel
Save