From 80cefc8082e7db6a12b3a59079c413be858813c1 Mon Sep 17 00:00:00 2001 From: Stefan Allius <122395479+s-allius@users.noreply.github.com> Date: Wed, 16 Apr 2025 01:49:53 +0200 Subject: [PATCH] S allius/issue378 (#382) * move home route into web diretory * add web UI to add-on * update changelog * use Blueprints --- CHANGELOG.md | 1 + app/src/server.py | 7 ++----- app/src/web/routes.py | 9 +++++++++ app/tests/test_server.py | 10 ---------- app/tests/test_web_route.py | 15 +++++++++++++++ ha_addons/Makefile | 3 ++- ha_addons/ha_addon/translations/de.yaml | 1 + ha_addons/ha_addon/translations/en.yaml | 1 + ha_addons/templates/config.jinja | 5 ++++- 9 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 app/src/web/routes.py create mode 100644 app/tests/test_web_route.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 64a7c8a..01bf55c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +- add web UI to add-on - allow `Y00` serial numbers for GEN3PLUS devices ## [0.13.0] - 2025-04-13 diff --git a/app/src/server.py b/app/src/server.py index 9cf5f6b..3202fd5 100644 --- a/app/src/server.py +++ b/app/src/server.py @@ -15,6 +15,7 @@ from cnf.config import Config from cnf.config_read_env import ConfigReadEnv from cnf.config_read_toml import ConfigReadToml from cnf.config_read_json import ConfigReadJson +from web.routes import web_routes from modbus_tcp import ModbusTcp @@ -31,11 +32,7 @@ class ProxyState: app = Quart(__name__) - - -@app.route('/') -async def hello(): - return Response(response="Hello, world") +app.register_blueprint(web_routes) @app.route('/-/ready') diff --git a/app/src/web/routes.py b/app/src/web/routes.py new file mode 100644 index 0000000..8ddcc36 --- /dev/null +++ b/app/src/web/routes.py @@ -0,0 +1,9 @@ +from quart import Blueprint +from quart import Response + +web_routes = Blueprint('web_routes', __name__) + + +@web_routes.route('/') +async def hello(): + return Response(response="Hello, world") diff --git a/app/tests/test_server.py b/app/tests/test_server.py index 0db3324..1fdae63 100644 --- a/app/tests/test_server.py +++ b/app/tests/test_server.py @@ -33,16 +33,6 @@ def test_get_log_level(): log_lvl = get_log_level() assert log_lvl == None - -@pytest.mark.asyncio -async def test_home(): - """Test the home route.""" - client = app.test_client() - response = await client.get('/') - assert response.status_code == 200 - result = await response.get_data() - assert result == b"Hello, world" - @pytest.mark.asyncio async def test_ready(): """Test the ready route.""" diff --git a/app/tests/test_web_route.py b/app/tests/test_web_route.py new file mode 100644 index 0000000..cffc3f9 --- /dev/null +++ b/app/tests/test_web_route.py @@ -0,0 +1,15 @@ +# test_with_pytest.py +import pytest +from server import app + +pytest_plugins = ('pytest_asyncio',) + + +@pytest.mark.asyncio +async def test_home(): + """Test the home route.""" + client = app.test_client() + response = await client.get('/') + assert response.status_code == 200 + result = await response.get_data() + assert result == b"Hello, world" diff --git a/ha_addons/Makefile b/ha_addons/Makefile index 9f2fbc2..e23d471 100644 --- a/ha_addons/Makefile +++ b/ha_addons/Makefile @@ -83,7 +83,8 @@ SRC_FILES := $(wildcard $(SRC_PROXY)/*.py)\ $(wildcard $(SRC_PROXY)/cnf/*.py)\ $(wildcard $(SRC_PROXY)/cnf/*.toml)\ $(wildcard $(SRC_PROXY)/gen3/*.py)\ - $(wildcard $(SRC_PROXY)/gen3plus/*.py) + $(wildcard $(SRC_PROXY)/gen3plus/*.py)\ + $(wildcard $(SRC_PROXY)/web/*.py) CNF_FILES := $(wildcard $(CNF_PROXY)/*.toml) # determine destination files diff --git a/ha_addons/ha_addon/translations/de.yaml b/ha_addons/ha_addon/translations/de.yaml index b4c4938..ad9e014 100755 --- a/ha_addons/ha_addon/translations/de.yaml +++ b/ha_addons/ha_addon/translations/de.yaml @@ -106,3 +106,4 @@ configuration: network: 5005/tcp: listening Port für TSUN GEN3 Wechselrichter 10000/tcp: listening Port für TSUN GEN3PLUS Wechselrichter + 8127/tcp: Port für das TSUN-Proxy Dashboard diff --git a/ha_addons/ha_addon/translations/en.yaml b/ha_addons/ha_addon/translations/en.yaml index 2187347..b4407f8 100755 --- a/ha_addons/ha_addon/translations/en.yaml +++ b/ha_addons/ha_addon/translations/en.yaml @@ -107,3 +107,4 @@ configuration: network: 5005/tcp: listening Port for TSUN GEN3 Devices 10000/tcp: listening Port for TSUN GEN3PLUS Devices + 8127/tcp: Port for the TSUN-Proxy Dashboard \ No newline at end of file diff --git a/ha_addons/templates/config.jinja b/ha_addons/templates/config.jinja index 8488f79..a381594 100755 --- a/ha_addons/templates/config.jinja +++ b/ha_addons/templates/config.jinja @@ -23,8 +23,11 @@ services: ports: 5005/tcp: 5005 10000/tcp: 10000 - + 8127/tcp: 8127 +webui: "http://[HOST]:[PORT:8127]/" watchdog: "http://[HOST]:[PORT:8127]/-/healthy" +ingress: true +ingress_port: 8127 # Definition of parameters in the configuration tab of the addon # parameters are available within the container as /data/options.json