Example #1
0
 def test_parsing(self):
     """Does the Mi TEMP BT data parser works correctly?"""
     poller = MiTempBtPoller(None, MockBackend)
     data = bytes([0x54, 0x3d, 0x32, 0x35, 0x2e, 0x36, 0x20,
                   0x48, 0x3d, 0x32, 0x33, 0x2e, 0x36, 0x00])
     poller._cache = data
     poller._last_read = datetime.now()
     self.assertEqual(poller._parse_data()[MI_TEMPERATURE], 25.6)
     self.assertEqual(poller._parse_data()[MI_HUMIDITY], 23.6)
Example #2
0
 def test_parsing(self):
     """Does the Mi TEMP BT data parser works correctly for positive single digit values? Value: T=2.3 H=3.6"""
     poller = MiTempBtPoller(None, MockBackend)
     data = bytearray(
         [0x54, 0x3d, 0x32, 0x2e, 0x33, 0x20, 0x48, 0x3d, 0x33, 0x2e,
          0x36]).decode("utf-8").strip(' \n\t')
     poller._cache = data
     poller._last_read = datetime.now()
     self.assertEqual(poller._parse_data()[MI_TEMPERATURE], 2.3)
     self.assertEqual(poller._parse_data()[MI_HUMIDITY], 3.6)
Example #3
0
 def test_parsing5(self):
     """Does the Mi TEMP BT data parser works correctly with spurious binary data? Value: T=-11.3 H=53.0\x02"""
     poller = MiTempBtPoller(None, MockBackend)
     data = bytearray([
         0x54, 0x3d, 0x2d, 0x31, 0x31, 0x2e, 0x33, 0x20, 0x48, 0x3d, 0x35,
         0x33, 0x2e, 0x30, 0x02
     ]).decode("utf-8").strip(' \n\t')
     poller._cache = data
     poller._last_read = datetime.now()
     self.assertEqual(poller._parse_data()[MI_TEMPERATURE], -11.3)
     self.assertEqual(poller._parse_data()[MI_HUMIDITY], 53.0)