text
stringlengths 1
93.6k
|
|---|
)
|
await self._connect()
|
continue
|
try:
|
async with asyncio.timeout(UDPC_UPDATE_CHECK_TIMEOUT):
|
sleep_interval = await self._udpc_update_handler(sleep_interval)
|
except TimeoutError as e:
|
_LOGGER.warning(
|
f"UDPC Update Check timeout after {UDPC_UPDATE_CHECK_TIMEOUT} sec. "
|
f"({e.__class__.__qualname__}: {e})"
|
)
|
await self._add_error()
|
await self._telnet.close()
|
self._telnet = None
|
sleep_interval = 3
|
await asyncio.sleep(sleep_interval)
|
raise ChildProcessError(
|
f"JuiceboxUDPCUpdater: More than {self._error_count} "
|
f"errors in the last {ERROR_LOOKBACK_MIN} min."
|
)
|
async def _udpc_update_handler(self, default_sleep_interval):
|
sleep_interval = default_sleep_interval
|
try:
|
_LOGGER.info("JuiceboxUDPCUpdater Check Starting")
|
connections = await self._telnet.get_udpc_list()
|
update_required = True
|
udpc_streams_to_close = {} # Key = Connection id, Value = list id
|
udpc_stream_to_update = 0
|
# _LOGGER.debug(f"connections: {connections}")
|
for i, connection in enumerate(connections):
|
if connection["type"] == "UDPC":
|
udpc_streams_to_close.update({int(connection["id"]): i})
|
if self._jpp_host not in connection["dest"]:
|
udpc_stream_to_update = int(connection["id"])
|
# _LOGGER.debug(f"udpc_streams_to_close: {udpc_streams_to_close}")
|
if udpc_stream_to_update == 0 and len(udpc_streams_to_close) > 0:
|
udpc_stream_to_update = int(max(udpc_streams_to_close, key=int))
|
_LOGGER.debug(f"Active UDPC Stream: {udpc_stream_to_update}")
|
for stream in list(udpc_streams_to_close):
|
if stream < udpc_stream_to_update:
|
udpc_streams_to_close.pop(stream, None)
|
if len(udpc_streams_to_close) == 0:
|
_LOGGER.info("UDPC IP not found, updating")
|
elif (
|
self._jpp_host
|
not in connections[udpc_streams_to_close[udpc_stream_to_update]]["dest"]
|
):
|
_LOGGER.info("UDPC IP incorrect, updating")
|
_LOGGER.debug(f"connections: {connections}")
|
elif len(udpc_streams_to_close) == 1:
|
_LOGGER.info("UDPC IP correct")
|
update_required = False
|
if update_required:
|
for id in udpc_streams_to_close:
|
_LOGGER.debug(f"Closing UDPC stream: {id}")
|
await self._telnet.close_udpc_stream(id)
|
await self._telnet.write_udpc_stream(self._jpp_host, self._udpc_port)
|
# Save is not recommended https://github.com/snicker/juicepassproxy/issues/96
|
# await self._telnet.save_udpc()
|
_LOGGER.info("UDPC IP Changed")
|
except ConnectionResetError as e:
|
_LOGGER.warning(
|
"Telnet connection to JuiceBox lost. "
|
"Nothing to worry about unless this happens a lot. "
|
f"({e.__class__.__qualname__}: {e})"
|
)
|
await self._add_error()
|
await self._telnet.close()
|
self._telnet = None
|
sleep_interval = 3
|
except TimeoutError as e:
|
_LOGGER.warning(
|
"Telnet connection to JuiceBox has timed out. "
|
"Nothing to worry about unless this happens a lot. "
|
f"({e.__class__.__qualname__}: {e})"
|
)
|
await self._add_error()
|
await self._telnet.close()
|
self._telnet = None
|
sleep_interval = 3
|
except OSError as e:
|
_LOGGER.warning(
|
"Could not route Telnet connection to JuiceBox. "
|
"Nothing to worry about unless this happens a lot. "
|
f"({e.__class__.__qualname__}: {e})"
|
)
|
await self._add_error()
|
await self._telnet.close()
|
self._telnet = None
|
sleep_interval = 3
|
return sleep_interval
|
async def _add_error(self):
|
self._error_timestamp_list.append(time.time())
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.