fix type variable assignation

This commit is contained in:
Maxime Alves LIRMM@home 2020-09-24 14:57:32 +02:00
commit a2d3b15138
2 changed files with 7 additions and 4 deletions

View file

@ -77,7 +77,8 @@ class Variable(RowClass):
def getall_values_of_type_since(type: VariableType, since: int) -> dict:
floatcast = lambda x: round(float(x) / 10, 2)
cast_fct = floatcast if type.slabel == 'A' else lambda x: x
type.__dict__.update({'since': since})
params = type.__dict__.copy()
params.update({'since': since})
return {
row['address']: cast_fct(row['value'])
@ -94,7 +95,7 @@ class Variable(RowClass):
AND var.address >= :start_address
AND var.address <= :end_address
AND var.last_update > :since""",
type.__dict__)
params)
if row['address'] and row['value']
}

View file

@ -40,12 +40,14 @@ class VariableValue(RowClass):
pass
try:
params = self.__dict__.copy()
params.update({'type': str(params['type'])})
DB.sql(
"""INSERT INTO var_value
(type, address, value)
VALUES
(:type, :address, :value)""",
self.__dict__
params
)
return True
except Exception as e:
@ -78,7 +80,7 @@ class VariableValue(RowClass):
AND time <= :time
ORDER BY time DESC
LIMIT 1""", {
'type':type, 'address':address, 'time':int(time.strftime('%s'))+1
'type':str(type), 'address':address, 'time':int(time.strftime('%s'))+1
}))
return VariableValue(**dict(row))
except StopIteration as e: