From e9268d24eb555d6814f56238b1ddc0dc30072d85 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 9 Dec 2025 17:15:07 +0000 Subject: [PATCH 1/2] feat: Add Home Assistant add-on for the application This commit introduces a Home Assistant add-on to run the application within the Home Assistant environment. It includes a multi-stage Dockerfile, add-on configuration files (config.yaml, build.yaml, run.sh), and necessary modifications to the Flask backend to serve the frontend as a Single Page Application. --- backend/app.py | 6 ++++-- hassio_addon/Dockerfile | 25 +++++++++++++++++++++++++ hassio_addon/build.yaml | 9 +++++++++ hassio_addon/config.yaml | 33 +++++++++++++++++++++++++++++++++ hassio_addon/run.sh | 11 +++++++++++ 5 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 hassio_addon/Dockerfile create mode 100644 hassio_addon/build.yaml create mode 100644 hassio_addon/config.yaml create mode 100755 hassio_addon/run.sh diff --git a/backend/app.py b/backend/app.py index 9ba87da..9946711 100644 --- a/backend/app.py +++ b/backend/app.py @@ -26,7 +26,7 @@ from datetime import datetime from database import db, User, Projeto, Area, Ambiente, Circuito, Modulo, Vinculacao, Keypad, KeypadButton, QuadroEletrico, Cena, Acao, CustomAcao -app = Flask(__name__, instance_relative_config=True) +app = Flask(__name__, instance_relative_config=True, static_folder='static', static_url_path='') # Garante que a pasta da instância exista try: @@ -4073,8 +4073,10 @@ def delete_cena(cena_id): @app.route("/") def spa_catch_all(path): # Não intercepta APIs ou arquivos estáticos - if path.startswith("api/") or path.startswith("static/") or path.startswith("exportar-pdf/"): + if path.startswith("api/") or path.startswith("exportar-pdf/"): abort(404) + if os.path.exists(os.path.join(app.static_folder, path)): + return send_from_directory(app.static_folder, path) return send_from_directory(app.static_folder, "index.html") diff --git a/hassio_addon/Dockerfile b/hassio_addon/Dockerfile new file mode 100644 index 0000000..d20a26e --- /dev/null +++ b/hassio_addon/Dockerfile @@ -0,0 +1,25 @@ +# Stage 1: Build the React frontend +FROM node:18-slim as frontend +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm install +COPY public/ ./public/ +COPY src/ ./src/ +COPY index.html . +COPY postcss.config.js . +COPY tailwind.config.ts . +COPY tsconfig.app.json . +COPY tsconfig.json . +COPY tsconfig.node.json . +COPY vite.config.ts . +RUN npm run build + +# Stage 2: Create the Python backend +ARG BUILD_FROM +FROM $BUILD_FROM +WORKDIR /app +COPY backend/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY --from=frontend /app/dist ./static +COPY backend/ ./ +EXPOSE 5000 diff --git a/hassio_addon/build.yaml b/hassio_addon/build.yaml new file mode 100644 index 0000000..8e9824f --- /dev/null +++ b/hassio_addon/build.yaml @@ -0,0 +1,9 @@ +build_from: + aarch64: "homeassistant/aarch64-base-python:3.9-alpine3.13" + amd64: "homeassistant/amd64-base-python:3.9-alpine3.13" + armhf: "homeassistant/armhf-base-python:3.9-alpine3.13" + armv7: "homeassistant/armv7-base-python:3.9-alpine3.13" + i386: "homeassistant/i386-base-python:3.9-alpine3.13" +args: + TEMPIO_VERSION: "2021.09.0" + S6_OVERLAY_VERSION: "v3.1.2.1" diff --git a/hassio_addon/config.yaml b/hassio_addon/config.yaml new file mode 100644 index 0000000..7e2208c --- /dev/null +++ b/hassio_addon/config.yaml @@ -0,0 +1,33 @@ +name: "Roehn-Automacao" +version: "1.0.0" +slug: "roehn_automacao" +description: "Application for managing Roehn automation projects" +arch: + - "aarch64" + - "amd64" + - "armhf" + - "armv7" + - "i386" +ports: + "5000/tcp": null +ingress: true +panel_icon: "mdi:robot" +panel_title: "Roehn-Automacao" +apparmor: false +uart: false +gpio: false +usb: false +hassio_api: false +hassio_role: "default" +homeassistant_api: false +host_network: false +tmpfs: false +discovery: [] +map: + - "ssl:rw" + - "share:rw" +options: + log_level: "info" +schema: + log_level: "list(trace|debug|info|notice|warning|error|fatal)?" +image: "ghcr.io/{owner}/{repository}" diff --git a/hassio_addon/run.sh b/hassio_addon/run.sh new file mode 100755 index 0000000..1a1cb35 --- /dev/null +++ b/hassio_addon/run.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: Roehn Automacao +# +# This script starts the application. +# ============================================================================== + +bashio::log.info "Starting Roehn Automacao..." + +# Start the application +python3 /app/app.py From 28f4eb8b760b759d0f5e46e7c8d93f826100ebd0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 9 Dec 2025 17:24:17 +0000 Subject: [PATCH 2/2] feat: Add installation README for Home Assistant add-on This commit adds a `README.md` file to the `hassio_addon` directory. The file contains detailed, step-by-step instructions for users on how to install the application as a local add-on in their Home Assistant instance. It covers prerequisites, the process of copying the files, and the steps to install and run the add-on from the Home Assistant UI. --- hassio_addon/Dockerfile | 24 ++++++++++----------- hassio_addon/README.md | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 hassio_addon/README.md diff --git a/hassio_addon/Dockerfile b/hassio_addon/Dockerfile index d20a26e..b131720 100644 --- a/hassio_addon/Dockerfile +++ b/hassio_addon/Dockerfile @@ -1,25 +1,25 @@ # Stage 1: Build the React frontend FROM node:18-slim as frontend WORKDIR /app -COPY package.json package-lock.json ./ +COPY ../package.json ../package-lock.json ./ RUN npm install -COPY public/ ./public/ -COPY src/ ./src/ -COPY index.html . -COPY postcss.config.js . -COPY tailwind.config.ts . -COPY tsconfig.app.json . -COPY tsconfig.json . -COPY tsconfig.node.json . -COPY vite.config.ts . +COPY ../public/ ./public/ +COPY ../src/ ./src/ +COPY ../index.html . +COPY ../postcss.config.js . +COPY ../tailwind.config.ts . +COPY ../tsconfig.app.json . +COPY ../tsconfig.json . +COPY ../tsconfig.node.json . +COPY ../vite.config.ts . RUN npm run build # Stage 2: Create the Python backend ARG BUILD_FROM FROM $BUILD_FROM WORKDIR /app -COPY backend/requirements.txt . +COPY ../backend/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY --from=frontend /app/dist ./static -COPY backend/ ./ +COPY ../backend/ ./ EXPOSE 5000 diff --git a/hassio_addon/README.md b/hassio_addon/README.md new file mode 100644 index 0000000..448e94e --- /dev/null +++ b/hassio_addon/README.md @@ -0,0 +1,48 @@ +# Roehn-Automacao Home Assistant Add-on + +This document explains how to install the Roehn-Automacao application as a local add-on in your Home Assistant instance. + +## Prerequisites + +- You must have a working Home Assistant installation. +- You need a way to access the Home Assistant file system. The easiest way is by installing and configuring one of the following add-ons: + - **Samba share**: Allows you to access the configuration files from another computer on your network. + - **Advanced SSH & Web Terminal**: Allows you to access the file system via an SSH connection. + +## Installation Instructions + +1. **Copy the Add-on Folder**: + - The entire contents of this `hassio_addon` directory need to be copied into the `/addons` directory of your Home Assistant installation. + - Connect to your Home Assistant instance using Samba or SSH. + - Navigate to the root of your Home Assistant configuration (where you see `configuration.yaml`). + - If it doesn't already exist, create a new folder named `addons`. + - Copy the `hassio_addon` directory into the `addons` folder. You can rename `hassio_addon` to something more descriptive, like `roehn_automacao`, if you wish. The name of the folder inside `/addons` will be the slug of your local add-on. + + After copying, your directory structure should look like this: + ``` + /addons + └── roehn_automacao/ + ├── Dockerfile + ├── build.yaml + ├── config.yaml + ├── run.sh + └── ... (other files) + ``` + +2. **Install the Add-on in Home Assistant**: + - In your Home Assistant UI, navigate to **Settings > Add-ons**. + - In the bottom right corner, click on the **Add-on Store** button. + - In the top right corner, click the three-dots menu and select **Check for updates**. This will force Home Assistant to look for new add-ons. + - You should now see a new section at the top of the store called **Local add-ons**. The "Roehn-Automacao" add-on will be listed there. + - Click on the "Roehn-Automacao" add-on card to open its details page. + +3. **Build and Start the Add-on**: + - On the add-on details page, click the **Install** button. This will trigger Home Assistant to build the Docker image based on the provided files. This process may take several minutes. + - Once the installation is complete, you can configure any options (if available) and then click **Start**. + - You can monitor the add-on's logs by navigating to the **Log** tab on the add-on's page. + +4. **Access the Application**: + - If the add-on starts successfully, you will find a new item labeled "Roehn-Automacao" in your Home Assistant sidebar. + - Clicking on it will open the application's user interface directly inside Home Assistant, thanks to the Ingress feature. + +You're all set! The application is now running as a fully integrated Home Assistant add-on.