diff options
-rw-r--r-- | glucometerutils/support/freestyle.py | 2 | ||||
-rw-r--r-- | test/test_freestyle.py | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index 1c5e284..816af81 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -28,7 +28,7 @@ from glucometerutils.support import hiddevice _INIT_SEQUENCE = (0x04, 0x05, 0x15, 0x01) _FREESTYLE_MESSAGE = construct.Struct( - 'hid_report' / construct.Const(construct.Byte, 0), + 'hid_report' / construct.Const(0, construct.Byte), 'message_type' / construct.Byte, 'command' / construct.Padded( 63, # command can only be up to 62 bytes, but one is used for length. diff --git a/test/test_freestyle.py b/test/test_freestyle.py new file mode 100644 index 0000000..0ff669d --- /dev/null +++ b/test/test_freestyle.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# +# SPDX-License-Identifier: MIT +"""Tests for the common FreeStyle functions..""" + +# pylint: disable=protected-access,missing-docstring + +from absl.testing import absltest + +from glucometerutils.support import freestyle + + +class TestFreeStyle(absltest.TestCase): + + def test_outgoing_command(self): + """Test the generation of a new outgoing message.""" + + self.assertEqual( + b'\0\x17\7command\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' + b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', + freestyle._FREESTYLE_MESSAGE.build( + {'message_type': 23, 'command': b'command'}), + ) |