From 4ec792319b0cc9ab9aa3410c454f4880515c62c0 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Wed, 15 Apr 2026 20:00:04 -0500 Subject: Rename doorbell-viewport role to unifi-protect-viewport --- .../files/unifi-protect-viewport-debug | 208 +++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 unifi-protect-viewport/files/unifi-protect-viewport-debug (limited to 'unifi-protect-viewport/files/unifi-protect-viewport-debug') diff --git a/unifi-protect-viewport/files/unifi-protect-viewport-debug b/unifi-protect-viewport/files/unifi-protect-viewport-debug new file mode 100644 index 0000000..1305c13 --- /dev/null +++ b/unifi-protect-viewport/files/unifi-protect-viewport-debug @@ -0,0 +1,208 @@ +#!/bin/bash +# doorbell-viewport-debug: CLI debug tool +# +# Commands: +# show Turn display on +# hide Turn display off +# test-display Test display power cycle (on -> 3s -> off) +# test-touch List touch devices and capabilities +# test-stream Fetch RTSP URL from Protect and play via mpv +# test-protect Test Protect API authentication and camera info + +set -e + +ENV_FILE="/etc/doorbell-viewport/doorbell-viewport.env" +CMD="${1:-help}" + +_load_env() { + if [ -f "$ENV_FILE" ]; then + set -a + # shellcheck disable=SC1090 + source "$ENV_FILE" + set +a + else + echo "Warning: $ENV_FILE not found" >&2 + fi +} + +_display_on() { + BACKLIGHT=$(ls /sys/class/backlight/ 2>/dev/null | head -1) + if [ -n "$BACKLIGHT" ]; then + MAX=$(cat "/sys/class/backlight/$BACKLIGHT/max_brightness") + echo "$MAX" > "/sys/class/backlight/$BACKLIGHT/brightness" + else + echo "No backlight device found" >&2 + fi +} + +_display_off() { + BACKLIGHT=$(ls /sys/class/backlight/ 2>/dev/null | head -1) + if [ -n "$BACKLIGHT" ]; then + echo "0" > "/sys/class/backlight/$BACKLIGHT/brightness" + else + echo "No backlight device found" >&2 + fi +} + +cmd_show() { + _load_env + echo "Turning display on..." + _display_on + echo "Display on" +} + +cmd_hide() { + _load_env + echo "Turning display off..." + _display_off + echo "Display off" +} + +cmd_test_display() { + _load_env + echo "Testing display power cycle..." + echo "ON..." + _display_on + sleep 3 + echo "OFF..." + _display_off + echo "Done" +} + +cmd_test_touch() { + echo "Touch devices:" + python3 - <<'PYEOF' +import evdev +for path in evdev.list_devices(): + try: + dev = evdev.InputDevice(path) + caps = dev.capabilities() + has_mt = ( + evdev.ecodes.EV_ABS in caps + and any( + code == evdev.ecodes.ABS_MT_POSITION_X + for code, _ in caps[evdev.ecodes.EV_ABS] + ) + ) + has_btn = ( + evdev.ecodes.EV_KEY in caps + and evdev.ecodes.BTN_TOUCH in [code for code, _ in caps.get(evdev.ecodes.EV_KEY, [])] + ) + print(f" {path}: {dev.name!r} (multitouch={has_mt}, btn_touch={has_btn})") + dev.close() + except Exception as e: + print(f" {path}: error: {e}") +PYEOF + echo "" + echo "To monitor live touch events interactively:" + echo " python3 -m evdev.evtest" +} + +cmd_test_stream() { + _load_env + if [ -z "$DOORBELL_VIEWPORT_PROTECT_HOST" ]; then + echo "Error: DOORBELL_VIEWPORT_PROTECT_HOST not set" >&2 + exit 1 + fi + + echo "Fetching RTSP URL from $DOORBELL_VIEWPORT_PROTECT_HOST..." + RTSP_URL=$(python3 - <&2 + exit 1 + fi + + echo "Playing: $RTSP_URL" + echo "(press q to quit)" + mpv \ + --vo=drm \ + "--video-rotate=${DOORBELL_VIEWPORT_ORIENTATION:-270}" \ + --fullscreen \ + --no-border \ + --no-osc \ + --no-input-default-bindings \ + --really-quiet \ + "$RTSP_URL" +} + +cmd_test_protect() { + _load_env + if [ -z "$DOORBELL_VIEWPORT_PROTECT_HOST" ]; then + echo "Error: DOORBELL_VIEWPORT_PROTECT_HOST not set" >&2 + exit 1 + fi + + python3 - <" + echo "" + echo "Commands:" + echo " show Turn display on" + echo " hide Turn display off" + echo " test-display Test display power cycle (on -> 3s -> off)" + echo " test-touch List touch devices and capabilities" + echo " test-stream Fetch RTSP URL and play via mpv" + echo " test-protect Test Protect API connection and camera info" + echo "" + echo "Config: $ENV_FILE" + ;; +esac -- cgit v1.2.3