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", __all__ = ["CBPiActor",
"CBPiActor2",
"CBPiExtension", "CBPiExtension",
"Property", "Property",
"PropertyType", "PropertyType",
@ -10,14 +9,12 @@ __all__ = ["CBPiActor",
"parameters", "parameters",
"background_task", "background_task",
"CBPiKettleLogic", "CBPiKettleLogic",
"CBPiKettleLogic2",
"CBPiSimpleStep", "CBPiSimpleStep",
"CBPiException", "CBPiException",
"KettleException", "KettleException",
"SensorException", "SensorException",
"ActorException", "ActorException",
"CBPiSensor", "CBPiSensor",
"CBPiSensor2",
"CBPiStep"] "CBPiStep"]
from cbpi.api.actor import * from cbpi.api.actor import *

View file

@ -2,50 +2,15 @@ from abc import ABCMeta
import asyncio import asyncio
from cbpi.api.extension import CBPiExtension from cbpi.api.extension import CBPiExtension
__all__ = ["CBPiActor", "CBPiActor2"] __all__ = ["CBPiActor"]
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
class CBPiActor(CBPiExtension, metaclass=ABCMeta):
def init(self): class CBPiActor(metaclass=ABCMeta):
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):
def __init__(self, cbpi, id, props): def __init__(self, cbpi, id, props):
self.cbpi = cbpi self.cbpi = cbpi
@ -64,16 +29,12 @@ class CBPiActor2(metaclass=ABCMeta):
async def run(self): async def run(self):
while self.running: while self.running:
print("RUNNING ACTOR")
await asyncio.sleep(1) await asyncio.sleep(1)
def get_state(self): def get_state(self):
print("########STATE", self.state)
return dict(state=self.state) return dict(state=self.state)
async def start(self): async def start(self):
print("START UP ACTOR")
self.running = True self.running = True
async def stop(self): async def stop(self):

View file

@ -3,44 +3,9 @@ from abc import ABCMeta
import logging import logging
import asyncio 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 class CBPiKettleLogic(metaclass=ABCMeta):
'''
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):
def __init__(self, cbpi, id, props): def __init__(self, cbpi, id, props):
self.cbpi = cbpi self.cbpi = cbpi

View file

@ -3,36 +3,9 @@ from abc import abstractmethod, ABCMeta
from cbpi.api.extension import CBPiExtension 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): class CBPiSensor(metaclass=ABCMeta):
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):
def __init__(self, cbpi, id, props): def __init__(self, cbpi, id, props):
self.cbpi = cbpi self.cbpi = cbpi

View file

@ -131,13 +131,13 @@ class PluginController():
''' '''
logger.debug("Register %s Class %s" % (name, clazz.__name__)) 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) 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) 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) self.cbpi.sensor.types[name] = self._parse_step_props(clazz,name)
if issubclass(clazz, CBPiStep): if issubclass(clazz, CBPiStep):

View file

@ -19,9 +19,13 @@ except Exception:
patcher.start() patcher.start()
import RPi.GPIO as GPIO 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 = "" my_name = ""
# Custom property which can be configured by the user # Custom property which can be configured by the user
@ -29,7 +33,6 @@ class CustomActor(CBPiActor2):
async def action1(self, **kwargs): async def action1(self, **kwargs):
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):
@ -53,57 +56,6 @@ class CustomActor(CBPiActor2):
async def run(self): async def run(self):
pass 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): def setup(cbpi):
''' '''

View file

@ -2,7 +2,12 @@ import asyncio
from cbpi.api import * 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 pass

View file

@ -7,55 +7,12 @@ from aiohttp import web
from cbpi.api import * 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), @parameters([Property.Number(label="Param1", configurable=True),
Property.Text(label="Param2", configurable=True, default_value="HALLO"), Property.Text(label="Param2", configurable=True, default_value="HALLO"),
Property.Select(label="Param3", options=[1,2,4]), Property.Select(label="Param3", options=[1,2,4]),
Property.Sensor(label="Param4"), Property.Sensor(label="Param4"),
Property.Actor(label="Param5")]) Property.Actor(label="Param5")])
class CustomSensor2(CBPiSensor2): class CustomSensor(CBPiSensor):
@action(key="Test", parameters=[]) @action(key="Test", parameters=[])
async def action1(self, **kwargs): async def action1(self, **kwargs):
@ -67,11 +24,8 @@ class CustomSensor2(CBPiSensor2):
@action(key="Test2", parameters=[]) @action(key="Test2", parameters=[])
async def action3(self, **kwargs): async def action3(self, **kwargs):
print("ACTION!", kwargs) print("ACTION!", kwargs)
async def run(self): async def run(self):
while self.running is True: while self.running is True:
@ -88,5 +42,4 @@ def setup(cbpi):
:param cbpi: the cbpi core :param cbpi: the cbpi core
:return: :return:
''' '''
cbpi.plugin.register("CustomSensor2", CustomSensor2) cbpi.plugin.register("CustomSensor", CustomSensor)
#cbpi.plugin.register("CustomSensor", CustomSensor)

View file

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

View file

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

View file

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

View file

@ -1,21 +1,5 @@
{ {
"data": [ "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": { "basic": {
"name": "Weissbier" "name": "WOOHOo"
}, },
"profile": [ "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.