superguardado: fixes pi_bot (offset persistente, unit systemd) + voz.py (desconectar chromecast) + lecciones 27-31

This commit is contained in:
minguezsanzjuanjose
2026-08-02 23:26:26 +02:00
parent 5d232cd830
commit 312646f510
3 changed files with 47 additions and 2 deletions

View File

@@ -231,6 +231,15 @@ def _url_silencio():
return f"http://{_ip_lan()}:{config.GOOGLE_TV_PUERTO}/{os.path.basename(ruta)}"
def _desconectar(chromecasts):
for cc in chromecasts:
try:
if cc.is_active and cc.is_connected:
cc.disconnect()
except Exception:
pass
def _reproducir_y_esperar(c, url, content_type, titulo, desc):
c.media_controller.play_media(url, content_type, title=titulo)
print(f"[Voz] {desc}")
@@ -307,6 +316,7 @@ def anuncio_en_teles(texto):
except Exception as e:
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
finally:
_desconectar(chromecasts)
pychromecast.discovery.stop_discovery(browser)
except Exception as e:
print(f"[Voz] Error de casting: {e}")
@@ -358,6 +368,7 @@ def youtube_en_teles(url):
except Exception as e:
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
finally:
_desconectar(chromecasts)
pychromecast.discovery.stop_discovery(browser)
except Exception as e:
print(f"[Voz] Error YouTube: {e}")
@@ -414,6 +425,7 @@ def anuncio_simple(texto):
except Exception as e:
print(f"[Voz] Error en {c.cast_info.friendly_name}: {e}")
finally:
_desconectar(chromecasts)
pychromecast.discovery.stop_discovery(browser)
except Exception as e:
print(f"[Voz] Error de casting: {e}")