Fix slixmpp 1.13 compatibility and empty capabilities handling

- Replace process(forever=True) with asyncio event loop in _SlixClient.start()
- Make send_xmpp_message() thread-safe via loop.call_soon_threadsafe()
- Remove wait=True from join_muc() (no longer supported in slixmpp 1.13)
- Silence empty retained MQTT capability messages in CapabilitiesRegistry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 10:28:28 +00:00
parent c1666db5aa
commit 7ab395037d
2 changed files with 13 additions and 3 deletions
+2
View File
@@ -63,6 +63,8 @@ class CapabilitiesRegistry:
logger.debug(f"[Registry] Capacités mises à jour pour {caps.agent_id}") logger.debug(f"[Registry] Capacités mises à jour pour {caps.agent_id}")
def update_from_json(self, data: str | bytes) -> Optional[AgentCapabilities]: def update_from_json(self, data: str | bytes) -> Optional[AgentCapabilities]:
if not data or (isinstance(data, (str, bytes)) and not data.strip()):
return None # Empty retained message — ignore silently
try: try:
caps = AgentCapabilities.from_json(data) caps = AgentCapabilities.from_json(data)
self.update(caps) self.update(caps)
+11 -3
View File
@@ -187,8 +187,12 @@ class _SlixClient(ClientXMPP):
logger.warning(f"[XMPP] OMEMO non disponible : {e}") logger.warning(f"[XMPP] OMEMO non disponible : {e}")
def start(self): def start(self):
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self.loop = loop
self.connect() self.connect()
self.process(forever=True) loop.run_forever()
async def _on_session_start(self, event): async def _on_session_start(self, event):
self.send_presence() self.send_presence()
@@ -197,7 +201,6 @@ class _SlixClient(ClientXMPP):
self.plugin["xep_0045"].join_muc( self.plugin["xep_0045"].join_muc(
room=self._muc_room, room=self._muc_room,
nick=self._muc_nick, nick=self._muc_nick,
wait=True,
) )
if self._on_connected_cb: if self._on_connected_cb:
self._on_connected_cb() self._on_connected_cb()
@@ -217,5 +220,10 @@ class _SlixClient(ClientXMPP):
self._on_message_cb(str(msg["from"]), body, is_muc=True) self._on_message_cb(str(msg["from"]), body, is_muc=True)
def send_xmpp_message(self, to: str, body: str, is_muc: bool = False): def send_xmpp_message(self, to: str, body: str, is_muc: bool = False):
import functools
msg_type = "groupchat" if is_muc else "chat" msg_type = "groupchat" if is_muc else "chat"
self.send_message(mto=to, mbody=body, mtype=msg_type) fn = functools.partial(self.send_message, mto=to, mbody=body, mtype=msg_type)
if hasattr(self, 'loop') and self.loop and self.loop.is_running():
self.loop.call_soon_threadsafe(fn)
else:
fn()