06-sep: [aspiradora] mapping MIoT real r2205 (bateria siid3) + menu reabre categoria tras consulta
This commit is contained in:
@@ -295,6 +295,29 @@ def _fin_accion(chat_id):
|
||||
_enviar_nuevo(chat_id, "✅ Hecho. Pulsa /menu para volver al menú.", None)
|
||||
|
||||
|
||||
def _reabrir(chat_id, message_id, categoria, comando):
|
||||
"""Para consultas (estado, listar): ejecuta, borra los mensajes viejos
|
||||
dejando solo el ultimo resultado y muestra de nuevo el menu de la
|
||||
categoria (con su tecla de volver operativa)."""
|
||||
import pi_bot
|
||||
pi_bot.procesar(comando, chat_id)
|
||||
try:
|
||||
hist = pi_bot.historial_chat.get(chat_id, []) or []
|
||||
for mid in hist[:-1]:
|
||||
_borrar(chat_id, mid)
|
||||
pi_bot.historial_chat[chat_id] = hist[-1:] if hist else []
|
||||
ent = pi_bot.entrantes_chat.get(chat_id, []) or []
|
||||
for mid in ent:
|
||||
_borrar(chat_id, mid)
|
||||
pi_bot.entrantes_chat[chat_id] = []
|
||||
except Exception:
|
||||
pass
|
||||
_borrar(chat_id, message_id)
|
||||
teclado = _teclado_categoria(chat_id, categoria)
|
||||
if teclado is not None:
|
||||
_enviar_nuevo(chat_id, _header(categoria), teclado)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- menu ----
|
||||
|
||||
def enviar_menu(chat_id):
|
||||
@@ -318,8 +341,8 @@ def _header(categoria):
|
||||
return nombres.get(categoria, "🧭 <b>Menú IDD</b>")
|
||||
|
||||
|
||||
def _abrir_categoria(chat_id, message_id, categoria):
|
||||
teclado = {
|
||||
def _teclado_categoria(chat_id, categoria):
|
||||
teclados = {
|
||||
"videoclub": lambda: teclado_videoclub(chat_id),
|
||||
"nas": teclado_nas,
|
||||
"tv": teclado_tv,
|
||||
@@ -328,10 +351,15 @@ def _abrir_categoria(chat_id, message_id, categoria):
|
||||
"sistema": teclado_sistema,
|
||||
"router": teclado_router,
|
||||
}
|
||||
fn = teclado.get(categoria)
|
||||
if not fn:
|
||||
fn = teclados.get(categoria)
|
||||
return fn() if fn else None
|
||||
|
||||
|
||||
def _abrir_categoria(chat_id, message_id, categoria):
|
||||
teclado = _teclado_categoria(chat_id, categoria)
|
||||
if teclado is None:
|
||||
return False
|
||||
_enviar_edit(chat_id, message_id, _header(categoria), fn())
|
||||
_enviar_edit(chat_id, message_id, _header(categoria), teclado)
|
||||
return True
|
||||
|
||||
|
||||
@@ -460,18 +488,26 @@ def _ejecutar_accion(chat_id, message_id, partes):
|
||||
"qos": "qos estado",
|
||||
"limite": "limite listar",
|
||||
"seguridad": "seguridad estado",
|
||||
"parental_listar": "parental listar",
|
||||
}
|
||||
if accion == "parental_listar":
|
||||
_reabrir(chat_id, message_id, "parental", "parental listar")
|
||||
return
|
||||
if accion in directos:
|
||||
_disp(chat_id, message_id, directos[accion])
|
||||
return
|
||||
if accion == "termo":
|
||||
_disp(chat_id, message_id, f"termo {sub}")
|
||||
if sub == "estado":
|
||||
_reabrir(chat_id, message_id, "domotica", "termo estado")
|
||||
elif sub in ("on", "off"):
|
||||
_disp(chat_id, message_id, f"termo {sub}")
|
||||
_fin_accion(chat_id)
|
||||
return
|
||||
if accion == "aspiradora":
|
||||
if sub in ("estado", "start", "stop", "home", "pause", "locate"):
|
||||
_disp(chat_id, message_id, f"aspiradora {sub}")
|
||||
if sub != "estado":
|
||||
if sub == "estado":
|
||||
_reabrir(chat_id, message_id, "domotica", "aspiradora estado")
|
||||
else:
|
||||
_disp(chat_id, message_id, f"aspiradora {sub}")
|
||||
_fin_accion(chat_id)
|
||||
return
|
||||
if accion == "tablets":
|
||||
|
||||
Reference in New Issue
Block a user