mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 16:38:36 +01:00
requirements fix
This commit is contained in:
parent
26417074de
commit
dcc82d4bd8
8 changed files with 104 additions and 8 deletions
|
@ -18,6 +18,10 @@ class ConfigController():
|
||||||
self.cbpi = cbpi
|
self.cbpi = cbpi
|
||||||
self.cbpi.register(self)
|
self.cbpi.register(self)
|
||||||
|
|
||||||
|
|
||||||
|
def get_state(self):
|
||||||
|
return self.cache
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
this_directory = os.path.dirname(__file__)
|
this_directory = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ class DashboardController(CRUDController):
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.cbpi.register(self)
|
self.cbpi.register(self)
|
||||||
|
|
||||||
|
def get_state(self):
|
||||||
|
return dict(items=self.cache)
|
||||||
|
|
||||||
async def get_content(self, dashboard_id):
|
async def get_content(self, dashboard_id):
|
||||||
return await DashboardContentModel.get_by_dashboard_id(dashboard_id)
|
return await DashboardContentModel.get_by_dashboard_id(dashboard_id)
|
||||||
|
|
||||||
|
|
|
@ -108,13 +108,14 @@ class PluginController():
|
||||||
'''
|
'''
|
||||||
logger.info("Register %s Class %s" % (name, clazz.__name__))
|
logger.info("Register %s Class %s" % (name, clazz.__name__))
|
||||||
if issubclass(clazz, CBPiActor):
|
if issubclass(clazz, CBPiActor):
|
||||||
self.cbpi.actor.types[name] = {"class": clazz, "config": self._parse_props(clazz)}
|
#self.cbpi.actor.types[name] = {"class": clazz, "config": self._parse_props(clazz)}
|
||||||
|
self.cbpi.actor.types[name] = self._parse_props(clazz)
|
||||||
|
|
||||||
if issubclass(clazz, CBPiSensor):
|
if issubclass(clazz, CBPiSensor):
|
||||||
self.cbpi.sensor.types[name] = {"class": clazz, "config": self._parse_props(clazz)}
|
self.cbpi.sensor.types[name] = self._parse_props(clazz)
|
||||||
|
|
||||||
if issubclass(clazz, CBPiKettleLogic):
|
if issubclass(clazz, CBPiKettleLogic):
|
||||||
self.cbpi.kettle.types[name] = {"class": clazz, "config": self._parse_props(clazz)}
|
self.cbpi.kettle.types[name] = self._parse_props(clazz)
|
||||||
|
|
||||||
if issubclass(clazz, CBPiSimpleStep):
|
if issubclass(clazz, CBPiSimpleStep):
|
||||||
self.cbpi.step.types[name] = self._parse_props(clazz)
|
self.cbpi.step.types[name] = self._parse_props(clazz)
|
||||||
|
|
|
@ -14,14 +14,17 @@ class SystemController():
|
||||||
self.service = cbpi.actor
|
self.service = cbpi.actor
|
||||||
self.cbpi.register(self, "/system")
|
self.cbpi.register(self, "/system")
|
||||||
|
|
||||||
@request_mapping("/state", method="GET", auth_required=False)
|
@request_mapping("/", method="GET", auth_required=False)
|
||||||
def state(self, request):
|
def state(self, request):
|
||||||
# TODO implement restart
|
# TODO implement restart
|
||||||
return web.json_response(data=dict(
|
return web.json_response(data=dict(
|
||||||
actor=self.cbpi.actor.get_state(),
|
actor=self.cbpi.actor.get_state(),
|
||||||
sensor=self.cbpi.sensor.get_state(),
|
sensor=self.cbpi.sensor.get_state(),
|
||||||
kettle=self.cbpi.kettle.get_state(),
|
kettle=self.cbpi.kettle.get_state(),
|
||||||
step=self.cbpi.step.get_state())
|
step=self.cbpi.step.get_state(),
|
||||||
|
dashboard=self.cbpi.dashboard.get_state(),
|
||||||
|
translations=self.cbpi.translation.get_all(),
|
||||||
|
config=self.cbpi.config.get_state())
|
||||||
, dumps=json_dumps)
|
, dumps=json_dumps)
|
||||||
|
|
||||||
@request_mapping("/restart", method="POST", name="RestartServer", auth_required=False)
|
@request_mapping("/restart", method="POST", name="RestartServer", auth_required=False)
|
||||||
|
@ -48,3 +51,4 @@ class SystemController():
|
||||||
@request_mapping("/events", method="GET", name="get_all_events", auth_required=False)
|
@request_mapping("/events", method="GET", name="get_all_events", auth_required=False)
|
||||||
def get_all_events(self, request):
|
def get_all_events(self, request):
|
||||||
return web.json_response(data=self.cbpi.bus.dump())
|
return web.json_response(data=self.cbpi.bus.dump())
|
||||||
|
|
||||||
|
|
29
cbpi/controller/translation_controller.py
Normal file
29
cbpi/controller/translation_controller.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from database.model import TranslationModel
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationController(object):
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, cbpi):
|
||||||
|
self.cbpi = cbpi
|
||||||
|
self._cache = {}
|
||||||
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
async def init(self):
|
||||||
|
self._cache = await TranslationModel.get_all()
|
||||||
|
print(self._cache)
|
||||||
|
|
||||||
|
|
||||||
|
def get_all(self):
|
||||||
|
return self._cache
|
||||||
|
|
||||||
|
async def add_key(self, locale, key):
|
||||||
|
|
||||||
|
try:
|
||||||
|
if locale not in self._cache or key not in self._cache[locale]:
|
||||||
|
await TranslationModel.add_key(locale, key)
|
||||||
|
self._cache = await TranslationModel.get_all()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error("Error during adding translation key %s - %s - %s" % (key, locale, str(e)))
|
|
@ -30,7 +30,8 @@ from cbpi.http_endpoints.http_dashboard import DashBoardHttpEndpoints
|
||||||
from cbpi.http_endpoints.http_kettle import KettleHttpEndpoints
|
from cbpi.http_endpoints.http_kettle import KettleHttpEndpoints
|
||||||
from cbpi.http_endpoints.http_sensor import SensorHttpEndpoints
|
from cbpi.http_endpoints.http_sensor import SensorHttpEndpoints
|
||||||
from cbpi.http_endpoints.http_step import StepHttpEndpoints
|
from cbpi.http_endpoints.http_step import StepHttpEndpoints
|
||||||
|
from controller.translation_controller import TranslationController
|
||||||
|
from http_endpoints.http_translation import TranslationHttpEndpoint
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -73,6 +74,7 @@ class CraftBeerPi():
|
||||||
self.bus = CBPiEventBus(self.app.loop, self)
|
self.bus = CBPiEventBus(self.app.loop, self)
|
||||||
self.ws = CBPiWebSocket(self)
|
self.ws = CBPiWebSocket(self)
|
||||||
self.job = JobController(self)
|
self.job = JobController(self)
|
||||||
|
self.translation = TranslationController(self)
|
||||||
self.actor = ActorController(self)
|
self.actor = ActorController(self)
|
||||||
self.sensor = SensorController(self)
|
self.sensor = SensorController(self)
|
||||||
self.plugin = PluginController(self)
|
self.plugin = PluginController(self)
|
||||||
|
@ -88,6 +90,7 @@ class CraftBeerPi():
|
||||||
self.http_actor = ActorHttpEndpoints(self)
|
self.http_actor = ActorHttpEndpoints(self)
|
||||||
self.http_kettle = KettleHttpEndpoints(self)
|
self.http_kettle = KettleHttpEndpoints(self)
|
||||||
self.http_dashboard = DashBoardHttpEndpoints(self)
|
self.http_dashboard = DashBoardHttpEndpoints(self)
|
||||||
|
self.http_translation = TranslationHttpEndpoint(self)
|
||||||
|
|
||||||
self.notification = NotificationController(self)
|
self.notification = NotificationController(self)
|
||||||
self.login = Login(self)
|
self.login = Login(self)
|
||||||
|
@ -221,7 +224,7 @@ class CraftBeerPi():
|
||||||
await self.job.init()
|
await self.job.init()
|
||||||
await DBModel.setup()
|
await DBModel.setup()
|
||||||
await self.config.init()
|
await self.config.init()
|
||||||
|
await self.translation.init()
|
||||||
self._setup_http_index()
|
self._setup_http_index()
|
||||||
self.plugin.load_plugins()
|
self.plugin.load_plugins()
|
||||||
self.plugin.load_plugins_from_evn()
|
self.plugin.load_plugins_from_evn()
|
||||||
|
|
|
@ -130,3 +130,35 @@ class DashboardContentModel(DBModel):
|
||||||
async with aiosqlite.connect(DATABASE_FILE) as db:
|
async with aiosqlite.connect(DATABASE_FILE) as db:
|
||||||
await db.execute("DELETE FROM %s WHERE dbid = ?" % (cls.__table_name__), (id,))
|
await db.execute("DELETE FROM %s WHERE dbid = ?" % (cls.__table_name__), (id,))
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationModel(DBModel):
|
||||||
|
__fields__ = ["key", "text", "language_code"]
|
||||||
|
__table_name__ = "translation"
|
||||||
|
__json_fields__ = []
|
||||||
|
__priamry_key__ = "key"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_all(cls):
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
async with aiosqlite.connect(DATABASE_FILE) as db:
|
||||||
|
sql = "SELECT * FROM %s" % cls.__table_name__
|
||||||
|
db.row_factory = DBModel.dict_factory
|
||||||
|
async with db.execute(sql) as cursor:
|
||||||
|
async for row in cursor:
|
||||||
|
code = row.get("language_code")
|
||||||
|
key = row.get("key")
|
||||||
|
text = row.get("text")
|
||||||
|
if code not in result:
|
||||||
|
result[code] = {}
|
||||||
|
result[code][key] = text
|
||||||
|
await cursor.close()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def add_key(cls, locale, key):
|
||||||
|
async with aiosqlite.connect(DATABASE_FILE) as db:
|
||||||
|
await db.execute("INSERT INTO %s (language_code, key, text) VALUES (?,?, ' ')" % (cls.__table_name__), (locale, key))
|
||||||
|
await db.commit()
|
||||||
|
|
20
cbpi/http_endpoints/http_translation.py
Normal file
20
cbpi/http_endpoints/http_translation.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from aiohttp import web
|
||||||
|
from aiohttp_auth import auth
|
||||||
|
|
||||||
|
from cbpi.api import *
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationHttpEndpoint():
|
||||||
|
|
||||||
|
def __init__(self,cbpi):
|
||||||
|
self.cbpi = cbpi
|
||||||
|
self.cbpi.register(self, url_prefix="/translation")
|
||||||
|
|
||||||
|
|
||||||
|
@request_mapping(path="/missing_key", method="POST", auth_required=False)
|
||||||
|
async def missing_key(self, request):
|
||||||
|
data = await request.json()
|
||||||
|
await self.cbpi.translation.add_key(**data)
|
||||||
|
return web.Response(status=204)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue