ratatouille/ihm.py
2025-06-24 01:41:50 +02:00

44 lines
881 B
Python

from flask import Flask, request
from flask import render_template
import logging
import config
from src.hass import Hass
logging.basicConfig(
level=10,
format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s"
)
walle = Hass(config.hass_url, config.hass_token)
app = Flask(__name__)
@app.route("/")
def home():
return render_template('home.html')
@app.route("/light_on")
def light_on():
try:
room = request.args.get('room')
logging.info(f"light_on {room}")
walle.light_on(room)
return "ok"
except Exception as e:
logging.error(e)
return "error", 400
@app.route("/light_off")
def light_off():
try:
room = request.args.get('room')
logging.info(f"light_off {room}")
walle.light_off(room)
return "ok"
except Exception as e:
return "error", 400