Sensor

Sensor Controller

class cbpi.controller.sensor_controller.SensorController(cbpi)

Bases: cbpi.controller.crud_controller.CRUDController

_abc_impl = <_abc_data object>
_post_add_callback(m)
Parameters:m
Returns:
_post_update_callback(sensor)
_pre_delete_callback(sensor_id)
Parameters:m
Returns:
_pre_update_callback(sensor)
get_state()
get_value(sensor_id)
init()

This method initializes all actors during startup. It creates actor instances

Returns:
init_sensor(sensor)
model

alias of cbpi.database.model.SensorModel

stop_sensor(sensor)

CBPiSensor

class cbpi.api.CBPiSensor(*args, **kwds)

Bases: cbpi.api.extension.CBPiExtension

init()
log_data(value)
run(cbpi)
state()

Custom Sensor

__init__.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import asyncio
import logging
import random

from cbpi.api import *

class CustomSensor(CBPiSensor):

    # Custom Properties which will can be configured by the user

    p1 = Property.Number(label="Test")
    p2 = Property.Text(label="Test")
    interval = Property.Number(label="interval")

    # Internal runtime variable
    value = 0

    @action(key="name", parameters={})
    def myAction(self):
        '''
        Custom Action Exampel
        :return: None
        '''
        pass

    def init(self):
        super().init()


    def state(self):
        super().state()

    def stop(self):
        pass

    async def run(self, cbpi):
        self.value = 0
        while True:
            await asyncio.sleep(self.interval)
            self.log_data(10)
            self.value = self.value + 1
            await cbpi.bus.fire("sensor/%s" % self.id, value=self.value)





def setup(cbpi):

    '''
    This method is called by the server during startup 
    Here you need to register your plugins at the server
    
    :param cbpi: the cbpi core 
    :return: 
    '''

    cbpi.plugin.register("CustomSensor", CustomSensor)

config.yaml

1
2
name: DummySensor
version: 4