feat: v 1.4.0 Полный функционал для работы с вятяжкой

* Добавил полный функционал управления elica через esp32 по MQTT
    * Добавил в прошивку принудительную блокировку внешнего винтелятора при работающей вытяжке
    * Добавил веб-панели для управления вытяжкой
This commit is contained in:
2026-09-27 00:00:26 +03:00
parent e55d7a818e
commit 774d16f10a
16 changed files with 2014 additions and 11 deletions
+124 -7
View File
@@ -10,12 +10,15 @@ from fastapi.staticfiles import StaticFiles
from pathlib import Path as FilePath
from app.qingping.service import QingpingService
from app.metrics import PrometheusMetricsService
from app.elica import ElicaConfig, ElicaController, ElicaService
from app.my_dataclasses import (
TION_MAC,
QINGPING_MAC,
QINGPING_MQTT_HOST,
QINGPING_MQTT_PORT,
ELICA_MQTT_HOST,
ELICA_MQTT_PORT,
MIN_FAN_SPEED,
MAX_FAN_SPEED,
MIN_TARGET_TEMP,
@@ -87,6 +90,14 @@ qingping_service = QingpingService(
mac=QINGPING_MAC,
)
elica_service = ElicaService(
ElicaConfig(
mqtt_host=ELICA_MQTT_HOST,
mqtt_port=ELICA_MQTT_PORT,
)
)
elica_controller = ElicaController(elica_service)
schedule_service: ScheduleService | None = None
schedule_load_error: str | None = None
@@ -109,6 +120,7 @@ async def lifespan(app: FastAPI):
await service.start()
await qingping_service.start()
await elica_service.start()
try:
try:
@@ -200,6 +212,7 @@ async def lifespan(app: FastAPI):
if schedule_service is not None:
await schedule_service.stop()
await elica_service.stop()
await qingping_service.stop()
await service.stop()
@@ -225,22 +238,55 @@ app.mount(
@app.get("/", include_in_schema=False)
async def root():
return RedirectResponse(url="/ui/panel")
return RedirectResponse(url="/ui/tion")
@app.get("/ui", include_in_schema=False)
async def ui_root():
return RedirectResponse(url="/ui/panel")
return RedirectResponse(url="/ui/tion")
# Canonical UI routes. Device-specific names make room for additional
# controllers/widgets without overloading generic "panel"/"widget" names.
@app.get("/ui/tion", include_in_schema=False)
async def ui_tion():
return FileResponse(WEB_ROOT / "tion.html")
@app.get("/ui/tion-widget", include_in_schema=False)
async def ui_tion_widget():
return FileResponse(WEB_ROOT / "tion-widget.html")
@app.get("/ui/elica", include_in_schema=False)
async def ui_elica():
return FileResponse(WEB_ROOT / "elica.html")
@app.get("/ui/elica-widget", include_in_schema=False)
async def ui_elica_widget():
return FileResponse(WEB_ROOT / "elica-widget.html")
# Backward-compatible aliases for existing bookmarks/Homarr embeds.
@app.get("/ui/panel", include_in_schema=False)
async def ui_panel_legacy():
return RedirectResponse(url="/ui/tion")
@app.get("/ui/widget", include_in_schema=False)
async def ui_widget():
return FileResponse(WEB_ROOT / "widget.html")
async def ui_widget_legacy():
return RedirectResponse(url="/ui/tion-widget")
@app.get("/ui/panel", include_in_schema=False)
async def ui_panel():
return FileResponse(WEB_ROOT / "panel.html")
@app.get("/ui/exhaust", include_in_schema=False)
async def ui_exhaust_legacy():
return RedirectResponse(url="/ui/elica")
@app.get("/ui/exhaust-widget", include_in_schema=False)
async def ui_exhaust_widget_legacy():
return RedirectResponse(url="/ui/elica-widget")
@app.exception_handler(RequestValidationError)
@@ -291,9 +337,31 @@ def get_status() -> dict:
"qingping": qingping_service.status(),
"elica": get_elica_status(),
"schedule": get_schedule_status(),
}
def get_elica_status() -> dict:
"""Текущее состояние ESP32, вытяжки Elica и внешнего вентилятора."""
return elica_service.status()
async def execute_elica_command(operation):
try:
await operation()
except Exception as exc:
raise HTTPException(
status_code=503,
detail={
"message": "Elica unavailable",
"error": f"{type(exc).__name__}: {exc}",
},
) from exc
return get_elica_status()
def get_effective_speed() -> int:
if (
@@ -531,6 +599,55 @@ async def status():
return get_status()
# ----------------------------------------------------------------------
# Elica / exhaust
# ----------------------------------------------------------------------
@app.get("/api/elica/status")
async def elica_status():
return get_elica_status()
@app.post("/api/elica/power/{state}")
async def set_elica_power(state: Literal["on", "off"]):
operation = (
elica_controller.power_on
if state == "on"
else elica_controller.power_off
)
return await execute_elica_command(operation)
@app.post("/api/elica/speed/{speed}")
async def set_elica_speed(
speed: Annotated[int, Path(ge=1, le=4)],
):
return await execute_elica_command(
lambda: elica_controller.set_speed(speed)
)
@app.post("/api/elica/timer/{state}")
async def set_elica_timer(state: Literal["on", "off"]):
enabled = state == "on"
return await execute_elica_command(
lambda: elica_controller.set_timer(enabled)
)
@app.post("/api/elica/light/toggle")
async def toggle_elica_light():
return await execute_elica_command(elica_controller.toggle_light)
@app.post("/api/elica/external-fan/{state}")
async def set_external_fan(state: Literal["on", "off"]):
enabled = state == "on"
return await execute_elica_command(
lambda: elica_controller.set_external_fan(enabled)
)
# ----------------------------------------------------------------------
# Power
# ----------------------------------------------------------------------