02-ago: [proyecto] vigilancia - apagado de la tele por ADB (KEYCODE_POWER) tras el anuncio, sin VoiceMonkey + adb-tools ignorado

This commit is contained in:
minguezsanzjuanjose
2026-08-02 14:35:03 +02:00
parent 5e5aaba4ed
commit f6745a7db1
4 changed files with 58 additions and 1 deletions

46
vigilancia/tv_adb.py Normal file
View File

@@ -0,0 +1,46 @@
import subprocess
import time
import config
def _adb(args, timeout=20):
try:
return subprocess.run(
[config.ADB_PATH] + args,
capture_output=True, text=True, timeout=timeout,
)
except Exception as e:
print(f"[ADB] Error: {e}")
return None
def estado():
r = _adb(["devices"])
if r is None:
return "error"
for linea in r.stdout.splitlines()[1:]:
if linea.strip().startswith(config.ADB_TV_IP):
if "unauthorized" in linea:
return "unauthorized"
if "device" in linea:
return "device"
return "offline"
def conectar():
_adb(["connect", config.ADB_TV_IP])
time.sleep(1)
return estado()
def apagar_tv():
"""Apaga la tele igual que el boton POWER del mando (KEYCODE_POWER)."""
e = conectar()
if e != "device":
print(f"[ADB] Tele no disponible ({e})")
return False
r = _adb(["-s", config.ADB_TV_IP, "shell", "input", "keyevent", "26"])
ok = r is not None and r.returncode == 0
print("[ADB] Comando POWER enviado" if ok else "[ADB] Fallo al enviar POWER")
return ok