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"Texto final {config.GOOGLE_TV_TEXTO_FINAL_SG}s en "
|
||||||
f"{c.cast_info.friendly_name}")
|
f"{c.cast_info.friendly_name}")
|
||||||
|
|
||||||
if config.GOOGLE_TV_APAGAR_VIA_ADB:
|
if apagar_tv_remote():
|
||||||
from tv_adb import apagar_tv
|
print(f"[Voz] {c.cast_info.friendly_name} apagada")
|
||||||
apagar_tv()
|
else:
|
||||||
elif config.ALEXA_APAGAR_TV_MONKEY:
|
print(f"[Voz] {c.cast_info.friendly_name} no se pudo apagar")
|
||||||
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)")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
||||||
finally:
|
finally:
|
||||||
@@ -322,6 +316,28 @@ def reproducir_en_teles(texto):
|
|||||||
anuncio_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):
|
def anuncio_simple(texto):
|
||||||
"""Mensaje rapido: enciende, reproduce el mensaje una vez y apaga."""
|
"""Mensaje rapido: enciende, reproduce el mensaje una vez y apaga."""
|
||||||
if not config.GOOGLE_TV_ACTIVO:
|
if not config.GOOGLE_TV_ACTIVO:
|
||||||
@@ -347,9 +363,7 @@ def anuncio_simple(texto):
|
|||||||
_reproducir_y_esperar(
|
_reproducir_y_esperar(
|
||||||
c, url_mensaje, tipo, texto[:80],
|
c, url_mensaje, tipo, texto[:80],
|
||||||
f"Mensaje simple en {c.cast_info.friendly_name}")
|
f"Mensaje simple en {c.cast_info.friendly_name}")
|
||||||
if config.GOOGLE_TV_APAGAR_VIA_ADB:
|
apagar_tv_remote()
|
||||||
from tv_adb import apagar_tv
|
|
||||||
apagar_tv()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user