GitBook: [doc] 2 pages modified

This commit is contained in:
manuel 2021-01-27 09:43:24 +00:00 committed by gitbook-bot
parent 8112ddfdb6
commit e87a662d8e
No known key found for this signature in database
GPG key ID: 07D2180C7B12D0FF
3 changed files with 14 additions and 23 deletions

View file

@ -22,9 +22,9 @@ cbpi start
## Links ## Links
{% embed url="https://www.facebook.com/groups/craftbeerpi" %} {% embed url="https://www.facebook.com/groups/craftbeerpi" caption="" %}
{% embed url="https://www.youtube.com/channel/UCy47sYaG8YLwJWw2iY5\_aNg" %} {% embed url="https://www.youtube.com/channel/UCy47sYaG8YLwJWw2iY5\_aNg" caption="" %}
{% embed url="http://web.craftbeerpi.com" %} {% embed url="http://web.craftbeerpi.com" caption="" %}

View file

@ -19,27 +19,19 @@ python3 -m pip insatll cbpi
### 2. Create Folder structure ### 2. Create Folder structure
### 3. Add Custom Code ### 3. Add Custom Code
### 4. Test the Code ### 4. Test the Code
### 3. Build plugin ### 3. Build plugin
### 4. Upload the plugin ### 4. Upload the plugin
### Full Example ### Full Example
[https://github.com/Manuel83/cbpi4-ui-plugin](https://github.com/Manuel83/cbpi4-ui-plugin) [https://github.com/Manuel83/cbpi4-ui-plugin](https://github.com/Manuel83/cbpi4-ui-plugin)
## Sensor ## Sensor
```python ```python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
@ -60,13 +52,13 @@ Make sure to extend CBPiSensor
Property.Sensor(label="Param4"), Property.Sensor(label="Param4"),
Property.Actor(label="Param5")]) Property.Actor(label="Param5")])
class CustomSensor(CBPiSensor): class CustomSensor(CBPiSensor):
def __init__(self, cbpi, id, props): def __init__(self, cbpi, id, props):
super(CustomSensor, self).__init__(cbpi, id, props) super(CustomSensor, self).__init__(cbpi, id, props)
self.value = 0 self.value = 0
@action(key="Test", parameters=[]) @action(key="Test", parameters=[])
async def action1(self, **kwargs): async def action1(self, **kwargs):
''' '''
@ -83,7 +75,7 @@ class CustomSensor(CBPiSensor):
self.value = random.randint(0,50) self.value = random.randint(0,50)
self.push_update(self.value) self.push_update(self.value)
await asyncio.sleep(1) await asyncio.sleep(1)
def get_state(self): def get_state(self):
# return the current state of the sensor # return the current state of the sensor
return dict(value=self.value) return dict(value=self.value)
@ -94,7 +86,7 @@ def setup(cbpi):
''' '''
This method is called by the server during startup This method is called by the server during startup
Here you need to register your plugins at the server Here you need to register your plugins at the server
:param cbpi: the cbpi core :param cbpi: the cbpi core
:return: :return:
''' '''
@ -104,7 +96,6 @@ def setup(cbpi):
## Actor ## Actor
```python ```python
import logging import logging
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -141,10 +132,10 @@ class CustomActor(CBPiActor):
print("ACTION !", kwargs) print("ACTION !", kwargs)
self.my_name = kwargs.get("name") self.my_name = kwargs.get("name")
pass pass
def init(self): def init(self):
print("INIT") print("INIT")
self.state = False self.state = False
pass pass
@ -157,9 +148,9 @@ class CustomActor(CBPiActor):
self.state = False self.state = False
def get_state(self): def get_state(self):
return self.state return self.state
async def run(self): async def run(self):
pass pass
@ -168,7 +159,7 @@ def setup(cbpi):
''' '''
This method is called by the server during startup This method is called by the server during startup
Here you need to register your plugins at the server Here you need to register your plugins at the server
:param cbpi: the cbpi core :param cbpi: the cbpi core
:return: :return:
''' '''