Skip to content

Commit

Permalink
fix: prefer WebSockets over XMPP (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jan 24, 2025
1 parent aca43f7 commit 381ec77
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/aioharmony/harmonyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import aioharmony.exceptions as aioexc
import aioharmony.handler as handlers
from aioharmony.const import (
DEFAULT_XMPP_HUB_PORT,
DEFAULT_WS_HUB_PORT,
HUB_COMMANDS,
PROTOCOL,
WEBSOCKETS,
Expand Down Expand Up @@ -135,33 +135,35 @@ def current_activity_id(self):

async def _websocket_or_xmpp(self) -> bool:
"""
Determine if XMPP is enabled, if not fall-back to web sockets.
Determine if web sockets are enabled, if not fall-back to XMPP.
"""
if not self._protocol == WEBSOCKETS:
if self._protocol != XMPP:
try:
_, _ = await asyncio.open_connection(
host=self._ip_address, port=DEFAULT_XMPP_HUB_PORT
host=self._ip_address, port=DEFAULT_WS_HUB_PORT
)
except ConnectionRefusedError:
if self._protocol == XMPP:
_LOGGER.warning(
"%s: XMPP is not enabled on this HUB, will be defaulting back to WEBSOCKETS.",
"%s: WEBSOCKETS is not enabled on this HUB, will be defaulting back to XMPP.",
self.name,
)
else:
_LOGGER.debug(
"%s: XMPP is not enabled, using web sockets.", self.name
"%s: WEBSOCKETS is not enabled, using XMPP.", self.name
)
self._protocol = WEBSOCKETS
self._protocol = XMPP
except OSError as exc:
_LOGGER.error(
"%s: Unable to determine if XMPP is enabled: %s", self.name, exc
"%s: Unable to determine if Websocket is available: %s",
self.name,
exc,
)
if self._protocol is None:
return False
else:
_LOGGER.debug("%s: XMPP is enabled", self.name)
self._protocol = XMPP
_LOGGER.debug("%s: Websocket available", self.name)
self._protocol = WEBSOCKETS

if self._protocol == WEBSOCKETS:
_LOGGER.debug("%s: Using WEBSOCKETS", self.name)
Expand Down

0 comments on commit 381ec77

Please sign in to comment.