From 7ab75f0b013ee205cf01946678b6ed824df02c66 Mon Sep 17 00:00:00 2001 From: manuel83 Date: Sat, 5 Jan 2019 20:43:48 +0100 Subject: [PATCH] setuptools added --- .gitignore | 7 +- .idea/craftbeerpi4.iml | 5 +- .idea/dataSources.local.xml | 18 + .idea/dataSources.xml | 51 + .idea/workspace.xml | 1125 +++++++++-------- Dockerfile | 8 +- MANIFEST.in | 2 + {core => cbpi}/__init__.py | 0 cbpi/api/__init__.py | 27 + cbpi/api/actor.py | 49 + cbpi/api/config.py | 8 + cbpi/api/decorator.py | 96 ++ cbpi/api/exceptions.py | 14 + cbpi/api/extension.py | 54 + cbpi/api/kettle_logic.py | 38 + cbpi/api/property.py | 113 ++ cbpi/api/sensor.py | 38 + cbpi/api/step.py | 134 ++ cbpi/cli.py | 42 + cbpi/config/config.yaml | 11 + {config => cbpi/config}/create_database.sql | 0 cbpi/config/plugin_list.txt | 1 + {core => cbpi}/controller/__init__.py | 0 {core => cbpi}/controller/actor_controller.py | 6 +- .../controller/config_controller.py | 10 +- {core => cbpi}/controller/crud_controller.py | 2 +- .../controller/dashboard_controller.py | 4 +- {core => cbpi}/controller/job_controller.py | 2 +- .../controller/kettle_controller.py | 13 +- .../controller/notification_controller.py | 2 +- .../controller/plugin_controller.py | 19 +- .../controller/sensor_controller.py | 11 +- {core => cbpi}/controller/step_controller.py | 8 +- .../controller/system_controller.py | 4 +- {core => cbpi}/craftbeerpi.py | 54 +- {core => cbpi}/database/__init__.py | 0 {core => cbpi}/database/model.py | 5 +- {core => cbpi}/database/orm_framework.py | 4 +- {core => cbpi}/eventbus.py | 11 +- {core => cbpi}/extension/__init__.py | 0 {core => cbpi}/extension/comp/__init__.py | 16 +- {core => cbpi}/extension/comp/config.yaml | 0 .../extension/comp/static/index.html | 0 .../extension/comp/static/index2.html | 0 .../extension/dummyactor/__init__.py | 4 +- .../extension/dummyactor/config.yaml | 0 .../extension/dummylogic/__init__.py | 2 +- .../extension/dummylogic/config.yaml | 0 .../extension/dummysensor/__init__.py | 2 +- .../extension/dummysensor/config.yaml | 0 .../extension/dummystep/__init__.py | 2 +- .../extension/dummystep/config.yaml | 0 {core => cbpi}/http_endpoints/__init__.py | 0 {core => cbpi}/http_endpoints/http_actor.py | 6 +- {core => cbpi}/http_endpoints/http_config.py | 7 +- .../http_endpoints/http_curd_endpoints.py | 4 +- .../http_endpoints/http_dashboard.py | 7 +- {core => cbpi}/http_endpoints/http_kettle.py | 4 +- {core => cbpi}/http_endpoints/http_login.py | 2 +- {core => cbpi}/http_endpoints/http_sensor.py | 6 +- {core => cbpi}/http_endpoints/http_step.py | 6 +- {core => cbpi}/job/__init__.py | 0 {core => cbpi}/job/_job.py | 0 {core => cbpi}/job/_scheduler.py | 0 {core => cbpi}/job/aiohttp.py | 0 {core => cbpi}/mqtt/__init__.py | 0 {core => cbpi}/mqtt/mqtt.py | 2 +- {core => cbpi}/mqtt/mqtt_matcher.py | 0 cbpi/utils/__init__.py | 1 + {core => cbpi}/utils/encoder.py | 2 +- {core => cbpi}/utils/utils.py | 2 +- {core => cbpi}/websocket.py | 6 +- config/plugin_list.txt | 2 - core/utils/__init__.py | 1 - craftbeerpi.db | Bin 53248 -> 53248 bytes logs/sensors/sensor_1.log | 34 - logs/sensors/sensor_1.log.1 | 86 -- logs/sensors/sensor_1.log.10 | 5 - logs/sensors/sensor_1.log.2 | 5 - logs/sensors/sensor_1.log.3 | 5 - logs/sensors/sensor_1.log.4 | 5 - logs/sensors/sensor_1.log.5 | 5 - logs/sensors/sensor_1.log.6 | 5 - logs/sensors/sensor_1.log.7 | 5 - logs/sensors/sensor_1.log.8 | 5 - logs/sensors/sensor_1.log.9 | 5 - logs/sensors/sensor_2.log | 23 - logs/sensors/sensor_2.log.1 | 86 -- logs/sensors/sensor_2.log.2 | 86 -- logs/sensors/sensor_2.log.3 | 86 -- requirements.txt | 62 +- run.py | 5 +- setup.py | 37 + tests/test_actor.py | 2 +- tests/test_config.py | 4 +- tests/test_dashboard.py | 2 +- tests/test_index.py | 2 +- tests/test_kettle.py | 2 +- tests/test_notification_controller.py | 2 +- tests/test_sensor.py | 2 +- tests/test_step.py | 2 +- tests/test_system.py | 2 +- tests/test_utils.py | 2 +- tests/test_ws.py | 2 +- 104 files changed, 1446 insertions(+), 1208 deletions(-) create mode 100644 MANIFEST.in rename {core => cbpi}/__init__.py (100%) create mode 100644 cbpi/api/__init__.py create mode 100644 cbpi/api/actor.py create mode 100644 cbpi/api/config.py create mode 100644 cbpi/api/decorator.py create mode 100644 cbpi/api/exceptions.py create mode 100644 cbpi/api/extension.py create mode 100644 cbpi/api/kettle_logic.py create mode 100644 cbpi/api/property.py create mode 100644 cbpi/api/sensor.py create mode 100644 cbpi/api/step.py create mode 100644 cbpi/cli.py create mode 100644 cbpi/config/config.yaml rename {config => cbpi/config}/create_database.sql (100%) create mode 100644 cbpi/config/plugin_list.txt rename {core => cbpi}/controller/__init__.py (100%) rename {core => cbpi}/controller/actor_controller.py (97%) rename {core => cbpi}/controller/config_controller.py (87%) rename {core => cbpi}/controller/crud_controller.py (96%) rename {core => cbpi}/controller/dashboard_controller.py (86%) rename {core => cbpi}/controller/job_controller.py (96%) rename {core => cbpi}/controller/kettle_controller.py (95%) rename {core => cbpi}/controller/notification_controller.py (94%) rename {core => cbpi}/controller/plugin_controller.py (89%) rename {core => cbpi}/controller/sensor_controller.py (89%) rename {core => cbpi}/controller/step_controller.py (97%) rename {core => cbpi}/controller/system_controller.py (93%) rename {core => cbpi}/craftbeerpi.py (84%) rename {core => cbpi}/database/__init__.py (100%) rename {core => cbpi}/database/model.py (96%) rename {core => cbpi}/database/orm_framework.py (97%) rename {core => cbpi}/eventbus.py (97%) rename {core => cbpi}/extension/__init__.py (100%) rename {core => cbpi}/extension/comp/__init__.py (70%) rename {core => cbpi}/extension/comp/config.yaml (100%) rename {core => cbpi}/extension/comp/static/index.html (100%) rename {core => cbpi}/extension/comp/static/index2.html (100%) rename {core => cbpi}/extension/dummyactor/__init__.py (97%) rename {core => cbpi}/extension/dummyactor/config.yaml (100%) rename {core => cbpi}/extension/dummylogic/__init__.py (98%) rename {core => cbpi}/extension/dummylogic/config.yaml (100%) rename {core => cbpi}/extension/dummysensor/__init__.py (97%) rename {core => cbpi}/extension/dummysensor/config.yaml (100%) rename {core => cbpi}/extension/dummystep/__init__.py (96%) rename {core => cbpi}/extension/dummystep/config.yaml (100%) rename {core => cbpi}/http_endpoints/__init__.py (100%) rename {core => cbpi}/http_endpoints/http_actor.py (97%) rename {core => cbpi}/http_endpoints/http_config.py (91%) rename {core => cbpi}/http_endpoints/http_curd_endpoints.py (96%) rename {core => cbpi}/http_endpoints/http_dashboard.py (97%) rename {core => cbpi}/http_endpoints/http_kettle.py (95%) rename {core => cbpi}/http_endpoints/http_login.py (97%) rename {core => cbpi}/http_endpoints/http_sensor.py (95%) rename {core => cbpi}/http_endpoints/http_step.py (97%) rename {core => cbpi}/job/__init__.py (100%) rename {core => cbpi}/job/_job.py (100%) rename {core => cbpi}/job/_scheduler.py (100%) rename {core => cbpi}/job/aiohttp.py (100%) rename {core => cbpi}/mqtt/__init__.py (100%) rename {core => cbpi}/mqtt/mqtt.py (98%) rename {core => cbpi}/mqtt/mqtt_matcher.py (100%) create mode 100644 cbpi/utils/__init__.py rename {core => cbpi}/utils/encoder.py (90%) rename {core => cbpi}/utils/utils.py (86%) rename {core => cbpi}/websocket.py (95%) delete mode 100644 core/utils/__init__.py delete mode 100644 logs/sensors/sensor_1.log delete mode 100644 logs/sensors/sensor_1.log.1 delete mode 100644 logs/sensors/sensor_1.log.10 delete mode 100644 logs/sensors/sensor_1.log.2 delete mode 100644 logs/sensors/sensor_1.log.3 delete mode 100644 logs/sensors/sensor_1.log.4 delete mode 100644 logs/sensors/sensor_1.log.5 delete mode 100644 logs/sensors/sensor_1.log.6 delete mode 100644 logs/sensors/sensor_1.log.7 delete mode 100644 logs/sensors/sensor_1.log.8 delete mode 100644 logs/sensors/sensor_1.log.9 delete mode 100644 logs/sensors/sensor_2.log delete mode 100644 logs/sensors/sensor_2.log.1 delete mode 100644 logs/sensors/sensor_2.log.2 delete mode 100644 logs/sensors/sensor_2.log.3 create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 0707a32..6c9203b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.pyc - docs_src/build/ - +build +dist +.idea +*.log +cbpi.egg-info \ No newline at end of file diff --git a/.idea/craftbeerpi4.iml b/.idea/craftbeerpi4.iml index 7857219..f9cabb2 100644 --- a/.idea/craftbeerpi4.iml +++ b/.idea/craftbeerpi4.iml @@ -2,13 +2,14 @@ - + + - \ No newline at end of file diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 2488295..a5d569c 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -14,5 +14,23 @@ false *:@ + + + + false + *:@ + + + + + false + *:@ + + + + + false + *:@ + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index a24bede..9b913ae 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -27,5 +27,56 @@ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/test/craftbeerpi.db + + + + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/xerial-sqlite-license.txt + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/sqlite-jdbc-3.16.1.jar + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/test22/craftbeerpi.db + + + + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/xerial-sqlite-license.txt + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/sqlite-jdbc-3.16.1.jar + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/cbpi/craftbeerpi.db + + + + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/xerial-sqlite-license.txt + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.16.1/sqlite-jdbc-3.16.1.jar + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d8b89b4..fbfb8e4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,39 +2,105 @@ + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -53,16 +121,17 @@ - + - + + - + + + + + + + + - - - - - - - - @@ -356,6 +437,28 @@ + + + + + + + + + - - - - - - - - - @@ -557,7 +656,7 @@ - + 1541288846149 @@ -577,18 +676,6 @@ - - - - - - - - - - - - @@ -607,9 +694,21 @@ + + + + + + + + + + + + - @@ -622,16 +721,17 @@ + - + - - + + @@ -643,40 +743,13 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - - - - - + + - - - - - - + + - - - - - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + + + + + + + - - - - + + + + + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -919,120 +1005,103 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + + - + - - - - - - - - + + - + - - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1041,82 +1110,24 @@ - + - - - - - + + - - - - - - - - + - - - - + + - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Dockerfile b/Dockerfile index ae7a12c..4252cd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ -FROM python:3 +FROM python:3.5.6-stretch WORKDIR /usr/src/app -COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt +COPY dist/cbpi-0.0.1.tar.gz ./ +RUN pip install cbpi-0.0.1.tar.gz --no-cache-dir COPY . . EXPOSE 8080 -CMD [ "python", "./run.py" ] +CMD [ "cbpi" ] diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e6120c3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include cbpi/config * +recursive-include cbpi/extension * \ No newline at end of file diff --git a/core/__init__.py b/cbpi/__init__.py similarity index 100% rename from core/__init__.py rename to cbpi/__init__.py diff --git a/cbpi/api/__init__.py b/cbpi/api/__init__.py new file mode 100644 index 0000000..9b3a8ed --- /dev/null +++ b/cbpi/api/__init__.py @@ -0,0 +1,27 @@ +__all__ = ["CBPiActor", + "CBPiExtension", + "Property", + "PropertyType", + "on_websocket_message", + "on_mqtt_message", + "on_event", + "on_startup", + "request_mapping", + "action", + "background_task", + "CBPiKettleLogic", + "CBPiSimpleStep", + "CBPiException", + "KettleException", + "SensorException", + "ActorException", + "CBPiSensor"] + +from cbpi.api.actor import * +from cbpi.api.sensor import * +from cbpi.api.extension import * +from cbpi.api.property import * +from cbpi.api.decorator import * +from cbpi.api.kettle_logic import * +from cbpi.api.step import * +from cbpi.api.exceptions import * \ No newline at end of file diff --git a/cbpi/api/actor.py b/cbpi/api/actor.py new file mode 100644 index 0000000..07271db --- /dev/null +++ b/cbpi/api/actor.py @@ -0,0 +1,49 @@ +from abc import ABCMeta + +from cbpi.api.extension import CBPiExtension + +__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 state(self): + + ''' + Return the current actor state + + :return: + ''' + + pass + + def reprJSON(self): + return dict(state=True) \ No newline at end of file diff --git a/cbpi/api/config.py b/cbpi/api/config.py new file mode 100644 index 0000000..35ed0ea --- /dev/null +++ b/cbpi/api/config.py @@ -0,0 +1,8 @@ +from enum import Enum + +class ConfigType(Enum): + STRING = "string" + NUMBER = "number" + SELECT = "select" + + diff --git a/cbpi/api/decorator.py b/cbpi/api/decorator.py new file mode 100644 index 0000000..83a02c8 --- /dev/null +++ b/cbpi/api/decorator.py @@ -0,0 +1,96 @@ +__all__ = ["request_mapping", "on_startup", "on_event", "on_mqtt_message", "on_websocket_message", "action", "background_task"] + +from aiohttp_auth import auth + +def composed(*decs): + def deco(f): + for dec in reversed(decs): + f = dec(f) + return f + return deco + +def request_mapping(path, name=None, method="GET", auth_required=True): + + def on_http_request(path, name=None): + def real_decorator(func): + func.route = True + func.path = path + func.name = name + func.method = method + return func + + return real_decorator + + if auth_required is True: + return composed( + on_http_request(path, name), + auth.auth_required + ) + else: + return composed( + on_http_request(path, name) + ) + +def on_websocket_message(path, name=None): + def real_decorator(func): + func.ws = True + func.key = path + func.name = name + return func + + return real_decorator + +def on_event(topic): + def real_decorator(func): + func.eventbus = True + func.topic = topic + func.c = None + return func + + return real_decorator + +def action(key, parameters): + def real_decorator(func): + func.action = True + + func.key = key + func.parameters = parameters + return func + + return real_decorator + +def on_mqtt_message(topic): + def real_decorator(func): + func.mqtt = True + func.topic = topic + return func + + return real_decorator + + +def background_task(name, interval): + def real_decorator(func): + func.background_task = True + func.name = name + func.interval = interval + return func + + return real_decorator + + +def on_startup(name, order=0): + def real_decorator(func): + func.on_startup = True + func.name = name + func.order = order + return func + + return real_decorator + + +def entry_exit(f): + def new_f(): + + f() + + return new_f \ No newline at end of file diff --git a/cbpi/api/exceptions.py b/cbpi/api/exceptions.py new file mode 100644 index 0000000..77af2f6 --- /dev/null +++ b/cbpi/api/exceptions.py @@ -0,0 +1,14 @@ +__all__ = ["CBPiException","KettleException","SensorException","ActorException"] + + +class CBPiException(Exception): + pass + +class KettleException(CBPiException): + pass + +class SensorException(CBPiException): + pass + +class ActorException(CBPiException): + pass \ No newline at end of file diff --git a/cbpi/api/extension.py b/cbpi/api/extension.py new file mode 100644 index 0000000..23f0c77 --- /dev/null +++ b/cbpi/api/extension.py @@ -0,0 +1,54 @@ +import logging +import os +import sys + +import yaml + +__all__ = ["CBPiExtension"] + + + +logger = logging.getLogger(__file__) + + + +class CBPiExtension(): + + def init(self): + pass + + def stop(self): + pass + + def __init__(self, *args, **kwds): + + for a in kwds: + logger.debug("Parameter: %s Value: %s" % ( a, kwds.get(a))) + super(CBPiExtension, self).__setattr__(a, kwds.get(a)) + self.cbpi = kwds.get("cbpi") + self.id = kwds.get("id") + self.value = None + self.__dirty = False + + def __setattr__(self, name, value): + + if name != "_CBPiExtension__dirty": + self.__dirty = True + super(CBPiExtension, self).__setattr__(name, value) + else: + super(CBPiExtension, self).__setattr__(name, value) + + def load_config(self): + + path = os.path.dirname(sys.modules[self.__class__.__module__].__file__) + + try: + with open("%s/config.yaml" % path, 'rt') as f: + data = yaml.load(f) + + return data + except: + logger.warning("Faild to load config %s/config.yaml" % path) + + + diff --git a/cbpi/api/kettle_logic.py b/cbpi/api/kettle_logic.py new file mode 100644 index 0000000..210c9ae --- /dev/null +++ b/cbpi/api/kettle_logic.py @@ -0,0 +1,38 @@ +from cbpi.api.extension import CBPiExtension + + +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 \ No newline at end of file diff --git a/cbpi/api/property.py b/cbpi/api/property.py new file mode 100644 index 0000000..98f44ca --- /dev/null +++ b/cbpi/api/property.py @@ -0,0 +1,113 @@ +__all__ = ["PropertyType", "Property"] + +class PropertyType(object): + pass + +class Property(object): + class Select(PropertyType): + + ''' + Select Property. The user can select value from list set as options parameter + ''' + + def __init__(self, label, options, description=""): + ''' + + :param label: + :param options: + :param description: + ''' + PropertyType.__init__(self) + self.label = label + self.options = options + self.description = description + + class Number(PropertyType): + + ''' + The user can set a number value + ''' + def __init__(self, label, configurable=False, default_value=None, unit="", description=""): + ''' + Test + + + :param label: + :param configurable: + :param default_value: + :param unit: + :param description: + ''' + PropertyType.__init__(self) + self.label = label + self.configurable = configurable + self.default_value = default_value + self.description = description + + class Text(PropertyType): + + ''' + The user can set a text value + ''' + def __init__(self, label, configurable=False, default_value="", description=""): + ''' + + :param label: + :param configurable: + :param default_value: + :param description: + ''' + PropertyType.__init__(self) + self.label = label + self.configurable = configurable + self.default_value = default_value + self.description = description + + class Actor(PropertyType): + + ''' + The user select an actor which is available in the system. The value of this variable will be the actor id + ''' + def __init__(self, label, description=""): + ''' + + :param label: + :param description: + ''' + PropertyType.__init__(self) + self.label = label + self.configurable = True + self.description = description + + class Sensor(PropertyType): + ''' + The user select a sensor which is available in the system. The value of this variable will be the sensor id + ''' + + def __init__(self, label, description=""): + ''' + + :param label: + :param description: + ''' + PropertyType.__init__(self) + self.label = label + self.configurable = True + self.description = description + + class Kettle(PropertyType): + ''' + The user select a kettle which is available in the system. The value of this variable will be the kettle id + ''' + + def __init__(self, label, description=""): + ''' + + :param label: + :param description: + ''' + + PropertyType.__init__(self) + self.label = label + self.configurable = True + self.description = description \ No newline at end of file diff --git a/cbpi/api/sensor.py b/cbpi/api/sensor.py new file mode 100644 index 0000000..a7c4909 --- /dev/null +++ b/cbpi/api/sensor.py @@ -0,0 +1,38 @@ +from logging.handlers import RotatingFileHandler +from time import localtime, strftime + +from cbpi.api.extension import CBPiExtension +import logging + + +class CBPiSensor(CBPiExtension): + def __init__(self, *args, **kwds): + CBPiExtension.__init__(self, *args, **kwds) + self.logger = logging.getLogger(__file__) + self.data_logger = None + + + + def log_data(self, value): + + formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime()) + + self.data_logger.debug("%s,%s" % (formatted_time, value)) + + + def init(self): + + + self.data_logger = logging.getLogger('cbpi.sensor.%s' % self.id) + self.data_logger.propagate = False + self.data_logger.setLevel(logging.DEBUG) + handler = RotatingFileHandler('./logs/sensors/sensor_%s.log' % self.id, maxBytes=2000, backupCount=10) + self.data_logger.addHandler(handler) + pass + + + async def run(self, cbpi): + self.logger.warning("Sensor Init not implemented") + + def state(self): + pass \ No newline at end of file diff --git a/cbpi/api/step.py b/cbpi/api/step.py new file mode 100644 index 0000000..08c2626 --- /dev/null +++ b/cbpi/api/step.py @@ -0,0 +1,134 @@ +import time +import asyncio +import logging +from abc import abstractmethod,ABCMeta + + +class CBPiSimpleStep(metaclass=ABCMeta): + + __dirty = False + managed_fields = [] + _interval = 0.1 + _max_exceptions = 2 + _exception_count = 0 + + def __init__(self, *args, **kwargs): + self.logger = logging.getLogger(__name__) + for a in kwargs: + super(CBPiSimpleStep, self).__setattr__(a, kwargs.get(a)) + self.id = kwargs.get("id") + self.is_stopped = False + self.is_next = False + self.start = time.time() + + def running(self): + ''' + Method checks if the step should continue running. + The method will return False if the step is requested to stop or the next step should start + + :return: True if the step is running. Otherwise False. + ''' + if self.is_next is True: + return False + + if self.is_stopped is True: + return False + + return True + + async def run(self): + + ''' + This method in running in the background. It invokes the run_cycle method in the configured interval + It checks if a managed variable was modified in the last exection cycle. If yes, the method will persisit the new value of the + managed property + + :return: None + ''' + + while self.running(): + try: + await self.run_cycle() + except Exception as e: + logging.exception("CBPiSimpleStep Error") + self._exception_count = self._exception_count + 1 + if self._exception_count == self._max_exceptions: + self.logger.error("Step Exception limit exceeded. Stopping Step") + self.stop() + + await asyncio.sleep(self._interval) + + if self.is_dirty(): + # Now we have to store the managed props + state = {} + for field in self.managed_fields: + state[field] = self.__getattribute__(field) + #step_controller.model.update_step_state(step_controller.current_step.id, state) + + await self.cbpi.step.model.update_step_state(self.id, state) + + self.reset_dirty() + + @abstractmethod + async def run_cycle(self): + ''' + This method is executed in the defined interval. + That the place to put your step logic. + The method need to be overwritten in the Ccstom step implementaion + + :return: None + ''' + + print("NOTING IMPLEMENTED") + pass + + def next(self): + + ''' + Request to stop the the step + + :return: None + ''' + + self.is_next = True + + def stop(self): + ''' + Request to stop the step + + :return: None + ''' + self.is_stopped = True + + def reset(self): + ''' + Reset the step. This method needs to be overwritten by the custom step implementation + + :return: None + ''' + pass + + def is_dirty(self): + + ''' + Check if a managed variable has a new value + + :return: True if at least one managed variable has a new value assigend. Otherwise False + ''' + return self.__dirty + + def reset_dirty(self): + ''' + Reset the dirty flag + + :return: + ''' + + self.__dirty = False + + def __setattr__(self, name, value): + if name != "_Step__dirty" and name in self.managed_fields: + self.__dirty = True + super(CBPiSimpleStep, self).__setattr__(name, value) + else: + super(CBPiSimpleStep, self).__setattr__(name, value) \ No newline at end of file diff --git a/cbpi/cli.py b/cbpi/cli.py new file mode 100644 index 0000000..4fe12df --- /dev/null +++ b/cbpi/cli.py @@ -0,0 +1,42 @@ +import logging + +from cbpi.craftbeerpi import CraftBeerPi +import os +import pathlib +import shutil + +logging.basicConfig(level=logging.INFO,filename='./logs/app.log', filemode='a', format='%(asctime)s - %(levelname)s - %(name)s - %(message)s') + +def create_plugin_file(): + import os.path + if os.path.exists(os.path.join(".", 'config', "plugin_list.txt")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "plugin_list.txt") + destfile = os.path.join(".", 'config') + shutil.copy(srcfile, destfile) + +def create_config_file(): + import os.path + if os.path.exists(os.path.join(".", 'config', "config.yaml")) is False: + srcfile = os.path.join(os.path.dirname(__file__), "config", "config.yaml") + destfile = os.path.join(".", 'config') + 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) + + +def main(): + #import sys + #arg1, arg2 = sys.argv[1], sys.argv[2] + + create_home_folder_structure() + create_plugin_file() + create_config_file() + + + cbpi = CraftBeerPi() + cbpi.start() + + + diff --git a/cbpi/config/config.yaml b/cbpi/config/config.yaml new file mode 100644 index 0000000..f05f964 --- /dev/null +++ b/cbpi/config/config.yaml @@ -0,0 +1,11 @@ + +name: CraftBeerPi +version: 4.1 + +#index_url: /myext + +port: 8080 + +username: cbpi +password: 123 + diff --git a/config/create_database.sql b/cbpi/config/create_database.sql similarity index 100% rename from config/create_database.sql rename to cbpi/config/create_database.sql diff --git a/cbpi/config/plugin_list.txt b/cbpi/config/plugin_list.txt new file mode 100644 index 0000000..142c198 --- /dev/null +++ b/cbpi/config/plugin_list.txt @@ -0,0 +1 @@ +cbpi-actor \ No newline at end of file diff --git a/core/controller/__init__.py b/cbpi/controller/__init__.py similarity index 100% rename from core/controller/__init__.py rename to cbpi/controller/__init__.py diff --git a/core/controller/actor_controller.py b/cbpi/controller/actor_controller.py similarity index 97% rename from core/controller/actor_controller.py rename to cbpi/controller/actor_controller.py index 6f80755..b138363 100644 --- a/core/controller/actor_controller.py +++ b/cbpi/controller/actor_controller.py @@ -1,11 +1,11 @@ import logging from asyncio import Future -from cbpi_api import * +from cbpi.api import * from voluptuous import Schema -from core.controller.crud_controller import CRUDController -from core.database.model import ActorModel +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.model import ActorModel class ActorController(CRUDController): diff --git a/core/controller/config_controller.py b/cbpi/controller/config_controller.py similarity index 87% rename from core/controller/config_controller.py rename to cbpi/controller/config_controller.py index f245b18..224bc90 100644 --- a/core/controller/config_controller.py +++ b/cbpi/controller/config_controller.py @@ -1,10 +1,9 @@ import logging import os -from cbpi_api.config import ConfigType - -from core.database.model import ConfigModel -from utils import load_config +from cbpi.api.config import ConfigType +from cbpi.database.model import ConfigModel +from cbpi.utils import load_config class ConfigController(): @@ -21,7 +20,8 @@ class ConfigController(): async def init(self): this_directory = os.path.dirname(__file__) - self.static = load_config(os.path.join(this_directory, '../../config/config.yaml')) + + self.static = load_config("./config/config.yaml") items = await self.model.get_all() for key, value in items.items(): self.cache[value.name] = value diff --git a/core/controller/crud_controller.py b/cbpi/controller/crud_controller.py similarity index 96% rename from core/controller/crud_controller.py rename to cbpi/controller/crud_controller.py index 5f41ef8..506bead 100644 --- a/core/controller/crud_controller.py +++ b/cbpi/controller/crud_controller.py @@ -1,7 +1,7 @@ import pprint from abc import ABCMeta -from cbpi_api.exceptions import CBPiException +from cbpi.api import * class CRUDController(metaclass=ABCMeta): diff --git a/core/controller/dashboard_controller.py b/cbpi/controller/dashboard_controller.py similarity index 86% rename from core/controller/dashboard_controller.py rename to cbpi/controller/dashboard_controller.py index 98d823f..b4f9082 100644 --- a/core/controller/dashboard_controller.py +++ b/cbpi/controller/dashboard_controller.py @@ -2,8 +2,8 @@ import logging from voluptuous import Schema, MultipleInvalid -from core.controller.crud_controller import CRUDController -from core.database.model import DashboardModel, DashboardContentModel +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.model import DashboardModel, DashboardContentModel class DashboardController(CRUDController): diff --git a/core/controller/job_controller.py b/cbpi/controller/job_controller.py similarity index 96% rename from core/controller/job_controller.py rename to cbpi/controller/job_controller.py index e6e0e5f..9e58fb8 100644 --- a/core/controller/job_controller.py +++ b/cbpi/controller/job_controller.py @@ -1,7 +1,7 @@ import asyncio import logging -from job.aiohttp import setup, get_scheduler_from_app +from cbpi.job.aiohttp import setup, get_scheduler_from_app logger = logging.getLogger(__name__) class JobController(object): diff --git a/core/controller/kettle_controller.py b/cbpi/controller/kettle_controller.py similarity index 95% rename from core/controller/kettle_controller.py rename to cbpi/controller/kettle_controller.py index 3b48f8d..592f517 100644 --- a/core/controller/kettle_controller.py +++ b/cbpi/controller/kettle_controller.py @@ -1,13 +1,8 @@ import re - - -from cbpi_api import * -from cbpi_api.exceptions import KettleException, ActorException, SensorException - -from core.controller.crud_controller import CRUDController -from core.database.model import KettleModel - -from core.job.aiohttp import get_scheduler_from_app +from cbpi.api import * +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.model import KettleModel +from cbpi.job.aiohttp import get_scheduler_from_app class KettleController(CRUDController): diff --git a/core/controller/notification_controller.py b/cbpi/controller/notification_controller.py similarity index 94% rename from core/controller/notification_controller.py rename to cbpi/controller/notification_controller.py index 3e12bff..16577d9 100644 --- a/core/controller/notification_controller.py +++ b/cbpi/controller/notification_controller.py @@ -1,4 +1,4 @@ -from cbpi_api import * +from cbpi.api import * class NotificationController(object): diff --git a/core/controller/plugin_controller.py b/cbpi/controller/plugin_controller.py similarity index 89% rename from core/controller/plugin_controller.py rename to cbpi/controller/plugin_controller.py index 6c815fb..4919d49 100644 --- a/core/controller/plugin_controller.py +++ b/cbpi/controller/plugin_controller.py @@ -5,9 +5,9 @@ from importlib import import_module import aiohttp import yaml from aiohttp import web -from cbpi_api import * +from cbpi.api import * -from core.utils.utils import load_config, json_dumps +from cbpi.utils.utils import load_config, json_dumps logger = logging.getLogger(__name__) @@ -33,17 +33,20 @@ class PluginController(): def load_plugins(self): - for filename in os.listdir("./core/extension"): + this_directory = os.path.dirname(__file__) - if os.path.isdir("./core/extension/" + filename) is False or filename == "__pycache__": + for filename in os.listdir(os.path.join(this_directory, "../extension")): + + if os.path.isdir(os.path.join(this_directory, "../extension/") + filename) is False or filename == "__pycache__": continue try: logger.info("Trying to load plugin %s" % filename) - data = load_config("./core/extension/%s/config.yaml" % filename) + + data = load_config(os.path.join(this_directory, "../extension/%s/config.yaml" % filename)) if(data.get("version") == 4): - self.modules[filename] = import_module("core.extension.%s" % (filename)) + self.modules[filename] = import_module("cbpi.extension.%s" % (filename)) self.modules[filename].setup(self.cbpi) logger.info("Plugin %s loaded successful" % filename) @@ -57,8 +60,8 @@ class PluginController(): def load_plugins_from_evn(self): plugins = [] - - with open('./config/plugin_list.txt') as f: + this_directory = os.path.dirname(__file__) + with open(os.path.join(this_directory, "../config/plugin_list.txt")) as f: plugins = f.read().splitlines() plugins = list(set(plugins)) diff --git a/core/controller/sensor_controller.py b/cbpi/controller/sensor_controller.py similarity index 89% rename from core/controller/sensor_controller.py rename to cbpi/controller/sensor_controller.py index fb3f19c..b2fe700 100644 --- a/core/controller/sensor_controller.py +++ b/cbpi/controller/sensor_controller.py @@ -1,12 +1,9 @@ -import json + import logging +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.model import SensorModel +from cbpi.job.aiohttp import get_scheduler_from_app -from cbpi_api import request_mapping - -from core.controller.crud_controller import CRUDController -from core.database.model import SensorModel -from core.job.aiohttp import get_scheduler_from_app -from core.utils.encoder import ComplexEncoder class SensorController(CRUDController): diff --git a/core/controller/step_controller.py b/cbpi/controller/step_controller.py similarity index 97% rename from core/controller/step_controller.py rename to cbpi/controller/step_controller.py index 08809f3..703a73f 100644 --- a/core/controller/step_controller.py +++ b/cbpi/controller/step_controller.py @@ -1,11 +1,9 @@ -import asyncio import logging import time -from cbpi_api import * - -from core.controller.crud_controller import CRUDController -from core.database.model import StepModel +from cbpi.api import * +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.model import StepModel class StepController(CRUDController): diff --git a/core/controller/system_controller.py b/cbpi/controller/system_controller.py similarity index 93% rename from core/controller/system_controller.py rename to cbpi/controller/system_controller.py index aec1a53..47a0814 100644 --- a/core/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -2,9 +2,9 @@ import datetime from aiohttp import web from aiojobs.aiohttp import get_scheduler_from_app -from cbpi_api import * +from cbpi.api import * -from utils import json_dumps +from cbpi.utils import json_dumps class SystemController(): diff --git a/core/craftbeerpi.py b/cbpi/craftbeerpi.py similarity index 84% rename from core/craftbeerpi.py rename to cbpi/craftbeerpi.py index e8dde1d..4af48b3 100644 --- a/core/craftbeerpi.py +++ b/cbpi/craftbeerpi.py @@ -1,5 +1,4 @@ import logging -import os from os import urandom from aiohttp import web @@ -7,33 +6,36 @@ from aiohttp_auth import auth from aiohttp_session import session_middleware from aiohttp_session.cookie_storage import EncryptedCookieStorage from aiohttp_swagger import setup_swagger -from cbpi_api.exceptions import CBPiException +from cbpi.api.exceptions import CBPiException from voluptuous import MultipleInvalid -from controller.dashboard_controller import DashboardController -from controller.job_controller import JobController -from core.controller.actor_controller import ActorController -from core.controller.config_controller import ConfigController -from core.controller.kettle_controller import KettleController -from core.controller.notification_controller import NotificationController -from core.controller.plugin_controller import PluginController -from core.controller.sensor_controller import SensorController -from core.controller.step_controller import StepController -from core.controller.system_controller import SystemController -from core.database.model import DBModel -from core.eventbus import CBPiEventBus -from core.http_endpoints.http_login import Login -from core.utils import * -from core.websocket import CBPiWebSocket -from http_endpoints.http_actor import ActorHttpEndpoints -from http_endpoints.http_config import ConfigHttpEndpoints -from http_endpoints.http_dashboard import DashBoardHttpEndpoints -from http_endpoints.http_kettle import KettleHttpEndpoints -from http_endpoints.http_sensor import SensorHttpEndpoints -from http_endpoints.http_step import StepHttpEndpoints +from cbpi.controller.dashboard_controller import DashboardController +from cbpi.controller.job_controller import JobController +from cbpi.controller.actor_controller import ActorController +from cbpi.controller.config_controller import ConfigController +from cbpi.controller.kettle_controller import KettleController +from cbpi.controller.notification_controller import NotificationController +from cbpi.controller.plugin_controller import PluginController +from cbpi.controller.sensor_controller import SensorController +from cbpi.controller.step_controller import StepController +from cbpi.controller.system_controller import SystemController +from cbpi.database.model import DBModel +from cbpi.eventbus import CBPiEventBus +from cbpi.http_endpoints.http_login import Login +from cbpi.utils import * +from cbpi.websocket import CBPiWebSocket +from cbpi.http_endpoints.http_actor import ActorHttpEndpoints +from cbpi.http_endpoints.http_config import ConfigHttpEndpoints +from cbpi.http_endpoints.http_dashboard import DashBoardHttpEndpoints +from cbpi.http_endpoints.http_kettle import KettleHttpEndpoints +from cbpi.http_endpoints.http_sensor import SensorHttpEndpoints +from cbpi.http_endpoints.http_step import StepHttpEndpoints + logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) + + + @web.middleware async def error_middleware(request, handler): @@ -56,7 +58,9 @@ async def error_middleware(request, handler): class CraftBeerPi(): def __init__(self): - self.static_config = load_config(os.path.join(os.path.dirname(__file__), '../config/config.yaml')) + + + self.static_config = load_config("./config/config.yaml") self.database_file = "./craftbeerpi.db" logger.info("Init CraftBeerPI") diff --git a/core/database/__init__.py b/cbpi/database/__init__.py similarity index 100% rename from core/database/__init__.py rename to cbpi/database/__init__.py diff --git a/core/database/model.py b/cbpi/database/model.py similarity index 96% rename from core/database/model.py rename to cbpi/database/model.py index 8b5cee2..5c03512 100644 --- a/core/database/model.py +++ b/cbpi/database/model.py @@ -1,10 +1,9 @@ import json import aiosqlite -from cbpi_api.exceptions import CBPiException -from voluptuous import Schema, MultipleInvalid -from core.database.orm_framework import DBModel + +from cbpi.database.orm_framework import DBModel DATABASE_FILE = "./craftbeerpi.db" diff --git a/core/database/orm_framework.py b/cbpi/database/orm_framework.py similarity index 97% rename from core/database/orm_framework.py rename to cbpi/database/orm_framework.py index 3cbf08e..3d52185 100644 --- a/core/database/orm_framework.py +++ b/cbpi/database/orm_framework.py @@ -2,7 +2,7 @@ import json import aiosqlite import os -from cbpi_api.exceptions import CBPiException +from cbpi.api import * from voluptuous import MultipleInvalid, Schema DATABASE_FILE = "./craftbeerpi.db" @@ -38,7 +38,7 @@ class DBModel(object): async with aiosqlite.connect(DATABASE_FILE) as db: assert isinstance(db, aiosqlite.Connection) this_directory = os.path.dirname(__file__) - qry = open(os.path.join(this_directory, '../../config/create_database.sql'), 'r').read() + qry = open(os.path.join(this_directory, "../config/create_database.sql"), 'r').read() cursor = await db.executescript(qry) @classmethod diff --git a/core/eventbus.py b/cbpi/eventbus.py similarity index 97% rename from core/eventbus.py rename to cbpi/eventbus.py index 7f66bec..aa4fd25 100644 --- a/core/eventbus.py +++ b/cbpi/eventbus.py @@ -2,10 +2,12 @@ import asyncio import inspect import logging -from cbpi_api.exceptions import CBPiException +from cbpi.api import * class CBPiEventBus(object): + + class Node(object): __slots__ = '_children', '_content' @@ -22,17 +24,18 @@ class CBPiEventBus(object): self.topic = topic self.supports_future = supports_future - class Result(): + class Result: def __init__(self, result, timeout): self.result = result self.timeout = timeout - class ResultContainer(): + class ResultContainer: def __init__(self, results, timeout=False): self.results = {} self.timeout = timeout + self._jobs = set() for key, value in results.items(): if value.done() is True: self.results[key] = CBPiEventBus.Result(value.result(), True) @@ -108,7 +111,7 @@ class CBPiEventBus(object): def sync_fire(self,topic: str,timeout=1, **kwargs): self.loop.create_task(self.fire(topic=topic, timeout=timeout, **kwargs)) - async def fire(self, topic: str, timeout=1, **kwargs): + async def fire(self, topic: str, timeout=0.5, **kwargs): futures = {} diff --git a/core/extension/__init__.py b/cbpi/extension/__init__.py similarity index 100% rename from core/extension/__init__.py rename to cbpi/extension/__init__.py diff --git a/core/extension/comp/__init__.py b/cbpi/extension/comp/__init__.py similarity index 70% rename from core/extension/comp/__init__.py rename to cbpi/extension/comp/__init__.py index 0045bef..1a473af 100644 --- a/core/extension/comp/__init__.py +++ b/cbpi/extension/comp/__init__.py @@ -1,9 +1,11 @@ +import os + from aiohttp import web -from cbpi_api import * -from core.controller.crud_controller import CRUDController -from core.database.orm_framework import DBModel -from core.http_endpoints.http_api import HttpAPI +from cbpi.api import * +from cbpi.controller.crud_controller import CRUDController +from cbpi.database.orm_framework import DBModel +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints class DummyModel(DBModel): @@ -14,7 +16,7 @@ class DummyModel(DBModel): __table_name__ = "dummy" -class MyComp(CBPiExtension, CRUDController, HttpAPI): +class MyComp(CBPiExtension, CRUDController, HttpCrudEndpoints): model = DummyModel def __init__(self, cbpi): @@ -23,10 +25,12 @@ class MyComp(CBPiExtension, CRUDController, HttpAPI): :param cbpi: ''' + + self.cbpi = cbpi # register component for http, events # In addtion the sub folder static is exposed to access static content via http - self.cbpi.register(self, "/dummy", static="./core/extension/comp/static") + self.cbpi.register(self, "/dummy", static=os.path.join(os.path.dirname(__file__), "static")) @on_event(topic="actor/#") diff --git a/core/extension/comp/config.yaml b/cbpi/extension/comp/config.yaml similarity index 100% rename from core/extension/comp/config.yaml rename to cbpi/extension/comp/config.yaml diff --git a/core/extension/comp/static/index.html b/cbpi/extension/comp/static/index.html similarity index 100% rename from core/extension/comp/static/index.html rename to cbpi/extension/comp/static/index.html diff --git a/core/extension/comp/static/index2.html b/cbpi/extension/comp/static/index2.html similarity index 100% rename from core/extension/comp/static/index2.html rename to cbpi/extension/comp/static/index2.html diff --git a/core/extension/dummyactor/__init__.py b/cbpi/extension/dummyactor/__init__.py similarity index 97% rename from core/extension/dummyactor/__init__.py rename to cbpi/extension/dummyactor/__init__.py index f21060a..a8a890c 100644 --- a/core/extension/dummyactor/__init__.py +++ b/cbpi/extension/dummyactor/__init__.py @@ -1,8 +1,8 @@ import logging from unittest.mock import MagicMock, patch -from cbpi_api import * -from cbpi_api.exceptions import CBPiException +from cbpi.api import * + logger = logging.getLogger(__name__) diff --git a/core/extension/dummyactor/config.yaml b/cbpi/extension/dummyactor/config.yaml similarity index 100% rename from core/extension/dummyactor/config.yaml rename to cbpi/extension/dummyactor/config.yaml diff --git a/core/extension/dummylogic/__init__.py b/cbpi/extension/dummylogic/__init__.py similarity index 98% rename from core/extension/dummylogic/__init__.py rename to cbpi/extension/dummylogic/__init__.py index 2f024b1..3788526 100644 --- a/core/extension/dummylogic/__init__.py +++ b/cbpi/extension/dummylogic/__init__.py @@ -1,6 +1,6 @@ import asyncio -from cbpi_api import * +from cbpi.api import * class CustomLogic(CBPiKettleLogic): diff --git a/core/extension/dummylogic/config.yaml b/cbpi/extension/dummylogic/config.yaml similarity index 100% rename from core/extension/dummylogic/config.yaml rename to cbpi/extension/dummylogic/config.yaml diff --git a/core/extension/dummysensor/__init__.py b/cbpi/extension/dummysensor/__init__.py similarity index 97% rename from core/extension/dummysensor/__init__.py rename to cbpi/extension/dummysensor/__init__.py index 61b5755..2e3a69f 100644 --- a/core/extension/dummysensor/__init__.py +++ b/cbpi/extension/dummysensor/__init__.py @@ -2,7 +2,7 @@ import asyncio import logging import random -from cbpi_api import * +from cbpi.api import * class CustomSensor(CBPiSensor): diff --git a/core/extension/dummysensor/config.yaml b/cbpi/extension/dummysensor/config.yaml similarity index 100% rename from core/extension/dummysensor/config.yaml rename to cbpi/extension/dummysensor/config.yaml diff --git a/core/extension/dummystep/__init__.py b/cbpi/extension/dummystep/__init__.py similarity index 96% rename from core/extension/dummystep/__init__.py rename to cbpi/extension/dummystep/__init__.py index e4921f4..670934e 100644 --- a/core/extension/dummystep/__init__.py +++ b/cbpi/extension/dummystep/__init__.py @@ -1,6 +1,6 @@ import asyncio -from cbpi_api import * +from cbpi.api import * class CustomStepCBPi(CBPiSimpleStep): diff --git a/core/extension/dummystep/config.yaml b/cbpi/extension/dummystep/config.yaml similarity index 100% rename from core/extension/dummystep/config.yaml rename to cbpi/extension/dummystep/config.yaml diff --git a/core/http_endpoints/__init__.py b/cbpi/http_endpoints/__init__.py similarity index 100% rename from core/http_endpoints/__init__.py rename to cbpi/http_endpoints/__init__.py diff --git a/core/http_endpoints/http_actor.py b/cbpi/http_endpoints/http_actor.py similarity index 97% rename from core/http_endpoints/http_actor.py rename to cbpi/http_endpoints/http_actor.py index e084365..38b7dd7 100644 --- a/core/http_endpoints/http_actor.py +++ b/cbpi/http_endpoints/http_actor.py @@ -1,8 +1,8 @@ from aiohttp import web -from cbpi_api import request_mapping -from cbpi_api.exceptions import CBPiException +from cbpi.api import * + +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints auth = False class ActorHttpEndpoints(HttpCrudEndpoints): diff --git a/core/http_endpoints/http_config.py b/cbpi/http_endpoints/http_config.py similarity index 91% rename from core/http_endpoints/http_config.py rename to cbpi/http_endpoints/http_config.py index 2c72c92..b6a2156 100644 --- a/core/http_endpoints/http_config.py +++ b/cbpi/http_endpoints/http_config.py @@ -1,9 +1,8 @@ from aiohttp import web -from cbpi_api import request_mapping -from cbpi_api.exceptions import CBPiException +from cbpi.api import * -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints -from utils import json_dumps +from cbpi.utils import json_dumps +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints class ConfigHttpEndpoints(HttpCrudEndpoints): diff --git a/core/http_endpoints/http_curd_endpoints.py b/cbpi/http_endpoints/http_curd_endpoints.py similarity index 96% rename from core/http_endpoints/http_curd_endpoints.py rename to cbpi/http_endpoints/http_curd_endpoints.py index 83156e0..c918c1d 100644 --- a/core/http_endpoints/http_curd_endpoints.py +++ b/cbpi/http_endpoints/http_curd_endpoints.py @@ -1,9 +1,9 @@ import logging from aiohttp import web -from cbpi_api import * +from cbpi.api import * -from core.utils.utils import json_dumps +from cbpi.utils.utils import json_dumps class HttpCrudEndpoints(): diff --git a/core/http_endpoints/http_dashboard.py b/cbpi/http_endpoints/http_dashboard.py similarity index 97% rename from core/http_endpoints/http_dashboard.py rename to cbpi/http_endpoints/http_dashboard.py index 1af3c15..fe6e94f 100644 --- a/core/http_endpoints/http_dashboard.py +++ b/cbpi/http_endpoints/http_dashboard.py @@ -1,10 +1,9 @@ from aiohttp import web -from cbpi_api import request_mapping +from cbpi.api import * from voluptuous import Schema -from database.model import DashboardContentModel -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints -from utils import json_dumps +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints +from cbpi.utils import json_dumps class DashBoardHttpEndpoints(HttpCrudEndpoints): diff --git a/core/http_endpoints/http_kettle.py b/cbpi/http_endpoints/http_kettle.py similarity index 95% rename from core/http_endpoints/http_kettle.py rename to cbpi/http_endpoints/http_kettle.py index 263ef2b..671111d 100644 --- a/core/http_endpoints/http_kettle.py +++ b/cbpi/http_endpoints/http_kettle.py @@ -1,8 +1,8 @@ from aiohttp import web -from cbpi_api import request_mapping +from cbpi.api import * -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints auth = False diff --git a/core/http_endpoints/http_login.py b/cbpi/http_endpoints/http_login.py similarity index 97% rename from core/http_endpoints/http_login.py rename to cbpi/http_endpoints/http_login.py index 3151504..7be98cd 100644 --- a/core/http_endpoints/http_login.py +++ b/cbpi/http_endpoints/http_login.py @@ -1,7 +1,7 @@ from aiohttp import web from aiohttp_auth import auth -from cbpi_api import * +from cbpi.api import * class Login(): diff --git a/core/http_endpoints/http_sensor.py b/cbpi/http_endpoints/http_sensor.py similarity index 95% rename from core/http_endpoints/http_sensor.py rename to cbpi/http_endpoints/http_sensor.py index f503fab..dddd06a 100644 --- a/core/http_endpoints/http_sensor.py +++ b/cbpi/http_endpoints/http_sensor.py @@ -1,8 +1,6 @@ -from aiohttp import web -from cbpi_api import request_mapping -from cbpi_api.exceptions import CBPiException +from cbpi.api import request_mapping -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints class SensorHttpEndpoints(HttpCrudEndpoints): diff --git a/core/http_endpoints/http_step.py b/cbpi/http_endpoints/http_step.py similarity index 97% rename from core/http_endpoints/http_step.py rename to cbpi/http_endpoints/http_step.py index 1eb2e40..2d0d86c 100644 --- a/core/http_endpoints/http_step.py +++ b/cbpi/http_endpoints/http_step.py @@ -1,8 +1,8 @@ from aiohttp import web -from cbpi_api import request_mapping -from cbpi_api.exceptions import CBPiException +from cbpi.api import * -from http_endpoints.http_curd_endpoints import HttpCrudEndpoints + +from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints class StepHttpEndpoints(HttpCrudEndpoints): diff --git a/core/job/__init__.py b/cbpi/job/__init__.py similarity index 100% rename from core/job/__init__.py rename to cbpi/job/__init__.py diff --git a/core/job/_job.py b/cbpi/job/_job.py similarity index 100% rename from core/job/_job.py rename to cbpi/job/_job.py diff --git a/core/job/_scheduler.py b/cbpi/job/_scheduler.py similarity index 100% rename from core/job/_scheduler.py rename to cbpi/job/_scheduler.py diff --git a/core/job/aiohttp.py b/cbpi/job/aiohttp.py similarity index 100% rename from core/job/aiohttp.py rename to cbpi/job/aiohttp.py diff --git a/core/mqtt/__init__.py b/cbpi/mqtt/__init__.py similarity index 100% rename from core/mqtt/__init__.py rename to cbpi/mqtt/__init__.py diff --git a/core/mqtt/mqtt.py b/cbpi/mqtt/mqtt.py similarity index 98% rename from core/mqtt/mqtt.py rename to cbpi/mqtt/mqtt.py index f17bc6a..303dc03 100644 --- a/core/mqtt/mqtt.py +++ b/cbpi/mqtt/mqtt.py @@ -1,5 +1,5 @@ from aiojobs.aiohttp import get_scheduler_from_app -from core.mqtt_matcher import MQTTMatcher +from cbpi.mqtt_matcher import MQTTMatcher from hbmqtt.broker import Broker from hbmqtt.client import MQTTClient from hbmqtt.mqtt.constants import QOS_1, QOS_0 diff --git a/core/mqtt/mqtt_matcher.py b/cbpi/mqtt/mqtt_matcher.py similarity index 100% rename from core/mqtt/mqtt_matcher.py rename to cbpi/mqtt/mqtt_matcher.py diff --git a/cbpi/utils/__init__.py b/cbpi/utils/__init__.py new file mode 100644 index 0000000..1bc153a --- /dev/null +++ b/cbpi/utils/__init__.py @@ -0,0 +1 @@ +from cbpi.utils.utils import * diff --git a/core/utils/encoder.py b/cbpi/utils/encoder.py similarity index 90% rename from core/utils/encoder.py rename to cbpi/utils/encoder.py index 49fee31..1c4dfa2 100644 --- a/core/utils/encoder.py +++ b/cbpi/utils/encoder.py @@ -4,7 +4,7 @@ class ComplexEncoder(JSONEncoder): def default(self, obj): - from core.database.orm_framework import DBModel + from cbpi.database.orm_framework import DBModel try: if isinstance(obj, DBModel): diff --git a/core/utils/utils.py b/cbpi/utils/utils.py similarity index 86% rename from core/utils/utils.py rename to cbpi/utils/utils.py index 9d824df..e4c34a4 100644 --- a/core/utils/utils.py +++ b/cbpi/utils/utils.py @@ -1,4 +1,4 @@ -from core.utils.encoder import ComplexEncoder +from cbpi.utils.encoder import ComplexEncoder __all__ = ['load_config',"json_dumps"] diff --git a/core/websocket.py b/cbpi/websocket.py similarity index 95% rename from core/websocket.py rename to cbpi/websocket.py index bccea10..f3e41fe 100644 --- a/core/websocket.py +++ b/cbpi/websocket.py @@ -4,10 +4,10 @@ from collections import defaultdict import aiohttp from aiohttp import web -from cbpi_api import * +from cbpi.api import * from voluptuous import Schema -from utils import json_dumps +from cbpi.utils import json_dumps class CBPiWebSocket: @@ -22,7 +22,7 @@ class CBPiWebSocket: @on_event(topic="#") async def listen(self, topic, **kwargs): data = dict(topic=topic, data=dict(**kwargs)) - self.logger.info("PUSH %s " % data) + self.logger.debug("PUSH %s " % data) self.send(data) def send(self, data): diff --git a/config/plugin_list.txt b/config/plugin_list.txt index c824f34..142c198 100644 --- a/config/plugin_list.txt +++ b/config/plugin_list.txt @@ -1,3 +1 @@ -cbpi-actor -cbpi-actor cbpi-actor \ No newline at end of file diff --git a/core/utils/__init__.py b/core/utils/__init__.py deleted file mode 100644 index 224962f..0000000 --- a/core/utils/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from core.utils.utils import * diff --git a/craftbeerpi.db b/craftbeerpi.db index c153a98e916ac59ad6d8fd85ef36b7ee128026ef..41f81ffa6003427b8db4602098e67da90659b6d6 100644 GIT binary patch delta 270 zcmZozz}&Ead4d#^h|okCCm^{oVF^F80q@_*>;lnje1d%JKxTn}$m9kAmdy?j<90HuKBL>|@k zRgN(WOlE?~3=p|FO=X@m7Zd+72L8+Z%lIoM3pmJb)^_maX8~HLH+h1u2B%@IHWMp@ zs;cJXgT5-9rnTCPaNg#B{?hWi=7#1*hUR(}=BDPxCY#mrFUYeSa;V1u@#MdK&Oo*r YnC;&02xY5H?(dI+s?pf|pHq)$ delta 215 zcmZozz}&Ead4d#^@S=$_PC#;F!V-RFT|Vi_>;ln~3j{