bugfixing

This commit is contained in:
Manuel Fritsch 2021-01-23 14:41:26 +01:00
parent 296c2c69f0
commit 6c537bd278
14 changed files with 65 additions and 318 deletions

View file

@ -1,5 +1,4 @@
__all__ = ["CBPiActor",
"CBPiActor2",
"CBPiExtension",
"Property",
"PropertyType",
@ -10,14 +9,12 @@ __all__ = ["CBPiActor",
"parameters",
"background_task",
"CBPiKettleLogic",
"CBPiKettleLogic2",
"CBPiSimpleStep",
"CBPiException",
"KettleException",
"SensorException",
"ActorException",
"CBPiSensor",
"CBPiSensor2",
"CBPiStep"]
from cbpi.api.actor import *

View file

@ -2,50 +2,15 @@ from abc import ABCMeta
import asyncio
from cbpi.api.extension import CBPiExtension
__all__ = ["CBPiActor", "CBPiActor2"]
__all__ = ["CBPiActor"]
import logging
logger = logging.getLogger(__file__)
class CBPiActor(CBPiExtension, metaclass=ABCMeta):
def init(self):
pass
def stop(self):
pass
def on(self, power):
'''
Code to switch the actor on. Power is provided as integer value
:param power: power value between 0 and 100
:return: None
'''
pass
def off(self):
'''
Code to switch the actor off
:return: None
'''
pass
def get_state(self):
'''
Return the current actor state
:return:
'''
pass
class CBPiActor2(metaclass=ABCMeta):
class CBPiActor(metaclass=ABCMeta):
def __init__(self, cbpi, id, props):
self.cbpi = cbpi
@ -64,16 +29,12 @@ class CBPiActor2(metaclass=ABCMeta):
async def run(self):
while self.running:
print("RUNNING ACTOR")
await asyncio.sleep(1)
def get_state(self):
print("########STATE", self.state)
return dict(state=self.state)
async def start(self):
print("START UP ACTOR")
self.running = True
async def stop(self):

View file

@ -3,44 +3,9 @@ from abc import ABCMeta
import logging
import asyncio
class CBPiKettleLogic(CBPiExtension):
'''
Base Class for a Kettle logic.
'''
def init(self):
'''
Code which will be executed when the logic is initialised. Needs to be overwritten by the implementing logic
:return: None
'''
pass
def stop(self):
'''
Code which will be executed when the logic is stopped. Needs to be overwritten by the implementing logic
:return: None
'''
pass
def run(self):
'''
This method is running as background process when logic is started.
Typically a while loop responsible that the method keeps running
while self.running:
await asyncio.sleep(1)
:return: None
'''
pass
class CBPiKettleLogic2(metaclass=ABCMeta):
class CBPiKettleLogic(metaclass=ABCMeta):
def __init__(self, cbpi, id, props):
self.cbpi = cbpi

View file

@ -3,36 +3,9 @@ from abc import abstractmethod, ABCMeta
from cbpi.api.extension import CBPiExtension
class CBPiSensor(CBPiExtension, metaclass=ABCMeta):
def __init__(self, *args, **kwds):
CBPiExtension.__init__(self, *args, **kwds)
self.logger = logging.getLogger(__file__)
self.data_logger = None
self.state = False
def get_parameter(self, name, default):
return self.cbpi.config.get(name, default)
def log_data(self, value):
self.cbpi.log.log_data(self.id, value)
def init(self):
pass
async def run(self, cbpi):
self.logger.warning("Sensor Init not implemented")
def get_state(self):
pass
def get_value(self):
pass
def get_unit(self):
pass
class CBPiSensor2(metaclass=ABCMeta):
class CBPiSensor(metaclass=ABCMeta):
def __init__(self, cbpi, id, props):
self.cbpi = cbpi

View file

@ -131,13 +131,13 @@ class PluginController():
'''
logger.debug("Register %s Class %s" % (name, clazz.__name__))
if issubclass(clazz, CBPiActor2):
if issubclass(clazz, CBPiActor):
self.cbpi.actor.types[name] = self._parse_step_props(clazz,name)
if issubclass(clazz, CBPiKettleLogic2):
if issubclass(clazz, CBPiKettleLogic):
self.cbpi.kettle.types[name] = self._parse_step_props(clazz,name)
if issubclass(clazz, CBPiSensor2):
if issubclass(clazz, CBPiSensor):
self.cbpi.sensor.types[name] = self._parse_step_props(clazz,name)
if issubclass(clazz, CBPiStep):

View file

@ -19,9 +19,13 @@ except Exception:
patcher.start()
import RPi.GPIO as GPIO
class CustomActor(CBPiActor2):
@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
@ -29,7 +33,6 @@ class CustomActor(CBPiActor2):
async def action1(self, **kwargs):
print("ACTION !", kwargs)
self.my_name = kwargs.get("name")
pass
def init(self):
@ -53,57 +56,6 @@ class CustomActor(CBPiActor2):
async def run(self):
pass
class GPIOActor(CBPiActor):
# Custom property which can be configured by the user
gpio = Property.Select("GPIO", options=[0,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], description="GPIO to which the actor is connected")
def init(self):
try:
GPIO.setup(int(self.gpio), GPIO.OUT)
GPIO.output(int(self.gpio), 0)
except Exception as e:
raise CBPiException("FAILD TO INIT ACTOR")
def on(self, power=0):
print("GPIO ON %s" % str(self.gpio))
GPIO.output(int(self.gpio), 1)
self.state = True
def off(self):
print("GPIO OFF %s" % str(self.gpio))
GPIO.output(int(self.gpio), 0)
self.state = False
class GPIORelayBoardActor(CBPiActor):
# Custom property which can be configured by the user
gpio = Property.Select("GPIO", options=[0,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], description="GPIO to which the actor is connected")
def init(self):
try:
GPIO.setup(int(self.gpio), GPIO.OUT)
GPIO.output(int(self.gpio), 1)
except Exception as e:
raise CBPiException("FAILD TO INIT ACTOR")
def on(self, power=0):
print("GPIO ON %s" % str(self.gpio))
GPIO.output(int(self.gpio), 0)
self.state = True
def off(self):
print("GPIO OFF %s" % str(self.gpio))
GPIO.output(int(self.gpio), 1)
self.state = False
def setup(cbpi):
'''

View file

@ -2,7 +2,12 @@ import asyncio
from cbpi.api import *
class CustomLogic(CBPiKettleLogic2):
@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 CustomLogic(CBPiKettleLogic):
pass

View file

@ -7,55 +7,12 @@ from aiohttp import web
from cbpi.api import *
class CustomSensor(CBPiSensor):
# Custom Properties which will can be configured by the user
interval = Property.Number(label="interval", configurable=True)
# Internal runtime variable
value = 0
@action(key="name", parameters={})
def myAction(self):
'''
Custom Action Exampel
:return: None
'''
pass
def init(self):
super().init()
self.state = True
def get_state(self):
return self.state
def get_value(self):
return self.value
def get_unit(self):
return "°%s" % self.get_parameter("TEMP_UNIT", "C")
def stop(self):
pass
async def run(self, cbpi):
self.value = 0
while True:
await asyncio.sleep(self.interval)
self.value = random.randint(1,101)
self.log_data(self.value)
await cbpi.bus.fire("sensor/%s/data" % self.id, value=self.value)
@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 CustomSensor2(CBPiSensor2):
class CustomSensor(CBPiSensor):
@action(key="Test", parameters=[])
async def action1(self, **kwargs):
@ -67,11 +24,8 @@ class CustomSensor2(CBPiSensor2):
@action(key="Test2", parameters=[])
async def action3(self, **kwargs):
print("ACTION!", kwargs)
async def run(self):
while self.running is True:
@ -88,5 +42,4 @@ def setup(cbpi):
:param cbpi: the cbpi core
:return:
'''
cbpi.plugin.register("CustomSensor2", CustomSensor2)
#cbpi.plugin.register("CustomSensor", CustomSensor)
cbpi.plugin.register("CustomSensor", CustomSensor)

View file

@ -1,24 +1,14 @@
{
"data": [
{
"id": "9NkxVioA7FfZi6waegi246",
"name": "Manuel",
"props": {},
"state": {},
"type": "CustomActor"
"id": "8BLRqagLicCdEBDdc77Sgr",
"name": "Test",
"props": {
"Param3": 2,
"Param4": "",
"Param5": "8BLRqagLicCdEBDdc77Sgr"
},
{
"id": "5hk68r3pFBe6JoRXzavLCA",
"name": "Actor 1",
"props": {},
"state": {},
"type": "CustomActor"
},
{
"id": "YgVFNsXncfMMoHD7U6TvP6",
"name": "111",
"props": {},
"state": {},
"state": false,
"type": "CustomActor"
}
]

View file

@ -196,7 +196,7 @@
"id": "2e325539-6ed9-4e0d-b1dc-de860c47a1be",
"name": "Heater",
"props": {
"actor": 1
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "ActorButton",
"x": 210,
@ -206,7 +206,7 @@
"id": "78b85989-c1bc-47e3-ad7b-0defeabb9bdc",
"name": "Pump",
"props": {
"actor": 2
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "ActorButton",
"x": 305,

View file

@ -1,25 +1,44 @@
{
"data": [
{
"agitator": "9NkxVioA7FfZi6waegi246",
"heater": "9NkxVioA7FfZi6waegi246",
"id": "gJ6jCupRmpxRsweY9nANTp",
"name": "Kettle 233312312",
"agitator": "",
"heater": "8BLRqagLicCdEBDdc77Sgr",
"id": "oHxKz3z5RjbsxfSz6KUgov",
"name": "Test",
"props": {},
"sensor": "TPpjzj9YXh6yYzvyJycmig",
"sensor": "",
"state": {},
"target_temp": 22,
"target_temp": null,
"type": "CustomKettleLogic"
},
{
"agitator": "9NkxVioA7FfZi6waegi246",
"heater": "9NkxVioA7FfZi6waegi246",
"id": "RMjMvwphxt3aiMrTnHbpcB",
"agitator": "",
"heater": "",
"id": "WxAkesrkqiHH3Gywc4fMci",
"name": "Test",
"props": {},
"sensor": "TPpjzj9YXh6yYzvyJycmig",
"props": {
"Param2": "13",
"Param3": 1,
"Param4": "",
"Param5": "8BLRqagLicCdEBDdc77Sgr"
},
"sensor": "",
"state": {},
"target_temp": 22,
"target_temp": null,
"type": "CustomKettleLogic"
},
{
"agitator": "",
"heater": "8BLRqagLicCdEBDdc77Sgr",
"id": "gc9Bwp38jtyxkVWH5oYRNZ",
"name": "Test",
"props": {
"Param3": 1,
"Param5": "8BLRqagLicCdEBDdc77Sgr"
},
"sensor": "",
"state": {},
"target_temp": null,
"type": "CustomKettleLogic"
}
]

View file

@ -1,21 +1,5 @@
{
"data": [
{
"id": "TPpjzj9YXh6yYzvyJycmig",
"name": "AMAZING22211111123123",
"props": {
"param1": "HALLO",
"param2": "Test"
},
"status": null,
"type": "CustomSensor2"
},
{
"id": "2rAviwweTUY27Y8yZKftWA",
"name": "Testasdfasdf",
"props": {},
"status": null,
"type": "CustomSensor2"
}
]
}

View file

@ -1,60 +1,8 @@
{
"basic": {
"name": "Weissbier"
"name": "WOOHOo"
},
"profile": [
{
"id": "eopJy6oxGqrNuRNtiAPXvN",
"name": "Step1",
"props": {
"Param1": "1",
"Param2": "HALLO",
"Param3": 1,
"count": 8,
"wohoo": 0
},
"status": "P",
"type": "CustomStep2"
},
{
"id": "hyXYDBUAENgwD7yNwaeLe7",
"name": "Step2",
"props": {
"Param1": "123",
"Param2": "Parameter2",
"Param3": 2,
"count": 0,
"wohoo": 0
},
"status": "I",
"type": "CustomStep2"
},
{
"id": "iJHU9FgeGBtvDhraEHUoP2",
"name": "Step3",
"props": {
"Param1": 123,
"Param2": "HALLO",
"Param3": 2,
"Param5": 1,
"count": 0,
"wohoo": 0
},
"status": "I",
"type": "CustomStep2"
},
{
"id": "duxvgLknKLjGYhdm9TKqUE",
"name": "Step4",
"props": {
"Param1": "1222",
"Param2": "HELLO",
"Param3": 2,
"count": 0,
"wohoo": 0
},
"status": "I",
"type": "CustomStep2"
}
]
}

Binary file not shown.