class TestParseZigBeeIOData(unittest.TestCase): """ Test parsing ZigBee specific IO data """ def setUp(self): self.zigbee = ZigBee(None) def test_parse_dio_adc(self): data = b"\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06" expected_results = [{"dio-11": True, "adc-1": 0, "adc-2": 592, "adc-3": 518}] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results) def test_parse_dio_adc_supply_voltage_not_clamped(self): """ When bit 7 on the ADC mask is set, the supply voltage is included in the ADC I/O sample section. This sample may exceed 10 bits of precision, even though all other ADC channels are limited to a range of 0-1.2v with 10 bits of precision. I assume that a voltage divider and the firmware is used internally to compute the actual Vcc voltage. Therefore, the I/O sampling routine must not clamp this ADC channel to 10 bits of precision. """ data = b"\x01\x00\x00\x80\x0D\x18" expected_results = [{"adc-7": 0xD18}] # import pdb # pdb.set_trace() results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results)
class TestParseZigBeeIOData(unittest.TestCase): """ Test parsing ZigBee specific IO data """ def setUp(self): self.zigbee = ZigBee(None) def test_parse_dio_adc(self): data = b'\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06' expected_results = [{'dio-11': True, 'adc-1': 0, 'adc-2': 592, 'adc-3': 518}] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results) def test_parse_samples_ticket_44(self): """ This example is from ticket 44 on Google Code: https://code.google.com/p/python-xbee/issues/detail?id=44 The author claims the given data is generated by an Xbee Pro 900HP module, but I could only find a definition for packet with a response type of 0x92 in the XBee ZB specification. """ data = (b'\x01' + # Number of samples b'\x10\x00' + # Digital I/O mask (CD/DIO12 enabled) b'\x0E' + # ADC 1,2,3 enabled b'\x10\x00' + # DIO12 is high b'\x03\xA4' + # ADC1 = 932 b'\x01\x31' + # ADC2 = 305 b'\x03\x31') # ADC3 = 817 expected_results = [{'dio-12': True, 'adc-1': 932, 'adc-2': 305, 'adc-3': 817}] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results) def test_parse_dio_adc_supply_voltage_not_clamped(self): """ When bit 7 on the ADC mask is set, the supply voltage is included in the ADC I/O sample section. This sample may exceed 10 bits of precision, even though all other ADC channels are limited to a range of 0-1.2v with 10 bits of precision. I assume that a voltage divider and the firmware is used internally to compute the actual Vcc voltage. Therefore, the I/O sampling routine must not clamp this ADC channel to 10 bits of precision. """ data = b'\x01\x00\x00\x80\x0D\x18' expected_results = [{'adc-7':0xD18}] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results)
class TestParseZigBeeIOData(unittest.TestCase): """ Test parsing ZigBee specific IO data """ def setUp(self): self.zigbee = ZigBee(None) def test_parse_dio_adc(self): data = b'\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06' expected_results = [{ 'dio-11': True, 'adc-1': 0, 'adc-2': 592, 'adc-3': 518 }] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results) def test_parse_dio_adc_supply_voltage_not_clamped(self): """ When bit 7 on the ADC mask is set, the supply voltage is included in the ADC I/O sample section. This sample may exceed 10 bits of precision, even though all other ADC channels are limited to a range of 0-1.2v with 10 bits of precision. I assume that a voltage divider and the firmware is used internally to compute the actual Vcc voltage. Therefore, the I/O sampling routine must not clamp this ADC channel to 10 bits of precision. """ data = b'\x01\x00\x00\x80\x0D\x18' expected_results = [{'adc-7': 0xD18}] #import pdb #pdb.set_trace() results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results)
class TestParseZigBeeIOData(unittest.TestCase): """ Test parsing ZigBee specific IO data """ def setUp(self): self.zigbee = ZigBee(None) def test_parse_dio_adc(self): data = b'\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06' expected_results = [{'dio-11': True, 'adc-1': 0, 'adc-2': 592, 'adc-3': 518}] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results)
class TestParseZigBeeIOData(unittest.TestCase): """ Test parsing ZigBee specific IO data """ def setUp(self): self.zigbee = ZigBee(None) def test_parse_dio_adc(self): data = '\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06' expected_results = [{ 'dio-11': True, 'adc-1': 0, 'adc-2': 592, 'adc-3': 518 }] results = self.zigbee._parse_samples(data) self.assertEqual(results, expected_results)