From ab261bd4de55c7ac8a8c085882d0812e1d3e7d27 Mon Sep 17 00:00:00 2001 From: Hebezo Date: Thu, 5 Mar 2026 15:06:18 +0100 Subject: [PATCH] refactor: update QR scanner instructions and improve config flow for local handling --- README.md | 7 +++---- README_DE.md | 7 +++---- custom_components/siedle/config_flow.py | 19 +++---------------- custom_components/siedle/const.py | 3 --- custom_components/siedle/fcm_handler.py | 1 - 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4c4ccc7..47bf238 100644 --- a/README.md +++ b/README.md @@ -77,10 +77,9 @@ Or manually in HACS: 1. In HA, go to **Settings → Devices & Services → Add Integration** 2. Search for **"Siedle"** -3. You'll be redirected to a QR scanner page: - - **HTTPS setup** (e.g., Nabu Casa, Reverse Proxy): The QR scanner page is served directly by your Home Assistant instance. The phone camera can scan the QR code directly. - - **HTTP setup** (local network without HTTPS): Since the browser camera requires a secure context (HTTPS), you will be redirected to an external scanner page hosted at `stefan-altheimer.de`. The scanned data is sent back to your local HA instance via the callback URL. - - **Manual input**: If the camera doesn't work (e.g., desktop browser, no camera permission), the scanner page offers a manual input field. Simply scan the QR code with any QR scanner app on your phone, copy the text content and paste it into the field. +3. You'll be redirected to a QR scanner page served directly by your Home Assistant instance: + - **With camera** (HTTPS required): If your HA is accessible via HTTPS (e.g., Nabu Casa, Reverse Proxy), the phone camera can scan the QR code directly in the browser. + - **Manual input**: If the camera doesn't work (e.g., HTTP-only setup, desktop browser, no camera permission), the scanner page offers a manual input field. Simply scan the QR code with any QR scanner app on your phone, copy the text content and paste it into the field. 4. Scan the QR code from the Siedle app (with the second device or webcam) 5. The data will be automatically transmitted to HA diff --git a/README_DE.md b/README_DE.md index 03425aa..ec5e970 100644 --- a/README_DE.md +++ b/README_DE.md @@ -77,10 +77,9 @@ Oder manuell in HACS: 1. Gehe in HA zu **Einstellungen → Geräte & Dienste → Integration hinzufügen** 2. Suche nach **"Siedle"** -3. Du wirst zu einer QR-Scanner-Seite weitergeleitet: - - **HTTPS-Setup** (z.B. Nabu Casa, Reverse Proxy): Die QR-Scanner-Seite wird direkt von deiner Home Assistant-Instanz ausgeliefert. Die Handy-Kamera kann den QR-Code direkt scannen. - - **HTTP-Setup** (lokales Netzwerk ohne HTTPS): Da die Browser-Kamera einen sicheren Kontext (HTTPS) benötigt, wirst du auf eine extern gehostete Scanner-Seite unter `stefan-altheimer.de` weitergeleitet. Die gescannten Daten werden über die Callback-URL an deine lokale HA-Instanz zurückgesendet. - - **Manuelle Eingabe**: Falls die Kamera nicht funktioniert (z.B. Desktop-Browser, keine Kamera-Berechtigung), bietet die Scanner-Seite ein manuelles Eingabefeld. Scanne den QR-Code einfach mit einer beliebigen QR-Scanner-App auf deinem Handy, kopiere den Textinhalt und füge ihn in das Feld ein. +3. Du wirst zu einer QR-Scanner-Seite weitergeleitet, die direkt von deiner Home Assistant-Instanz bereitgestellt wird: + - **Mit Kamera** (HTTPS erforderlich): Wenn dein HA über HTTPS erreichbar ist (z.B. Nabu Casa, Reverse Proxy), kann die Handy-Kamera den QR-Code direkt im Browser scannen. + - **Manuelle Eingabe**: Falls die Kamera nicht funktioniert (z.B. HTTP-Only-Setup, Desktop-Browser, keine Kamera-Berechtigung), bietet die Scanner-Seite ein manuelles Eingabefeld. Scanne den QR-Code einfach mit einer beliebigen QR-Scanner-App auf deinem Handy, kopiere den Textinhalt und füge ihn in das Feld ein. 4. Scanne den QR-Code von der Siedle App (mit dem zweiten Gerät oder der Webcam) 5. Die Daten werden automatisch an HA übermittelt diff --git a/custom_components/siedle/config_flow.py b/custom_components/siedle/config_flow.py index 1d5c931..e5f27d1 100644 --- a/custom_components/siedle/config_flow.py +++ b/custom_components/siedle/config_flow.py @@ -2,7 +2,6 @@ import logging import voluptuous as vol import json -from urllib.parse import quote from homeassistant import config_entries from homeassistant.core import callback @@ -10,7 +9,6 @@ from .const import ( DOMAIN, - CONF_QR_CODE_URL, CONF_EXT_SIP_ENABLED, CONF_EXT_SIP_HOST, CONF_EXT_SIP_PORT, @@ -96,25 +94,14 @@ async def async_step_user(self, user_input=None): except Exception as e: _LOGGER.error("Error registering view: %s", e) - # Build callback URL for QR scanner - # Camera requires HTTPS (secure context). Prefer local HTTPS, - # fall back to external hosted scanner if only HTTP is available. + # Build URL for QR scanner page (served by HA itself) external = self.hass.config.external_url internal = self.hass.config.internal_url base_url = external or internal or "http://homeassistant.local:8123" flow_id = self.flow_id - callback_url = quote(f"{base_url}/api/siedle/qr_callback", safe='') - - # Check if we have HTTPS available -> use local scanner - if (external and external.startswith("https://")) or \ - (internal and internal.startswith("https://")): - # Use HTTPS URL for local scanner page - https_base = external if (external and external.startswith("https://")) else internal - qr_scanner_url = f"{https_base}/api/siedle/qr_scanner?config_flow_id={flow_id}&callback_url={callback_url}" - else: - # No HTTPS - fall back to external hosted scanner page - qr_scanner_url = f"{CONF_QR_CODE_URL}?config_flow_id={flow_id}&callback_url={callback_url}" + qr_scanner_url = f"{base_url}/api/siedle/qr_scanner?config_flow_id={flow_id}" + return self.async_external_step( step_id="qr_scan", url=qr_scanner_url, diff --git a/custom_components/siedle/const.py b/custom_components/siedle/const.py index decf689..e72eb33 100644 --- a/custom_components/siedle/const.py +++ b/custom_components/siedle/const.py @@ -1,9 +1,6 @@ """Constants for Siedle integration.""" DOMAIN = "siedle" -# Config Flow -CONF_QR_CODE_URL = "http://www.stefan-altheimer.de/siedle/index.html" - # Defaults DEFAULT_NAME = "Siedle" DEFAULT_SCAN_INTERVAL = 300 diff --git a/custom_components/siedle/fcm_handler.py b/custom_components/siedle/fcm_handler.py index 92f8bc6..3348e95 100644 --- a/custom_components/siedle/fcm_handler.py +++ b/custom_components/siedle/fcm_handler.py @@ -18,7 +18,6 @@ _LOGGER = logging.getLogger(__name__) -# Siedle Firebase Configuration (extracted from APK) SIEDLE_FIREBASE = { "project_id": "siedle-sus-android", "api_key": "AIzaSyDBeZC0fOq0b3WHZBUzvU2FM5nrLgglFQw",