From 2779c3cc2c3c5908f0063867551359c6dea382be Mon Sep 17 00:00:00 2001 From: Manuel Fritsch Date: Tue, 26 Jan 2021 20:21:53 +0100 Subject: [PATCH] reuqirements.txt updated --- cbpi/__init__.py | 2 +- cbpi/api/kettle_logic.py | 9 +- cbpi/cli.py | 34 ++++++- cbpi/config/config.yaml | 2 +- cbpi/config/dashboard/cbpi_dashboard_1.json | 3 + cbpi/config/plugin_list.txt | 3 + cbpi/controller/basic_controller.py | 8 +- cbpi/controller/dashboard_controller.py | 11 ++- cbpi/controller/plugin_controller.py | 2 +- cbpi/extension/dummysensor/__init__.py | 1 - cbpi/http_endpoints/http_dashboard.py | 5 +- config/cbpi_dashboard_1.json | 64 +++++++++++++ config/dashboard/widgets/kettle.svg | 81 ++++++++++++++++ config/dashboard/widgets/tank.svg | 101 ++++++++++++++++++++ config/step_data.json | 12 ++- requirements.txt | 28 +++--- setup.py | 5 +- 17 files changed, 329 insertions(+), 42 deletions(-) create mode 100644 cbpi/config/dashboard/cbpi_dashboard_1.json create mode 100644 config/cbpi_dashboard_1.json create mode 100644 config/dashboard/widgets/kettle.svg create mode 100644 config/dashboard/widgets/tank.svg diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 5fada43..f5d10d4 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1 +1 @@ -__version__ = "4.0.0.8" \ No newline at end of file +__version__ = "4.0.0.12" \ No newline at end of file diff --git a/cbpi/api/kettle_logic.py b/cbpi/api/kettle_logic.py index 02874ca..ef52353 100644 --- a/cbpi/api/kettle_logic.py +++ b/cbpi/api/kettle_logic.py @@ -28,16 +28,11 @@ class CBPiKettleLogic(metaclass=ABCMeta): await asyncio.sleep(1) def get_state(self): - print("########STATE", self.state) + return dict(state=self.state) async def start(self): - print("") - print("") - print("") - print("##################START UP KETTLE") - print("") - print("") + self.running = True async def stop(self): diff --git a/cbpi/cli.py b/cbpi/cli.py index a77471f..2330edb 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -13,8 +13,6 @@ import os import pathlib import shutil - - def create_plugin_file(): import os.path if os.path.exists(os.path.join(".", 'config', "plugin_list.txt")) is False: @@ -31,10 +29,38 @@ def create_config_file(): shutil.copy(srcfile, destfile) print("Config Folder created") + if os.path.exists(os.path.join(".", 'config', "actor.json")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "actor.json") + destfile = os.path.join(".", 'config') + shutil.copy(srcfile, destfile) + + if os.path.exists(os.path.join(".", 'config', "sensor.json")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "sensor.json") + destfile = os.path.join(".", 'config') + shutil.copy(srcfile, destfile) + + if os.path.exists(os.path.join(".", 'config', "kettle.json")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "kettle.json") + destfile = os.path.join(".", 'config') + shutil.copy(srcfile, destfile) + + if os.path.exists(os.path.join(".", 'config', "step_data.json")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "step_data.json") + destfile = os.path.join(".", 'config') + shutil.copy(srcfile, destfile) + + if os.path.exists(os.path.join(".", 'config', "dashboard", "cbpi_dashboard_1.json")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "dashboard", "cbpi_dashboard_1.json") + destfile = os.path.join(".", "config", "dashboard") + shutil.copy(srcfile, destfile) + + def create_home_folder_structure(): pathlib.Path(os.path.join(".", 'logs/sensors')).mkdir(parents=True, exist_ok=True) pathlib.Path(os.path.join(".", 'config')).mkdir(parents=True, exist_ok=True) - print("Log Folder created") + pathlib.Path(os.path.join(".", 'config/dasboard')).mkdir(parents=True, exist_ok=True) + pathlib.Path(os.path.join(".", 'config/dasboard/widgets')).mkdir(parents=True, exist_ok=True) + print("Folder created") def copy_splash(): srcfile = os.path.join(os.path.dirname(__file__), "config", "splash.png") @@ -123,7 +149,7 @@ def remove(package_name): match_uninstalled = re.search(pattern, data) if match_uninstalled is None: - print(data) + print("Faild to uninstall plugin") return False diff --git a/cbpi/config/config.yaml b/cbpi/config/config.yaml index 27d1a5d..cc1c19d 100644 --- a/cbpi/config/config.yaml +++ b/cbpi/config/config.yaml @@ -2,7 +2,7 @@ name: CraftBeerPi version: 4.0.8 -#: /myext +index_url: /cbpi_ui/static/index.html port: 8000 diff --git a/cbpi/config/dashboard/cbpi_dashboard_1.json b/cbpi/config/dashboard/cbpi_dashboard_1.json new file mode 100644 index 0000000..92079a0 --- /dev/null +++ b/cbpi/config/dashboard/cbpi_dashboard_1.json @@ -0,0 +1,3 @@ +{ + "elements": [] +} \ No newline at end of file diff --git a/cbpi/config/plugin_list.txt b/cbpi/config/plugin_list.txt index e69de29..da44c91 100644 --- a/cbpi/config/plugin_list.txt +++ b/cbpi/config/plugin_list.txt @@ -0,0 +1,3 @@ +cbpi4-ui: + installation_date: '2021-01-06 16:03:31' + version: '0.0.1' \ No newline at end of file diff --git a/cbpi/controller/basic_controller.py b/cbpi/controller/basic_controller.py index 658a326..2f14006 100644 --- a/cbpi/controller/basic_controller.py +++ b/cbpi/controller/basic_controller.py @@ -90,11 +90,11 @@ class BasicController: return type = item["type"] - print(type) - print(self.types) + + clazz = self.types[type]["class"] item["instance"] = clazz(self.cbpi, item["id"], {}) - print(item["instance"]) + await item["instance"].start() item["instance"].task = self._loop.create_task(item["instance"].run()) logging.info("Sensor started {}".format(id)) @@ -142,7 +142,7 @@ class BasicController: logging.info("{} call all Action {} {}".format(self.name, id, action)) try: item = self.find_by_id(id) - print(item) + instance = item.get("instance") await instance.__getattribute__(action)(**parameter) except Exception as e: diff --git a/cbpi/controller/dashboard_controller.py b/cbpi/controller/dashboard_controller.py index 299d335..f8963b2 100644 --- a/cbpi/controller/dashboard_controller.py +++ b/cbpi/controller/dashboard_controller.py @@ -11,22 +11,25 @@ class DashboardController(): self.logger = logging.getLogger(__name__) self.cbpi.register(self) + self.path = os.path.join(".", 'config', "cbpi_dashboard_1.json") + async def init(self): pass async def get_content(self, dashboard_id): try: - with open('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id) as json_file: + with open(self.path) as json_file: data = json.load(json_file) return data except: return {} async def add_content(self, dashboard_id, data): - with open('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id, 'w') as outfile: + with open(self.path, 'w') as outfile: json.dump(data, outfile, indent=4, sort_keys=True) return {"status": "OK"} async def delete_content(self, dashboard_id): - if os.path.exists('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id): - os.remove('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id) + if os.path.exists(self.path): + os.remove(self.path) + diff --git a/cbpi/controller/plugin_controller.py b/cbpi/controller/plugin_controller.py index 372b7fa..619a995 100644 --- a/cbpi/controller/plugin_controller.py +++ b/cbpi/controller/plugin_controller.py @@ -173,7 +173,7 @@ class PluginController(): for method_name, method in cls.__dict__.items(): if hasattr(method, "action"): - print(method_name) + key = method.__getattribute__("key") parameters = [] for p in method.__getattribute__("parameters"): diff --git a/cbpi/extension/dummysensor/__init__.py b/cbpi/extension/dummysensor/__init__.py index 65ae6b2..32df456 100644 --- a/cbpi/extension/dummysensor/__init__.py +++ b/cbpi/extension/dummysensor/__init__.py @@ -34,7 +34,6 @@ class CustomSensor(CBPiSensor): async def run(self): while self.running is True: - print("HALLO") self.value = random.randint(0,50) self.push_update(self.value) await asyncio.sleep(1) diff --git a/cbpi/http_endpoints/http_dashboard.py b/cbpi/http_endpoints/http_dashboard.py index c447b20..c18d74f 100644 --- a/cbpi/http_endpoints/http_dashboard.py +++ b/cbpi/http_endpoints/http_dashboard.py @@ -4,6 +4,7 @@ from voluptuous import Schema from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints from cbpi.utils import json_dumps +import os class DashBoardHttpEndpoints(HttpCrudEndpoints): @@ -11,9 +12,7 @@ class DashBoardHttpEndpoints(HttpCrudEndpoints): def __init__(self, cbpi): self.cbpi = cbpi self.controller = cbpi.dashboard - self.cbpi.register(self, "/dashboard") - - + self.cbpi.register(self, "/dashboard", os.path.join(".","config", "dashboard", "widgets")) @request_mapping(path="/{id:\d+}/content", auth_required=False) diff --git a/config/cbpi_dashboard_1.json b/config/cbpi_dashboard_1.json new file mode 100644 index 0000000..5f3b3f8 --- /dev/null +++ b/config/cbpi_dashboard_1.json @@ -0,0 +1,64 @@ +{ + "elements": [ + { + "id": "6c670263-7b19-426c-8769-19aac8ebb381", + "name": "CustomSVG", + "props": { + "name": "tank", + "width": "200" + }, + "type": "CustomSVG", + "x": 295, + "y": 45 + }, + { + "id": "cbe859ca-b8e8-433f-952c-938a2f8a309b", + "name": "CustomSVG", + "props": { + "name": "tank", + "width": "100" + }, + "type": "CustomSVG", + "x": 555, + "y": 55 + }, + { + "id": "1f1d5ee6-1ccc-409b-a240-c81d50b71627", + "name": "CustomSVG", + "props": { + "name": "kettle", + "width": "100" + }, + "type": "CustomSVG", + "x": 795, + "y": 90 + } + ], + "pathes": [ + { + "coordinates": [ + [ + 305, + 75 + ], + [ + 160, + 190 + ], + [ + 245, + 460 + ], + [ + 525, + 395 + ], + [ + 560, + 75 + ] + ], + "id": "d22d65d2-c4db-4553-856a-e9239a79e136" + } + ] +} \ No newline at end of file diff --git a/config/dashboard/widgets/kettle.svg b/config/dashboard/widgets/kettle.svg new file mode 100644 index 0000000..a2000ef --- /dev/null +++ b/config/dashboard/widgets/kettle.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/dashboard/widgets/tank.svg b/config/dashboard/widgets/tank.svg new file mode 100644 index 0000000..5eaf7b7 --- /dev/null +++ b/config/dashboard/widgets/tank.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/step_data.json b/config/step_data.json index 4bd1d70..8bf517b 100644 --- a/config/step_data.json +++ b/config/step_data.json @@ -3,6 +3,16 @@ "name": "" }, "profile": [ - + { + "id": "6mdUtsrBaWeDvKgUXJiLqu", + "name": "Test", + "props": { + "Param1": 123, + "Param2": "HALLO", + "Param3": 1 + }, + "status": "I", + "type": "CustomStep2" + } ] } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3ee8248..15480d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,16 @@ -pandas -aiohttp>=3.4.4 -aiohttp-auth>=0.1.1 -aiohttp-route-decorator>=0.1.4 -aiohttp-security>=0.4.0 -aiohttp-session>=2.7.0 -aiohttp-swagger>=1.0.5 -aiojobs>=0.2.2 -aiosqlite>=0.7.0 -cryptography>=2.3.1 -voluptuous>=0.11.5 -pyfiglet>=0.7.6 +aiohttp==3.7.3 +aiohttp-auth==0.1.1 +aiohttp-route-decorator==0.1.4 +aiohttp-security==0.4.0 +aiohttp-session==2.9.0 +aiohttp-swagger==1.0.15 +aiojobs==0.3.0 +aiosqlite==0.16.0 +cryptography==3.3.1 +requests==2.25.1 +voluptuous==0.12.1 +pyfiglet==0.8.post1 +pandas==1.1.5 shortuuid==1.0.1 -tabulate==0.8.7 \ No newline at end of file +tabulate==0.8.7 +cbpi4-ui==0.0.2 \ No newline at end of file diff --git a/setup.py b/setup.py index 0946b45..b2261fa 100644 --- a/setup.py +++ b/setup.py @@ -27,9 +27,10 @@ setup(name='cbpi', "requests==2.25.1", "voluptuous==0.12.1", "pyfiglet==0.8.post1", - 'pandas==1.2.0', + 'pandas==1.1.5', 'shortuuid==1.0.1', - 'tabulate==0.8.7' + 'tabulate==0.8.7', + 'cbpi4-ui==0.0.2', ], dependency_links=[ 'https://testpypi.python.org/pypi'