-
Notifications
You must be signed in to change notification settings - Fork 169
Custom Sensor
Manuel83 edited this page Jun 18, 2017
·
4 revisions
CraftBeerPi distinguishes between Active and Passive Sensors
- Active Sensors: Has to handle it's own loop and push data to CraftBeerPi
- Passive Sensors: Are executed every 5 seconds by CraftBeerPi to pull new data
from modules import cbpi
from modules.core.hardware import SensorActive
from modules.core.props import Property
@cbpi.sensor
class DummyTempSensor(SensorActive):
temp = Property.Number("Temperature", configurable=True, default_value=5)
def get_unit(self):
'''
:return: Unit of the sensor as string. Should not be longer than 3 characters
'''
return "°C" if self.get_config_parameter("unit", "C") == "C" else "°F"
def stop(self):
'''
Stop the sensor. Is called when the sensor config is updated or the sensor is deleted
:return:
'''
pass
def execute(self):
'''
Active sensor has to handle its own loop
:return:
'''
while self.is_running():
self.data_received(self.temp)
self.sleep(5)
@classmethod
def init_global(cls):
'''
Called one at the startup for all sensors
:return:
'''
Get's invoked by CraftBeerPi core every 5 seconds`
COMMING SOON