02-ago: [proyecto] vigilancia - apagado TV por AndroidTVRemote (protocolo oficial Google, sin ADB/VoiceMonkey). Emparejado con PIN, certificado persistente.
This commit is contained in:
@@ -300,16 +300,10 @@ def anuncio_en_teles(texto):
|
||||
f"Texto final {config.GOOGLE_TV_TEXTO_FINAL_SG}s en "
|
||||
f"{c.cast_info.friendly_name}")
|
||||
|
||||
if config.GOOGLE_TV_APAGAR_VIA_ADB:
|
||||
from tv_adb import apagar_tv
|
||||
apagar_tv()
|
||||
elif config.ALEXA_APAGAR_TV_MONKEY:
|
||||
print("[Voz] Apagando la tele via Alexa...")
|
||||
from notificador import disparar_monkey_alexa
|
||||
disparar_monkey_alexa(config.ALEXA_APAGAR_TV_MONKEY)
|
||||
if config.GOOGLE_TV_APAGAR:
|
||||
c.quit_app()
|
||||
print(f"[Voz] {c.cast_info.friendly_name} apagada (standby)")
|
||||
if apagar_tv_remote():
|
||||
print(f"[Voz] {c.cast_info.friendly_name} apagada")
|
||||
else:
|
||||
print(f"[Voz] {c.cast_info.friendly_name} no se pudo apagar")
|
||||
except Exception as e:
|
||||
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
||||
finally:
|
||||
@@ -322,6 +316,28 @@ def reproducir_en_teles(texto):
|
||||
anuncio_en_teles(texto)
|
||||
|
||||
|
||||
def apagar_tv_remote():
|
||||
"""Apaga la TV via AndroidTVRemote (protocolo oficial Google)."""
|
||||
try:
|
||||
import asyncio
|
||||
from androidtvremote2 import AndroidTVRemote
|
||||
CERT = "/home/pi/minipc/tv_cert/cert.pem"
|
||||
KEY = "/home/pi/minipc/tv_cert/key.pem"
|
||||
TV_IP = "192.168.50.16"
|
||||
async def _apagar():
|
||||
r = AndroidTVRemote(
|
||||
client_name="MiniPC", certfile=CERT, keyfile=KEY, host=TV_IP)
|
||||
await r.async_connect()
|
||||
if r.is_on:
|
||||
r.send_key_command("POWER")
|
||||
return True
|
||||
return False
|
||||
return asyncio.run(_apagar())
|
||||
except Exception as e:
|
||||
print(f"[Voz] Error apagando TV: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def anuncio_simple(texto):
|
||||
"""Mensaje rapido: enciende, reproduce el mensaje una vez y apaga."""
|
||||
if not config.GOOGLE_TV_ACTIVO:
|
||||
@@ -347,9 +363,7 @@ def anuncio_simple(texto):
|
||||
_reproducir_y_esperar(
|
||||
c, url_mensaje, tipo, texto[:80],
|
||||
f"Mensaje simple en {c.cast_info.friendly_name}")
|
||||
if config.GOOGLE_TV_APAGAR_VIA_ADB:
|
||||
from tv_adb import apagar_tv
|
||||
apagar_tv()
|
||||
apagar_tv_remote()
|
||||
except Exception as e:
|
||||
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user