diff --git a/aioraven/data.py b/aioraven/data.py index 8451af1..49f7366 100644 --- a/aioraven/data.py +++ b/aioraven/data.py @@ -58,7 +58,7 @@ def convert_date(raw: Optional[str]) -> Optional[date]: def convert_date_code(raw: Optional[str]) -> Optional[Tuple[date, str]]: - if raw is not None: + if raw is not None and not all(ch == '\xff' for ch in raw): if len(raw) >= 9: date = convert_date(raw[:8]) if date is not None: diff --git a/aioraven/protocols.py b/aioraven/protocols.py index cee7d9e..9734ed4 100644 --- a/aioraven/protocols.py +++ b/aioraven/protocols.py @@ -43,9 +43,10 @@ def __init__( self._closed = self._loop.create_future() def _reset(self) -> None: - self._parser = Et.XMLPullParser(events=('end',)) - self._parser.feed(b'') self._stash = b'' + self._parser = Et.XMLPullParser(events=('end',)) + self._parser.feed( + b'') def _get_close_waiter(self, stream: Any) -> Future[None]: return self._closed diff --git a/test/test_data.py b/test/test_data.py index 6a7c075..0904343 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -352,6 +352,44 @@ async def test_get_device_info(): date_code=(date(2022, 1, 1), 'a0000042')) +@pytest.mark.asyncio +async def test_get_device_info_date_code_filler(): + """ + Verify behavior of the ``get_device_info`` command with a filler value for + date_code. + """ + responses = { + b'get_device_info': + b'' + b' 0x0123456789ABCDEF' + b' 0xABCDEF0123456789' + b' 0xABCDEF0123456789ABCDEF0123456789' + b' 1.21g' + b' 5.55 rev 2' + b' Mocked' + b' aioraven' + b' Python' + b' \xff\xff\xff\xff\xff\xff\xff\xff' + b'\xff\xff\xff\xff\xff\xff\xff\xff' + b'', + } + + async with mock_device(responses) as (host, port): + async with RAVEnNetworkDevice(host, port) as dut: + actual = await dut.get_device_info() + + assert actual == DeviceInfo( + device_mac_id=bytes.fromhex('0123456789ABCDEF'), + install_code=bytes.fromhex('ABCDEF0123456789'), + link_key=bytes.fromhex('ABCDEF0123456789ABCDEF0123456789'), + fw_version='1.21g', + hw_version='5.55 rev 2', + image_type='Mocked', + manufacturer='aioraven', + model_id='Python', + date_code=None) + + @pytest.mark.asyncio async def test_get_instantaneous_demand(): """Verify behavior of the ``get_instantaneous_demand`` command."""