diff options
author | Yves <yvesf-git@xapek.org> | 2010-06-20 14:53:22 +0200 |
---|---|---|
committer | Yves <yvesf-git@xapek.org> | 2010-06-20 14:53:22 +0200 |
commit | 9bf7c799973fb7158797f92880cefb3c5939611c (patch) | |
tree | 67195cb91bf325e2dc8b32c8b6c3ab8ee90e4d13 | |
parent | 2be1a10fd6135ec833b49c378057815f31a24c0d (diff) | |
download | ebus-alt-9bf7c799973fb7158797f92880cefb3c5939611c.tar.gz ebus-alt-9bf7c799973fb7158797f92880cefb3c5939611c.zip |
ebus_app korrigiert, sql-modell ist noch falsch
-rwxr-xr-x | bin/ebus_app.py | 23 | ||||
-rw-r--r-- | ebus/__init__.py | 5 |
2 files changed, 17 insertions, 11 deletions
diff --git a/bin/ebus_app.py b/bin/ebus_app.py index 9d6cf6a..c9b89f6 100755 --- a/bin/ebus_app.py +++ b/bin/ebus_app.py @@ -15,17 +15,20 @@ session = sessionmaker(bind=db_engine)() def insert(ebus_packet): try: - if len(ebus_packet.values()) > 0: - for name,value in ebus_packet.values(): - sensor = session.query().filter(name=name).first() - if not sensor: - sensor = model.Sensor(name) - session.add(sensor) - m_value = model.Value(sensor, value) - session.add(m_value) - print m_value - session.commit() + for valueKey in ebus_packet.values().keys(): + print "Key", valueKey + sensor = session.query(model.Sensor).filter(model.Sensor.name==valueKey).first() + if not sensor: + print "Add sensor %s" % valueKey + sensor = model.Sensor(valueKey) + session.add(sensor) + print sensor + m_value = model.Value(sensor, ebus_packet.values()[valueKey]) + session.add(m_value) + print m_value + session.commit() except Exception,e: + session.rollback() try: print "Failed to insert %s -- reason %s" % (ebus_packet.name(), e) except Exception,e: diff --git a/ebus/__init__.py b/ebus/__init__.py index 9ac981d..ad79846 100644 --- a/ebus/__init__.py +++ b/ebus/__init__.py @@ -117,7 +117,10 @@ class EbusXMLMixin(object): p=EbusXMLMixin.ebus_xml.xpath("/ebus/packets/packet[@primary=$primary and @secondary=$secondary]", primary="#x%.2x"%self.primary_command, secondary="#x%.2x"%self.secondary_command) - return len(p)>0 and p[0] or None + if len(p)>0 and p[0] is not None: + return p[0] + else: + return None def _get_source(self): s=EbusXMLMixin.ebus_xml.xpath("/ebus/devices/device[@address=$address]", |