Skip to content

Commit

Permalink
Merge pull request #41 from bendavis/update/1.064
Browse files Browse the repository at this point in the history
Update to work with fw 1.064
  • Loading branch information
jlvaillant committed Feb 15, 2022
2 parents 810a714 + 429759b commit 40fc347
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async def start(self):
query.append(items)
numAttributes += len(items["keys"])
# a query too large can choke the protocol...
# we split them in maximum of 250 attributes (arbitrary but seems to work)
# we split them in maximum of 50 attributes (arbitrary but seems to work)
if numAttributes >= 50:
res = await self.sendCmd("RequestParamList", {"objectList": query})
self._applyUpdates(res["objectList"])
Expand Down
24 changes: 0 additions & 24 deletions custom_components/intellicenter/pyintellicenter/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def __init__(self, controller):
self._out_pending = 0
self._out_queue = SimpleQueue()

# the coroutine for sending regular 'ping' to IntelliCenter
self._heartbeat = None
# and the number of unacknowledgged ping issued
self._num_unacked_pings = 0

Expand All @@ -52,19 +50,12 @@ def connection_made(self, transport):
self._transport = transport
self._msgID = 1

# start a task to send 'ping' every 30s
self._heartbeat = asyncio.create_task(self.heartbeat())

# and notify our controller that we are ready!
self._controller.connection_made(self, transport)

def connection_lost(self, exc):
"""Handle the callback for connection lost."""

if self._heartbeat:
self._heartbeat.cancel()
self._heartbeat = None

self._controller.connection_lost(exc)

def data_received(self, data) -> None:
Expand Down Expand Up @@ -181,18 +172,3 @@ def processMessage(self, message: str) -> None:

except Exception as err:
_LOGGER.error(f"PROTOCOL: exception while receiving message {err}")

async def heartbeat(self):
"""Send a ping every 10s to keep and check that the connection is alive."""

while self._num_unacked_pings < 2:
# we sleep first as there is no need for an immediate ping upon connection
await asyncio.sleep(10)
_LOGGER.debug("PROTOCOL: sending ping")
self.sendRequest("ping")
self._num_unacked_pings += 1

# if we already have sent 2 pings without a pong
# we assume the connection went dead and abort
_LOGGER.error("PROTOCOL: heartbeat missed, closing connection")
self._transport.close()

0 comments on commit 40fc347

Please sign in to comment.