From e78b32ddfd8579af40fc934e694446034270e26d Mon Sep 17 00:00:00 2001 From: Manuel83 Date: Sun, 18 Jun 2017 23:13:10 +0200 Subject: [PATCH] Created Custom Sensor (markdown) --- Custom-Sensor.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Custom-Sensor.md diff --git a/Custom-Sensor.md b/Custom-Sensor.md new file mode 100644 index 0000000..7e7437f --- /dev/null +++ b/Custom-Sensor.md @@ -0,0 +1,46 @@ +# Custom Sensor + +## Active Sensor + +``` +@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 his own loop + :return: + ''' + while self.is_running(): + self.data_received(self.temp) + socketio.sleep(5) + + @classmethod + def init_global(cls): + ''' + Called one at the startup for all sensors + :return: + ''' + +``` + + + +## Passive Sensor` + +Get's invoked by CraftBeerPi core every 5 seconds` \ No newline at end of file