03-oct: superguardado automático

This commit is contained in:
minguezsanzjuanjose
2026-10-03 19:24:21 +02:00
parent 1b385cca7c
commit 5446db6a2b
6 changed files with 104 additions and 56 deletions

View File

@@ -9,6 +9,16 @@ from dotenv import load_dotenv
dotenv_path = r"C:\Users\juanm\Documents\GitHub\biblioteca_negocio_prolongo\.env"
load_dotenv(dotenv_path)
# Permitir importar modulos del repo de negocio (ha_alexa).
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
if _SCRIPT_DIR not in sys.path:
sys.path.insert(0, _SCRIPT_DIR)
try:
import infra_paths
infra_paths.bootstrap_biblioteca_paths()
except Exception:
pass
def cerrar_ventanas():
print("1. Cerrando ventanas abiertas (excepto terminal de OpenCode)...")
ps_command = """
@@ -25,32 +35,16 @@ def cerrar_ventanas():
print(" -> Ventanas cerradas.")
def apagar_luces_alexa():
"""Apaga las luces 'barras' y 'cuartillo' via VoiceMonkey"""
print("2. Apagando luces de Alexa (barras + cuartillo)...")
token = os.getenv("VOICEMONKEY_TOKEN")
if not token:
print(" -> [ERROR] Falta VOICEMONKEY_TOKEN en .env")
"""Apaga las luces 'barras' y 'cuartillo' via HOME ASSISTANT (sustituye a VoiceMonkey)."""
print("2. Apagando luces de Alexa via Home Assistant (barras + cuartillo)...")
try:
from ha_alexa import command
except Exception as e:
print(f" -> [ERROR] No se pudo cargar ha_alexa: {e}")
return
# VoiceMonkey: crear dos "monkeys" (triggers virtuales) llamados 'apagar-barras' y 'apagar-cuartillo'
# que en su rutina de Alexa ejecutan: "Alexa, apaga barras" y "Alexa, apaga cuartillo"
luces = [
("barras", "apagar-barras"),
("cuartillo", "apagar-cuartillo")
]
for nombre, monkey in luces:
url = f"https://api-v2.voicemonkey.io/trigger?token={token}&device={monkey}"
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req, timeout=10) as response:
if response.status == 200:
print(f" -> Señal enviada para apagar '{nombre}'")
else:
print(f" -> Error HTTP {response.status} al apagar '{nombre}'")
except Exception as e:
print(f" -> Error al apagar '{nombre}': {e}")
for nombre in ("barras", "cuartillo"):
ok = command(f"apaga {nombre}")
print(f" -> {'OK' if ok else 'ERROR'} al apagar '{nombre}'")
def apagar_pantalla_tapo():
print("3. Apagando pantalla (Tapo) via túnel RPi...")