Skip to content

Commit

Permalink
Merge pull request #12 from hostcc/bugfix/base-command-excessive-packet
Browse files Browse the repository at this point in the history
Ignore excessive packets upon retrying a command
  • Loading branch information
hostcc authored Feb 7, 2022
2 parents 0728ae8 + 475b93e commit a4dedbe
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/pyg90alarm/base_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
import logging
import json
import asyncio
# Python 3.6 has `InvalidStateError` under `asyncio.base_futures` while later
# version have it under `asyncio.expcetions`
try:
from asyncio.exceptions import InvalidStateError # pylint:disable=E1101
except ImportError:
from asyncio.base_futures import InvalidStateError
from typing import NamedTuple, Optional
from .exceptions import (G90Error, G90TimeoutError)

Expand Down Expand Up @@ -90,19 +84,19 @@ def datagram_received(self, data, addr):
"""
tbd
"""
if asyncio.isfuture(self._data) and not self._data.cancelled():
try:
self._data.set_result((*addr, data))
except InvalidStateError as exc:
_LOGGER.error('Wrong state of the future %s: %s',
repr(self._data), exc)
raise exc
if asyncio.isfuture(self._data):
if self._data.done():
_LOGGER.warning('Excessive packet received'
' from %s:%s: %s',
addr[0], addr[1], data)
return
self._data.set_result((*addr, data))

def error_received(self, exc):
"""
tbd
"""
if asyncio.isfuture(self._data) and not self._data.cancelled():
if asyncio.isfuture(self._data) and not self._data.done():
self._data.set_exception(exc)


Expand Down

0 comments on commit a4dedbe

Please sign in to comment.