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

49 lines
1,009 B
Python
Raw Normal View History

2018-11-04 00:47:26 +01:00
import logging
2019-01-04 09:29:09 +01:00
from unittest.mock import MagicMock, patch
2018-11-01 19:50:04 +01:00
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-01-22 23:25:20 +01:00
my_name = ""
2018-11-01 19:50:04 +01:00
2018-12-08 14:21:00 +01:00
# Custom property which can be configured by the user
@action("test", parameters={})
2021-01-22 23:25:20 +01:00
async def action1(self, **kwargs):
2021-02-16 20:37:51 +01:00
2021-01-22 23:25:20 +01:00
self.my_name = kwargs.get("name")
pass
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)