summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/web_kbn.py58
-rw-r--r--include/py/homekit/config/config.py2
-rw-r--r--include/py/homekit/util.py9
-rw-r--r--requirements.txt5
-rw-r--r--web/kbn_templates/base.html23
5 files changed, 93 insertions, 4 deletions
diff --git a/bin/web_kbn.py b/bin/web_kbn.py
new file mode 100644
index 0000000..b66e2a5
--- /dev/null
+++ b/bin/web_kbn.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+import asyncio
+import jinja2
+import aiohttp_jinja2
+import os
+import __py_include
+
+from typing import Optional
+from homekit.config import config, AppConfigUnit
+from homekit.util import homekit_path
+from aiohttp import web
+from homekit import http
+
+
+class WebKbnConfig(AppConfigUnit):
+ NAME = 'web_kbn'
+
+ @classmethod
+ def schema(cls) -> Optional[dict]:
+ return {
+ 'listen_addr': cls._addr_schema(required=True)
+ }
+
+
+class WebSite(http.HTTPServer):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ aiohttp_jinja2.setup(
+ self.app,
+ loader=jinja2.FileSystemLoader(homekit_path('web', 'kbn_templates'))
+ )
+
+ self.get('/', self.get_index)
+
+ @staticmethod
+ async def get_index(req: http.Request):
+ # context = {
+ # 'username': request.match_info.get("username", ""),
+ # 'current_date': 'January 27, 2017'
+ # }
+ # response = aiohttp_jinja2.render_template("example.html", request,
+ # context=context)
+ # return response
+
+ message = "nothing here, keep lurking"
+ return http.Response(text=message, content_type='text/plain')
+
+
+if __name__ == '__main__':
+ config.load_app(WebKbnConfig)
+
+ loop = asyncio.get_event_loop()
+ # print(config.app_config)
+
+ print(config.app_config['listen_addr'].host)
+ server = WebSite(config.app_config['listen_addr'])
+ server.run()
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py
index 773de1e..7d30a77 100644
--- a/include/py/homekit/config/config.py
+++ b/include/py/homekit/config/config.py
@@ -277,9 +277,7 @@ class Config:
and not isinstance(name, bool) \
and issubclass(name, AppConfigUnit) or name == AppConfigUnit:
self.app_name = name.NAME
- print(self.app_config)
self.app_config = name()
- print(self.app_config)
app_config = self.app_config
else:
self.app_name = name if isinstance(name, str) else None
diff --git a/include/py/homekit/util.py b/include/py/homekit/util.py
index 22bba86..2680c37 100644
--- a/include/py/homekit/util.py
+++ b/include/py/homekit/util.py
@@ -9,6 +9,7 @@ import logging
import string
import random
import re
+import os
from enum import Enum
from datetime import datetime
@@ -252,4 +253,10 @@ def next_tick_gen(freq):
t = time.time()
while True:
t += freq
- yield max(t - time.time(), 0) \ No newline at end of file
+ yield max(t - time.time(), 0)
+
+
+def homekit_path(*args) -> str:
+ return os.path.realpath(
+ os.path.join(os.path.dirname(__file__), '..', '..', '..', *args)
+ )
diff --git a/requirements.txt b/requirements.txt
index 521ae41..66e8379 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -17,4 +17,7 @@ cerberus~=1.3.4
# following can be installed from debian repositories
# matplotlib~=3.5.0
-Pillow==9.5.0 \ No newline at end of file
+Pillow==9.5.0
+
+jinja2~=3.1.2
+aiohttp-jinja2~=1.5.1 \ No newline at end of file
diff --git a/web/kbn_templates/base.html b/web/kbn_templates/base.html
new file mode 100644
index 0000000..e567a90
--- /dev/null
+++ b/web/kbn_templates/base.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+<head>
+ <title>{{ title }}</title>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
+ <script>
+ window.onerror = function(error) {
+ window.console && console.error(error);
+ }
+ </script>
+ {{ head_static }}
+</head>
+<body>
+<div class="container py-3">
+
+{% if js %}
+<script>{{ js|raw }}</script>
+{% endif %}
+
+</div>
+</body>
+</html>