diff options
Diffstat (limited to 'ebus/model')
-rw-r--r-- | ebus/model/sql.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ebus/model/sql.py b/ebus/model/sql.py index de13239..219cfbc 100644 --- a/ebus/model/sql.py +++ b/ebus/model/sql.py @@ -33,7 +33,9 @@ class Value(ModelBase): discriminator = Column('type', String(50)) __mapper_args__ = {'polymorphic_on': discriminator} - def __init__(self, sensor, timestamp=datetime.now()): + def __init__(self, sensor, timestamp=None): + if not timestamp: + timestamp = datetime.now() self.timestamp = timestamp self.sensor = sensor @@ -48,7 +50,7 @@ class ValueFloat(Value): __mapper_args__ = {'polymorphic_identity': 'float'} value_float = Column(Float(precision=4)) - def __init__(self, sensor, value, timestamp=datetime.now()): + def __init__(self, sensor, value, timestamp=None): Value.__init__(self, sensor, timestamp) self.value_float = value @@ -59,7 +61,7 @@ class ValueInt(Value): __mapper_args__ = {'polymorphic_identity': 'int'} value_int = Column(Integer) - def __init__(self, sensor, value, timestamp=datetime.now()): + def __init__(self, sensor, value, timestamp=None): Value.__init__(self, sensor, timestamp) self.value_int = value @@ -70,7 +72,7 @@ class ValueString(Value): __mapper_args__ = {'polymorphic_identity': 'string'} value_string = Column(String) - def __init__(self, sensor, value, timestamp=datetime.now()): + def __init__(self, sensor, value, timestamp=None): Value.__init__(self, sensor, timestamp) self.value_string = value @@ -110,19 +112,19 @@ class EbusSQL(object): yield ValueInt(sensor, \ model.Word(name, offset).value(packet.data)) elif field.tag == "data1b": - yield ValueInt(sensor, \ + yield ValueFloat(sensor, \ model.Data1b(name, offset).value(packet.data)) elif field.tag == "data1c": - yield ValueInt(sensor, \ + yield ValueFloat(sensor, \ model.Data1c(name, offset).value(packet.data)) elif field.tag == "data2b": - yield ValueInt(sensor, \ + yield ValueFloat(sensor, \ model.Data2b(name, offset).value(packet.data)) elif field.tag == "data2c": - yield ValueInt(sensor, + yield ValueFloat(sensor, model.Data2c(name, offset).value(packet.data)) elif field.tag == "bcd": - yield ValueString(sensor, + yield ValueInt(sensor, model.Bcd(name, offset).value(packet.data)) elif field.tag == "byteEnum": options = dict(map(lambda opt: ( int(opt.get("value")[2:],16), opt.get("name")), |