Actor

Architecture

_images/picture.jpeg

ActorController

class core.controller.actor_controller.ActorController(cbpi)

The main actor controller

get_all(force_db_update=False)
Parameters:force_db_update
Returns:
http_add(request)

— description: This end-point allow to test that service is up. tags: - REST API produces: - application/json responses:

“200”:
description: successful operation. Return “pong” text
“405”:
description: invalid HTTP Method
http_delete_one(request)

— description: This end-point allow to test that service is up. tags: - REST API produces: - text/plain responses:

“200”:
description: successful operation. Return “pong” text
“405”:
description: invalid HTTP Method
http_get_all(request)

test

Parameters:request
Returns:
http_get_one(request)

— description: This end-point allow to test that service is up. tags: - REST API produces: - application/json parameters: - name: “id”

in: “path” description: “ID of object to return” required: true type: “integer” format: “int64”
responses:
“200”:
description: successful operation. Return “pong” text
“405”:
description: invalid HTTP Method
http_off(request) → aiohttp.web_response.Response
Parameters:request
Returns:
http_on(request) → aiohttp.web_response.Response
Parameters:request
Returns:
http_toggle(request) → aiohttp.web_response.Response
Parameters:request
Returns:
http_update(request)

— description: This end-point allow to test that service is up. tags: - REST API produces: - application/json parameters: - in: body

name: body description: Created user object required: false schema:

type: object properties:

id:
type: integer format: int64
responses:
“200”:
description: successful operation. Return “pong” text
“405”:
description: invalid HTTP Method
init()

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

Returns:
off(id, **kwargs) → None

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

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

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

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

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

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

Parameters:power
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging

from core.api import CBPiActor, Property, action, background_task



class CustomActor(CBPiActor):

    name = Property.Number(label="Test")
    name1 = Property.Text(label="Test")
    name2 = Property.Kettle(label="Test")

    @background_task("s1", interval=2)
    async def bg_job(self):
        print("WOOH BG")

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

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

    def off(self):
        print("OFF")
        self.state = False

    def on(self, power=100):

        print("ON")
        self.state = True


    def __init__(self, cbpi=None):

        if cbpi is None:
            return

        print("INIT MY ACTOR111111")
        self.cfg = self.load_config()

        self.logger = logging.getLogger(__file__)
        logging.basicConfig(level=logging.INFO)

        self.logger.info("########WOOHOO MY ACTOR")
        self.cbpi = cbpi


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: Manuel
version: 4