craftbeerpi4-pione/cbpi/api/sensor.py

70 lines
1.5 KiB
Python
Raw Normal View History

2019-08-16 21:36:55 +02:00
import logging
2021-01-22 23:25:20 +01:00
from abc import abstractmethod, ABCMeta
2019-01-05 20:43:48 +01:00
from cbpi.api.extension import CBPiExtension
2019-08-16 21:36:55 +02:00
class CBPiSensor(CBPiExtension, metaclass=ABCMeta):
2019-01-05 20:43:48 +01:00
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):
2019-08-05 20:51:20 +02:00
self.cbpi.log.log_data(self.id, value)
2019-01-05 20:43:48 +01:00
def init(self):
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):
2021-01-22 23:25:20 +01:00
pass
class CBPiSensor2(metaclass=ABCMeta):
def __init__(self, cbpi, id, props):
self.cbpi = cbpi
self.id = id
self.props = props
self.logger = logging.getLogger(__file__)
self.data_logger = None
self.state = False
self.running = False
def init(self):
pass
def log_data(self, value):
self.cbpi.log.log_data(self.id, value)
@abstractmethod
async def run(self):
self.logger.warning("Sensor Init not implemented")
def get_state(self):
pass
def get_value(self):
pass
def get_unit(self):
pass
async def start(self):
self.running = True
async def stop(self):
self.running = False