Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command retry on connection lost #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions anthemav/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, update_callback=None, loop=None, connection_lost_callback=Non
self._input_numbers = {}
self._poweron_refresh_successful = False
self.transport = None
self._resend_action = {}

for key in LOOKUP:
setattr(self, '_'+key, '')
Expand Down Expand Up @@ -165,9 +166,13 @@ def connection_made(self, transport):

self.command('ECH1')
self.refresh_core()
if self._resend_action:
for k, v in self._resend_action.items():
self._set_boolean(k, v)

def data_received(self, data):
"""Called when asyncio.Protocol detects received data from network."""
self._resend_action = {}
self.buffer += data.decode()
self.log.debug('Received %d bytes from AVR: %s', len(self.buffer), self.buffer)
self._assemble_buffer()
Expand Down Expand Up @@ -503,6 +508,7 @@ def _get_boolean(self, key):
return False

def _set_boolean(self, key, value):
self._resend_action = {key: value}
if value is True:
self.command(key+'1')
else:
Expand Down