Compare commits
1 Commits
main
...
renovate/g
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2de498d0a2 |
@ -1,3 +1,3 @@
|
|||||||
name: "HA Add-ons by kvanzuijlen & Julian"
|
name: "HA Add-ons by kvanzuijlen"
|
||||||
url: "https://git.xn--julianbrger-zhb.de/admin/homeassistant-tuya-ipc-terminal-addon"
|
url: "https://github.com/kvanzuijlen/homeassistant-tuya-ipc-terminal-addon"
|
||||||
maintainer: "Julian"
|
maintainer: "kvanzuijlen"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# Dockerfile for Tuya IPC Terminal Add-on
|
# Dockerfile for Tuya IPC Terminal Add-on
|
||||||
ARG BUILD_FROM
|
ARG BUILD_FROM
|
||||||
FROM golang:1.24-bookworm@sha256:7b25b1ea217e0a56060953b3d4859134ecbe757d7434f7ce4756e0c25aad1ef0 AS builder
|
FROM golang:1.24-bookworm@sha256:4ed690d6649d63c312b99a6120025ec79ce3b542968a37da53d6236c7c61a848 AS builder
|
||||||
|
|
||||||
# Set up environment
|
# Set up environment
|
||||||
ENV LANG=C.UTF-8
|
ENV LANG=C.UTF-8
|
||||||
@ -16,8 +16,8 @@ COPY --from=builder /usr/src/app/tuya-ipc-terminal /usr/bin/
|
|||||||
|
|
||||||
# Copy run script
|
# Copy run script
|
||||||
COPY run.sh /
|
COPY run.sh /
|
||||||
COPY tuya_auth_login.exp /
|
COPY tuya_auth_qr.exp /
|
||||||
RUN chmod a+x /run.sh && chmod +x /tuya_auth_login.exp && chmod a+x /usr/bin/tuya-ipc-terminal
|
RUN chmod a+x /run.sh && chmod +x /tuya_auth_qr.exp && chmod a+x /usr/bin/tuya-ipc-terminal
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y expect && apt-get clean
|
RUN apt-get update && apt-get install -y expect && apt-get clean
|
||||||
RUN mkdir -p /config
|
RUN mkdir -p /config
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# Home Assistant add-on configuration for Tuya IPC Terminal
|
# Home Assistant add-on configuration for Tuya IPC Terminal
|
||||||
name: Tuya IPC Terminal
|
name: Tuya IPC Terminal
|
||||||
version: "1.0.19"
|
version: "1.0.0"
|
||||||
slug: tuya_ipc_terminal
|
slug: tuya_ipc_terminal
|
||||||
description: "Exposes Tuya camera streams as RTSP feeds"
|
description: "Exposes Tuya camera streams as RTSP feeds"
|
||||||
arch:
|
arch:
|
||||||
@ -14,12 +14,10 @@ startup: "application"
|
|||||||
boot: "auto"
|
boot: "auto"
|
||||||
options:
|
options:
|
||||||
TUYA_EMAIL: ""
|
TUYA_EMAIL: ""
|
||||||
TUYA_PASSWORD: ""
|
|
||||||
TUYA_REGION: "eu-central"
|
TUYA_REGION: "eu-central"
|
||||||
schema:
|
schema:
|
||||||
TUYA_EMAIL: str
|
TUYA_EMAIL: "email"
|
||||||
TUYA_PASSWORD: password
|
TUYA_REGION: "str"
|
||||||
TUYA_REGION: list(eu-central|eu-east|us-west|us-east|china|india)
|
|
||||||
ports:
|
ports:
|
||||||
8554/tcp: 8554
|
8554/tcp: 8554
|
||||||
ports_description:
|
ports_description:
|
||||||
|
|||||||
@ -1,69 +1,29 @@
|
|||||||
#!/usr/bin/with-contenv bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
|
# ==============================================================================
|
||||||
|
# Home Assistant Add-on: Tuya IPC Terminal
|
||||||
|
#
|
||||||
|
# This script starts the Tuya IPC Terminal application with the configured
|
||||||
|
# options.
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
# Konfiguration lesen
|
# Read configuration options
|
||||||
readonly TUYA_EMAIL=$(bashio::config 'TUYA_EMAIL')
|
readonly TUYA_EMAIL=$(bashio::config 'TUYA_EMAIL')
|
||||||
readonly TUYA_PASSWORD=$(bashio::config 'TUYA_PASSWORD')
|
|
||||||
readonly TUYA_REGION=$(bashio::config 'TUYA_REGION')
|
readonly TUYA_REGION=$(bashio::config 'TUYA_REGION')
|
||||||
|
|
||||||
if [[ -z "${TUYA_EMAIL}" || -z "${TUYA_PASSWORD}" ]]; then
|
# Check if required options are set
|
||||||
bashio::log.fatal "Tuya-E-Mail und Passwort müssen konfiguriert sein."
|
if [[ -z "${TUYA_EMAIL}" ]]; then
|
||||||
|
bashio::log.fatal "Please configure your Tuya email in the addon options."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- START: Authentifizierung und Kamera-Sync ---
|
# Authenticate with Tuya
|
||||||
bashio::log.info "Authentifizierung bei Tuya..."
|
bashio::log.info "Authenticating with Tuya..."
|
||||||
printf "%s\n%s\n%s\n" "${TUYA_REGION}" "${TUYA_EMAIL}" "${TUYA_PASSWORD}" | /tuya_auth_login.exp
|
printf "%s\n%s\n" "${TUYA_REGION}" "${TUYA_EMAIL}" | /tuya_auth_qr.exp
|
||||||
|
|
||||||
bashio::log.info "Synchronisiere Kameraliste mit Tuya-Cloud..."
|
# Refresh camera list
|
||||||
RETRIES=5
|
bashio::log.info "Refreshing camera list..."
|
||||||
SUCCESS=false
|
tuya-ipc-terminal cameras refresh
|
||||||
for i in $(seq 1 $RETRIES); do
|
|
||||||
bashio::log.info "Versuch ${i}/${RETRIES}, die Kameraliste abzurufen..."
|
|
||||||
if tuya-ipc-terminal cameras refresh; then
|
|
||||||
bashio::log.info "Kameraliste erfolgreich synchronisiert."
|
|
||||||
SUCCESS=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
bashio::log.warning "Fehler bei der Synchronisierung der Kameras. Warte 10 Sekunden."
|
|
||||||
sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$SUCCESS" = false ]; then
|
# Start the RTSP server
|
||||||
bashio::log.fatal "Konnte Kameraliste nach ${RETRIES} Versuchen nicht abrufen. Addon wird beendet."
|
bashio::log.info "Starting RTSP server on port 8554..."
|
||||||
exit 1
|
tuya-ipc-terminal rtsp start --port 8554
|
||||||
fi
|
|
||||||
|
|
||||||
# --- Starte den RTSP-Server und den Watchdog ---
|
|
||||||
bashio::log.info "Starte den Tuya RTSP-Server im Hintergrund..."
|
|
||||||
tuya-ipc-terminal rtsp start --port 8554 &
|
|
||||||
RTSP_PID=$!
|
|
||||||
sleep 2
|
|
||||||
bashio::log.info "RTSP-Server gestartet mit PID ${RTSP_PID}."
|
|
||||||
|
|
||||||
# --- KORRIGIERTE PRÜFUNG (OHNE 'ps') ---
|
|
||||||
if [ ! -d "/proc/${RTSP_PID}" ]; then
|
|
||||||
bashio::log.fatal "RTSP-Server konnte nicht gestartet werden oder ist sofort abgestürzt."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
bashio::log.info "Starte den Watchdog zur Überwachung der Sitzung."
|
|
||||||
while true; do
|
|
||||||
sleep 900
|
|
||||||
|
|
||||||
# --- KORRIGIERTE PRÜFUNG (OHNE 'ps') ---
|
|
||||||
if [ ! -d "/proc/${RTSP_PID}" ]; then
|
|
||||||
bashio::log.error "Watchdog: RTSP-Server-Prozess nicht gefunden! Starte das Addon neu."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
bashio::log.info "Watchdog: Überprüfe den Status der Tuya-Sitzung..."
|
|
||||||
RESPONSE=$(tuya-ipc-terminal cameras refresh 2>&1)
|
|
||||||
|
|
||||||
if echo "${RESPONSE}" | grep -q -E "401|USER_SESSION_LOSS|Not login"; then
|
|
||||||
bashio::log.error "Watchdog: Abgelaufene Sitzung erkannt! Starte das Addon neu."
|
|
||||||
kill "${RTSP_PID}"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
bashio::log.info "Watchdog: Sitzung ist gültig und RTSP-Server läuft."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|||||||
@ -1,63 +0,0 @@
|
|||||||
#!/usr/bin/expect -f
|
|
||||||
|
|
||||||
# Aktiviere internes Debugging, um den Ablauf zu verfolgen
|
|
||||||
exp_internal 1
|
|
||||||
puts "DEBUG: Expect-Skript gestartet."
|
|
||||||
|
|
||||||
# Entferne alte Konfiguration, um eine neue Sitzung zu erzwingen
|
|
||||||
set config_dir "/config/.tuya-data"
|
|
||||||
if { [file isdirectory $config_dir] } {
|
|
||||||
puts "DEBUG: Altes Konfigurationsverzeichnis gefunden, wird entfernt."
|
|
||||||
if {[catch {file delete -force -- $config_dir} err]} {
|
|
||||||
puts stderr "FATAL: Konnte Verzeichnis '$config_dir' nicht löschen: $err"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
puts "DEBUG: Starte Authentifizierungsprozess."
|
|
||||||
set timeout 60
|
|
||||||
|
|
||||||
# Lese Eingaben
|
|
||||||
gets stdin region
|
|
||||||
gets stdin email
|
|
||||||
gets stdin password
|
|
||||||
|
|
||||||
if { $region eq "" || $email eq "" || $password eq "" } {
|
|
||||||
puts stderr "FATAL: Eine der Eingaben ist leer."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
spawn tuya-ipc-terminal auth add $region $email --password
|
|
||||||
|
|
||||||
# --- START DER ENTSCHEIDENDEN KORREKTUR ---
|
|
||||||
# Verwende einen regulären Ausdruck (-re), der auf verschiedene Passwortabfragen reagiert.
|
|
||||||
# "Enter ?[Pp]assword:" fängt "Enter password:" und "Enter Password:" ab.
|
|
||||||
expect {
|
|
||||||
-re {Password:|Enter ?[Pp]assword:?|Please enter your password:} {
|
|
||||||
puts "DEBUG: Passwortabfrage erkannt. Sende Passwort..."
|
|
||||||
send "$password\r"
|
|
||||||
puts "DEBUG: Passwort gesendet."
|
|
||||||
# exp_continue sorgt dafür, dass das Skript auf weitere Ausgaben wartet
|
|
||||||
exp_continue
|
|
||||||
}
|
|
||||||
# --- ENDE DER KORREKTUR ---
|
|
||||||
|
|
||||||
"Authentication successful" {
|
|
||||||
puts "DEBUG: Erfolgsmeldung 'Authentication successful' erkannt."
|
|
||||||
# Warte, bis der Prozess sich beendet hat
|
|
||||||
catch {expect eof}
|
|
||||||
catch {wait}
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
eof {
|
|
||||||
puts "DEBUG: Prozess hat sich beendet (EOF)."
|
|
||||||
# Prüfe den Exit-Code des beendeten Prozesses
|
|
||||||
set exit_code [lindex [wait] 2]
|
|
||||||
puts "DEBUG: Prozess beendet mit Exit-Code $exit_code."
|
|
||||||
exit $exit_code
|
|
||||||
}
|
|
||||||
timeout {
|
|
||||||
puts stderr "FATAL: Timeout nach 60 Sekunden."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
40
tuya-ipc-terminal/tuya_auth_qr.exp
Normal file
40
tuya-ipc-terminal/tuya_auth_qr.exp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/expect -f
|
||||||
|
|
||||||
|
# Check if the config directory already exists.
|
||||||
|
set config_dir "/config/.tuya-data"
|
||||||
|
if { [file isdirectory $config_dir] } {
|
||||||
|
# If it exists, print a message and exit successfully.
|
||||||
|
puts "Skipping authentication: Configuration directory '$config_dir' already exists. To re-authenticate, delete the folder from the addon config folder."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# If the directory does not exist, proceed with authentication.
|
||||||
|
puts "Configuration directory not found. Proceeding with authentication..."
|
||||||
|
|
||||||
|
# Set a timeout for the expect command to wait for a response.
|
||||||
|
set timeout 20
|
||||||
|
|
||||||
|
# Read the region from the first line of standard input.
|
||||||
|
gets stdin region
|
||||||
|
if { [eof stdin] || $region eq "" } {
|
||||||
|
puts stderr "Error: Could not read region from stdin or region is empty."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Read the email from the second line of standard input.
|
||||||
|
gets stdin email
|
||||||
|
if { [eof stdin] || $email eq "" } {
|
||||||
|
puts stderr "Error: Could not read email from stdin or email is empty."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Spawn the tuya-ipc-terminal command, using the email variable.
|
||||||
|
spawn tuya-ipc-terminal auth add $region $email --qr
|
||||||
|
|
||||||
|
expect "Press Enter after scanning to continue"
|
||||||
|
|
||||||
|
# Send the Enter key
|
||||||
|
send "\r"
|
||||||
|
|
||||||
|
expect eof
|
||||||
|
wait
|
||||||
Loading…
x
Reference in New Issue
Block a user