Skip to content

Commit

Permalink
Add the ability to get the remote id without connecting the websocket (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 17, 2021
1 parent bc03061 commit 7f310cd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions aioharmony/hubconnector_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _session(self):
timeout=session_timeout)
return self._aiohttp_session

async def _get_remote_id(self) -> Optional[str]:
async def get_remote_id(self) -> Optional[str]:
"""Retrieve remote id from the HUB."""

if self._remote_id is None:
Expand All @@ -110,6 +110,14 @@ async def _get_remote_id(self) -> Optional[str]:
DEFAULT_DOMAIN
return self._remote_id

async def async_close_session(self) -> None:
""""Close the aiohttp session."""
if self._aiohttp_session is None:
return
with suppress(asyncio.TimeoutError), timeout(DEFAULT_TIMEOUT):
await self._aiohttp_session.close()
self._aiohttp_session = None

async def hub_connect(self, is_reconnect: bool = False) -> bool:
"""Connect to Hub Web Socket"""
# Acquire the lock.
Expand All @@ -128,7 +136,7 @@ async def hub_connect(self, is_reconnect: bool = False) -> bool:
else:
log_level = 40

if await self._get_remote_id() is None:
if await self.get_remote_id() is None:
# No remote ID means no connect.
_LOGGER.log(log_level,
"%s: Unable to retrieve HUB id",
Expand Down Expand Up @@ -248,12 +256,10 @@ async def _reconnect(self) -> None:
self._aiohttp_session.closed:
_LOGGER.debug("%s: Closing sessions",
self._ip_address)
with suppress(asyncio.TimeoutError), timeout(DEFAULT_TIMEOUT):
await self._aiohttp_session.close()
await self.async_close_session()

# Set web socket to none allowing for reconnect.
self._websocket = None
self._aiohttp_session = None

is_reconnect = False
self._connected = False
Expand Down

0 comments on commit 7f310cd

Please sign in to comment.