summaryrefslogtreecommitdiff
path: root/heap/bin/ebus_app.py
diff options
context:
space:
mode:
Diffstat (limited to 'heap/bin/ebus_app.py')
-rwxr-xr-xheap/bin/ebus_app.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/heap/bin/ebus_app.py b/heap/bin/ebus_app.py
new file mode 100755
index 0000000..c9b89f6
--- /dev/null
+++ b/heap/bin/ebus_app.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+# xapek.org, 2010
+import asyncore
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from ebus.web import model
+from ebus import EbusReader
+
+#db_engine = create_engine('sqlite:///:memory:', echo=True)
+db_engine = create_engine("postgresql://yvesf:iii@10.2.2.13:5432/yvesf", echo=True)
+
+session = sessionmaker(bind=db_engine)()
+
+
+def insert(ebus_packet):
+ try:
+ 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:
+ print e
+
+reader = EbusReader()
+reader.handle_ebus = insert
+reader.debug = False
+
+asyncore.loop()