src.nth.io/

summaryrefslogtreecommitdiff
path: root/unifi-protect-viewport/files/unifi-protect-viewport-debug
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-04-15 20:00:04 -0500
committerLuke Hoersten <[email protected]>2026-04-15 20:00:04 -0500
commit4ec792319b0cc9ab9aa3410c454f4880515c62c0 (patch)
tree876e693da2e2be042a574838484027de8be6b23d /unifi-protect-viewport/files/unifi-protect-viewport-debug
parent7d61034d91cc716ad6165f6867c49940ced94909 (diff)
Rename doorbell-viewport role to unifi-protect-viewport
Diffstat (limited to 'unifi-protect-viewport/files/unifi-protect-viewport-debug')
-rw-r--r--unifi-protect-viewport/files/unifi-protect-viewport-debug208
1 files changed, 208 insertions, 0 deletions
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 - <<PYEOF
+import os, sys, requests, urllib3
+urllib3.disable_warnings()
+host = os.environ['DOORBELL_VIEWPORT_PROTECT_HOST']
+user = os.environ['DOORBELL_VIEWPORT_PROTECT_USERNAME']
+passwd = os.environ['DOORBELL_VIEWPORT_PROTECT_PASSWORD']
+camera_id = os.environ['DOORBELL_VIEWPORT_CAMERA_ID']
+s = requests.Session()
+s.verify = False
+r = s.post(f'https://{host}/api/auth/login',
+ json={'username': user, 'password': passwd}, timeout=10)
+r.raise_for_status()
+r2 = s.get(f'https://{host}/proxy/protect/api/cameras/{camera_id}', timeout=10)
+r2.raise_for_status()
+for ch in r2.json().get('channels', []):
+ if ch.get('isRtspEnabled') and ch.get('rtspAlias'):
+ print(f"rtsp://{host}:7447/{ch['rtspAlias']}")
+ sys.exit(0)
+print('no-rtsp-url', file=sys.stderr)
+sys.exit(1)
+PYEOF
+ )
+
+ if [ -z "$RTSP_URL" ]; then
+ echo "Failed to get RTSP URL" >&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 - <<PYEOF
+import os, requests, urllib3
+urllib3.disable_warnings()
+host = os.environ['DOORBELL_VIEWPORT_PROTECT_HOST']
+user = os.environ['DOORBELL_VIEWPORT_PROTECT_USERNAME']
+passwd = os.environ['DOORBELL_VIEWPORT_PROTECT_PASSWORD']
+camera_id = os.environ['DOORBELL_VIEWPORT_CAMERA_ID']
+s = requests.Session()
+s.verify = False
+
+print(f"Connecting to {host}...")
+r = s.post(f'https://{host}/api/auth/login',
+ json={'username': user, 'password': passwd}, timeout=10)
+r.raise_for_status()
+print("Authentication: OK")
+
+r2 = s.get(f'https://{host}/proxy/protect/api/cameras/{camera_id}', timeout=10)
+r2.raise_for_status()
+data = r2.json()
+print(f"Camera name: {data.get('name', 'unknown')}")
+print(f"Camera type: {data.get('type', 'unknown')}")
+channels = [ch for ch in data.get('channels', []) if ch.get('isRtspEnabled')]
+print(f"RTSP channels: {len(channels)}")
+for ch in channels:
+ name = ch.get('name', '')
+ alias = ch.get('rtspAlias', '')
+ print(f" {name}: rtsp://{host}:7447/{alias}")
+print("Protect connection: OK")
+PYEOF
+}
+
+case "$CMD" in
+ show) cmd_show ;;
+ hide) cmd_hide ;;
+ test-display) cmd_test_display ;;
+ test-touch) cmd_test_touch ;;
+ test-stream) cmd_test_stream ;;
+ test-protect) cmd_test_protect ;;
+ help|*)
+ echo "Usage: doorbell-viewport-debug <command>"
+ 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