From 6c537bd278459adf33f1a128e2733f8ef4b9eac9 Mon Sep 17 00:00:00 2001 From: Manuel Fritsch Date: Sat, 23 Jan 2021 14:41:26 +0100 Subject: [PATCH] bugfixing --- cbpi/api/__init__.py | 3 -- cbpi/api/actor.py | 43 +----------------- cbpi/api/kettle_logic.py | 37 +-------------- cbpi/api/sensor.py | 29 +----------- cbpi/controller/plugin_controller.py | 6 +-- cbpi/extension/dummyactor/__init__.py | 60 +++---------------------- cbpi/extension/dummylogic/__init__.py | 7 ++- cbpi/extension/dummysensor/__init__.py | 51 +-------------------- config/actor.json | 26 ++++------- config/dashboard/cbpi_dashboard_1.json | 4 +- config/kettle.json | 43 +++++++++++++----- config/sensor.json | 18 +------- config/step_data.json | 56 +---------------------- craftbeerpi.db | Bin 53248 -> 53248 bytes 14 files changed, 65 insertions(+), 318 deletions(-) diff --git a/cbpi/api/__init__.py b/cbpi/api/__init__.py index 1b97489..d629a95 100644 --- a/cbpi/api/__init__.py +++ b/cbpi/api/__init__.py @@ -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 * diff --git a/cbpi/api/actor.py b/cbpi/api/actor.py index fa3022d..f7ebf25 100644 --- a/cbpi/api/actor.py +++ b/cbpi/api/actor.py @@ -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): diff --git a/cbpi/api/kettle_logic.py b/cbpi/api/kettle_logic.py index 673b79a..02874ca 100644 --- a/cbpi/api/kettle_logic.py +++ b/cbpi/api/kettle_logic.py @@ -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 diff --git a/cbpi/api/sensor.py b/cbpi/api/sensor.py index 987e095..de0568c 100644 --- a/cbpi/api/sensor.py +++ b/cbpi/api/sensor.py @@ -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 diff --git a/cbpi/controller/plugin_controller.py b/cbpi/controller/plugin_controller.py index baa10db..372b7fa 100644 --- a/cbpi/controller/plugin_controller.py +++ b/cbpi/controller/plugin_controller.py @@ -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): diff --git a/cbpi/extension/dummyactor/__init__.py b/cbpi/extension/dummyactor/__init__.py index 52067a0..e4557e7 100644 --- a/cbpi/extension/dummyactor/__init__.py +++ b/cbpi/extension/dummyactor/__init__.py @@ -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): ''' diff --git a/cbpi/extension/dummylogic/__init__.py b/cbpi/extension/dummylogic/__init__.py index 88b310a..5615277 100644 --- a/cbpi/extension/dummylogic/__init__.py +++ b/cbpi/extension/dummylogic/__init__.py @@ -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 diff --git a/cbpi/extension/dummysensor/__init__.py b/cbpi/extension/dummysensor/__init__.py index abfe25c..fdeb922 100644 --- a/cbpi/extension/dummysensor/__init__.py +++ b/cbpi/extension/dummysensor/__init__.py @@ -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) diff --git a/config/actor.json b/config/actor.json index 9605966..59aa613 100644 --- a/config/actor.json +++ b/config/actor.json @@ -1,24 +1,14 @@ { "data": [ { - "id": "9NkxVioA7FfZi6waegi246", - "name": "Manuel", - "props": {}, - "state": {}, - "type": "CustomActor" - }, - { - "id": "5hk68r3pFBe6JoRXzavLCA", - "name": "Actor 1", - "props": {}, - "state": {}, - "type": "CustomActor" - }, - { - "id": "YgVFNsXncfMMoHD7U6TvP6", - "name": "111", - "props": {}, - "state": {}, + "id": "8BLRqagLicCdEBDdc77Sgr", + "name": "Test", + "props": { + "Param3": 2, + "Param4": "", + "Param5": "8BLRqagLicCdEBDdc77Sgr" + }, + "state": false, "type": "CustomActor" } ] diff --git a/config/dashboard/cbpi_dashboard_1.json b/config/dashboard/cbpi_dashboard_1.json index 6447551..31fd9de 100644 --- a/config/dashboard/cbpi_dashboard_1.json +++ b/config/dashboard/cbpi_dashboard_1.json @@ -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, diff --git a/config/kettle.json b/config/kettle.json index 046d966..0b462d7 100644 --- a/config/kettle.json +++ b/config/kettle.json @@ -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" } ] diff --git a/config/sensor.json b/config/sensor.json index a311e6c..6346c5f 100644 --- a/config/sensor.json +++ b/config/sensor.json @@ -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" - } + ] } \ No newline at end of file diff --git a/config/step_data.json b/config/step_data.json index 973f247..ed352dd 100644 --- a/config/step_data.json +++ b/config/step_data.json @@ -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" - } + ] } \ No newline at end of file diff --git a/craftbeerpi.db b/craftbeerpi.db index 93e1d661b3cab056dda1fad1035b9b6e010a8ecb..ebaacfa358da2228addd69234c912e9b92787cb9 100644 GIT binary patch delta 56 zcmV-80LTA;paX!Q1CSd5r;!{(0jIHGre6pN01rVA+7Ah{5fGIQlcR2C1vUc)B`K2; OZyEzJF)_0%Z`EM+kP!j^ delta 55 zcmV-70LcG