mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-22 06:58:17 +01:00
GitBook: [master] one page modified
This commit is contained in:
parent
eb0cb4f6b0
commit
1ec7432285
1 changed files with 75 additions and 0 deletions
|
@ -101,3 +101,78 @@ def setup(cbpi):
|
|||
cbpi.plugin.register("CustomSensor", CustomSensor)
|
||||
```
|
||||
|
||||
## Actor
|
||||
|
||||
```python
|
||||
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from cbpi.api import *
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
import RPi.GPIO as GPIO
|
||||
except Exception:
|
||||
logger.error("Failed to load RPi.GPIO. Using Mock")
|
||||
MockRPi = MagicMock()
|
||||
modules = {
|
||||
"RPi": MockRPi,
|
||||
"RPi.GPIO": MockRPi.GPIO
|
||||
}
|
||||
patcher = patch.dict("sys.modules", modules)
|
||||
patcher.start()
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
|
||||
@parameters([Property.Number(label="Param1", configurable=True),
|
||||
Property.Text(label="Param2", configurable=True, default_value="HALLO"),
|
||||
Property.Select(label="Param3", options=[1,2,4]),
|
||||
Property.Sensor(label="Param4"),
|
||||
Property.Actor(label="Param5")])
|
||||
class CustomActor(CBPiActor):
|
||||
my_name = ""
|
||||
|
||||
# Custom property which can be configured by the user
|
||||
@action("test", parameters={})
|
||||
async def action1(self, **kwargs):
|
||||
print("ACTION !", kwargs)
|
||||
self.my_name = kwargs.get("name")
|
||||
pass
|
||||
|
||||
def init(self):
|
||||
print("INIT")
|
||||
|
||||
self.state = False
|
||||
pass
|
||||
|
||||
async def on(self, power=0):
|
||||
logger.info("ACTOR 1111 %s ON" % self.id)
|
||||
self.state = True
|
||||
|
||||
async def off(self):
|
||||
logger.info("ACTOR %s OFF " % self.id)
|
||||
self.state = False
|
||||
|
||||
def get_state(self):
|
||||
|
||||
return self.state
|
||||
|
||||
async def run(self):
|
||||
pass
|
||||
|
||||
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)
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue