Actor

Architecture

_images/picture.jpeg

ActorController

class core.controller.actor_controller.ActorController(cbpi)

Bases: core.controller.actor_controller.ActorHttp, core.controller.crud_controller.CRUDController

The main actor controller

init()

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

Returns:
model

alias of core.database.model.ActorModel

off(id, **kwargs) → None

Method to switch and actor off Supporting Event Topic “actor/+/off”

Parameters:
  • id – the actor id
  • kwargs
on(id, power=100, **kwargs) → None

Method to switch an actor on. Supporting Event Topic “actor/+/on”

Parameters:
  • actor_id – the actor id
  • power – as integer value between 1 and 100
  • kwargs
Returns:

register(name, clazz) → None
toggle(id, power=100, **kwargs) → None

Method to toggle an actor on or off Supporting Event Topic “actor/+/toggle”

Parameters:
  • id – the actor id
  • power – the power as interger between 0 and 100
Returns:

CBPiActor

class core.api.actor.CBPiActor(*args, **kwds)

Bases: core.api.extension.CBPiExtension

off()

Code to switch the actor off

Returns:None
on(power)

Code to switch the actor on. Power is provided as integer value

Parameters:power – power value between 0 and 100
Returns:None
state()

Return the current actor state

Returns:

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)

config.yaml

1
2
name: DummyActor
version: 4