Browse Source

fix type variable assignation

Maxime Alves LIRMM@home 3 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,7 +77,8 @@ class Variable(RowClass):
77 77
     def getall_values_of_type_since(type: VariableType, since: int) -> dict:
78 78
         floatcast = lambda x: round(float(x) / 10, 2)
79 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 83
         return {
83 84
             row['address']: cast_fct(row['value'])
@@ -94,7 +95,7 @@ class Variable(RowClass):
94 95
                 AND var.address >= :start_address
95 96
                 AND var.address <= :end_address
96 97
                 AND var.last_update > :since""",
97
-            type.__dict__)
98
+            params)
98 99
 
99 100
             if row['address'] and row['value']
100 101
         }

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

@@ -40,12 +40,14 @@ class VariableValue(RowClass):
40 40
             pass
41 41
 
42 42
         try:
43
+            params = self.__dict__.copy()
44
+            params.update({'type': str(params['type'])})
43 45
             DB.sql(
44 46
                 """INSERT INTO var_value
45 47
                 (type, address, value)
46 48
                 VALUES
47 49
                 (:type, :address, :value)""",
48
-                self.__dict__
50
+                params
49 51
             )
50 52
             return True
51 53
         except Exception as e:
@@ -78,7 +80,7 @@ class VariableValue(RowClass):
78 80
                 AND time <= :time
79 81
             ORDER BY time DESC
80 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 85
             return VariableValue(**dict(row))
84 86
         except StopIteration as e:

Loading…
Cancel
Save