craftbeerpi4-pione/cbpi/extension/dummyactor/__init__.py

54 lines
1.2 KiB
Python
Raw Normal View History

2021-03-07 22:11:25 +01:00
from socket import timeout
from typing import KeysView
from voluptuous.schema_builder import message
2021-03-14 11:52:46 +01:00
from cbpi.api.dataclasses import NotificationAction, NotificationType
2018-11-04 00:47:26 +01:00
import logging
2019-01-04 09:29:09 +01:00
from unittest.mock import MagicMock, patch
2021-03-07 22:11:25 +01:00
from datetime import datetime
2019-01-05 20:43:48 +01:00
from cbpi.api import *
2019-01-04 09:29:09 +01:00
logger = logging.getLogger(__name__)
2021-01-30 22:29:33 +01:00
@parameters([])
2021-02-02 00:07:58 +01:00
class DummyActor(CBPiActor):
2021-03-07 22:11:25 +01:00
2018-11-01 19:50:04 +01:00
2021-03-07 22:11:25 +01:00
def __init__(self, cbpi, id, props):
super().__init__(cbpi, id, props)
2021-03-14 11:52:46 +01:00
@action("SAY HELLO", {})
async def helloWorld(self, **kwargs):
self.cbpi.notify("HELLO", "WOOHO", NotificationType.ERROR)
2021-02-02 00:07:58 +01:00
async def start(self):
await super().start()
2018-12-13 21:45:33 +01:00
2021-01-22 23:25:20 +01:00
async def on(self, power=0):
2021-02-02 00:07:58 +01:00
logger.info("ACTOR %s ON " % self.id)
2019-01-04 09:29:09 +01:00
self.state = True
2018-12-13 21:45:33 +01:00
2021-01-22 23:25:20 +01:00
async def off(self):
2019-01-04 09:29:09 +01:00
logger.info("ACTOR %s OFF " % self.id)
2021-02-02 00:07:58 +01:00
2019-01-04 09:29:09 +01:00
self.state = False
2018-11-01 19:50:04 +01:00
2019-01-08 23:31:39 +01:00
def get_state(self):
2021-01-22 23:25:20 +01:00
2019-01-08 23:31:39 +01:00
return self.state
2021-01-22 23:25:20 +01:00
async def run(self):
pass
2018-11-01 19:50:04 +01:00
def setup(cbpi):
2018-11-16 21:42:59 +01:00
'''
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:
'''
2021-02-02 00:07:58 +01:00
cbpi.plugin.register("DummyActor", DummyActor)