2019-01-05 20:43:48 +01:00
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
from time import localtime, strftime
|
|
|
|
|
|
|
|
from cbpi.api.extension import CBPiExtension
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
class CBPiSensor(CBPiExtension):
|
|
|
|
def __init__(self, *args, **kwds):
|
|
|
|
CBPiExtension.__init__(self, *args, **kwds)
|
|
|
|
self.logger = logging.getLogger(__file__)
|
|
|
|
self.data_logger = None
|
2019-01-08 23:31:39 +01:00
|
|
|
self.state = False
|
2019-01-05 20:43:48 +01:00
|
|
|
|
2019-01-28 22:21:31 +01:00
|
|
|
def get_parameter(self, name, default):
|
|
|
|
return self.cbpi.config.get(name, default)
|
2019-01-05 20:43:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
def log_data(self, value):
|
|
|
|
|
|
|
|
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
|
|
|
|
|
|
|
|
self.data_logger.debug("%s,%s" % (formatted_time, value))
|
|
|
|
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.data_logger = logging.getLogger('cbpi.sensor.%s' % self.id)
|
|
|
|
self.data_logger.propagate = False
|
|
|
|
self.data_logger.setLevel(logging.DEBUG)
|
2019-01-28 22:21:31 +01:00
|
|
|
handler = RotatingFileHandler('./logs/sensor_%s.log' % self.id, maxBytes=2000, backupCount=10)
|
2019-01-05 20:43:48 +01:00
|
|
|
self.data_logger.addHandler(handler)
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def run(self, cbpi):
|
|
|
|
self.logger.warning("Sensor Init not implemented")
|
|
|
|
|
2019-01-08 23:31:39 +01:00
|
|
|
def get_state(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_value(self):
|
2019-01-28 22:21:31 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
def get_unit(self):
|
2019-01-05 20:43:48 +01:00
|
|
|
pass
|