Properties

Properties can be use in all extensions. During the startup the server scans all extension for variables of type Property. Theses properties are exposed to the user for configuration during run time. For example the user can set the GPIO number or the 1Wire Id.

Typical example how to use properties in an actor module.

Custom Actor

__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
import logging

from core.api import CBPiActor, Property, action


class CustomActor(CBPiActor):

    # Custom property which can be configured by the user
    gpio = Property.Number(label="Test")


    @action(key="name", parameters={})
    def myAction(self):
        pass

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

    def off(self):
        print("OFF", self.gpio)

        # Code to swtich the actor off goes here

        self.state = False

    def on(self, power=100):
        print("ON", self.gpio)

        # Code to swtich the actor on goes here

        self.state = True



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("CustomActor", CustomActor)
class core.api.property.Property
class Actor(label, description='')

The user select an actor which is available in the system. The value of this variable will be the actor id

class Kettle(label, description='')

The user select a kettle which is available in the system. The value of this variable will be the kettle id

class Number(label, configurable=False, default_value=None, unit='', description='')

The user can set a number value

class Select(label, options, description='')

Select Property. The user can select value from list set as options parameter

class Sensor(label, description='')

The user select a sensor which is available in the system. The value of this variable will be the sensor id

class Text(label, configurable=False, default_value='', description='')

The user can set a text value