summaryrefslogtreecommitdiff
path: root/ebus
diff options
context:
space:
mode:
Diffstat (limited to 'ebus')
-rw-r--r--ebus/__init__.py16
-rw-r--r--ebus/model/sql.py20
2 files changed, 21 insertions, 15 deletions
diff --git a/ebus/__init__.py b/ebus/__init__.py
index 7b8c8ed..a435e76 100644
--- a/ebus/__init__.py
+++ b/ebus/__init__.py
@@ -3,11 +3,15 @@ import asynchat
import asyncore
import socket
import sys
+import logging
import os
from lxml import objectify
from lxml import etree
+logger = logging.getLogger("ebus.core")
+logger.setLevel(logging.INFO)
+
class UnknownPacketException(Exception):
pass
@@ -122,7 +126,7 @@ class EbusReader(asynchat.async_chat):
i = i + 1
if len(data) < 2:
- print "GAGA"
+ logger.critical("Daten Gaga")
return
source = ord(data[0])
sourceType = EbusPacket.address_to_type(source)
@@ -130,7 +134,7 @@ class EbusReader(asynchat.async_chat):
destinationType = EbusPacket.address_to_type(destination)
if len(data) < 9:
- print >>sys.stderr, "Unvollständige Daten"
+ logger.critical("Unvollständige Daten")
return
primaryCommand = ord(data[2])
@@ -154,15 +158,15 @@ class EbusReader(asynchat.async_chat):
self.handle_ebus(p)
elif sourceType == 'master' and destinationType == 'slave':
p = EbusMasterSlave(source, destination, primaryCommand, secondaryCommand, payload, None) #FIXME
- print >>sys.stderr, "SKIP MASTER-SLAVE"
+ logger.info("SKIP MASTER-SLAVE")
elif sourceType == 'master' and destinationType == 'broadcast':
p = EbusBroadcast(source, destination, primaryCommand, secondaryCommand, payload)
self.handle_ebus(p)
else:
- print >>sys.stderr, "SKIP source=%s sourceType=%s destination=%s destType=%s" % \
- (source, sourceType, destination, destinationType)
+ logger.warning("SKIP source=%s sourceType=%s destination=%s destType=%s" % \
+ (source, sourceType, destination, destinationType))
except UnknownPacketException,e:
print e
def handle_ebus(self,ebus_packet):
- print >>sys.stderr, "unhandled ebus_packet"
+ logger.critical("unhandled ebus_packet")
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")),