Esempio n. 1
0
 def test_byte_construction_with_header_single_data_byte_invalid_checksum(
         self):
     with self.assertRaises(ValueError):
         Packet([
             0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
             REMOTE_CONTROL, 1, ON, 2, 43
         ])
Esempio n. 2
0
 def test_byte_construction_with_header_multiple_data_bytes_invalid_checksum(
         self):
     with self.assertRaises(ValueError):
         Packet([
             0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
             PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 211
         ])
Esempio n. 3
0
 def test_kv_construction_multiple_data_bytes(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, PUMP_PROGRAM)
     self.assertEqual(packet.data_length, 4)
     self.assertEqual(packet.data, [SET, RPM, 5, 220])
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM,
         4, SET, RPM, 5, 220, 2, 210
     ])
Esempio n. 4
0
 def test_byte_construction_no_header_single_data_byte_valid_checksum(self):
     packet = Packet([DST, SRC, REMOTE_CONTROL, 1, ON, 2, 42])
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, REMOTE_CONTROL)
     self.assertEqual(packet.data_length, 1)
     self.assertEqual(packet.data, [ON])
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
         REMOTE_CONTROL, 1, ON, 2, 42
     ])
Esempio n. 5
0
 def test_byte_construction_no_header_multiple_data_bytes_no_checksum(self):
     packet = Packet([DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220])
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, PUMP_PROGRAM)
     self.assertEqual(packet.data_length, 4)
     self.assertEqual(packet.data, [SET, RPM, 5, 220])
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM,
         4, SET, RPM, 5, 220, 2, 210
     ])
Esempio n. 6
0
 def test_kv_construction_no_data(self):
     packet = Packet(dst=DST, action=GET_PUMP_STATUS)
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, GET_PUMP_STATUS)
     self.assertEqual(packet.data_length, 0)
     self.assertEqual(packet.data, None)
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
         GET_PUMP_STATUS, 0, 1, 45
     ])
Esempio n. 7
0
 def test_kv_construction_single_data_byte_list(self):
     packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON])
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, REMOTE_CONTROL)
     self.assertEqual(packet.data_length, 1)
     self.assertEqual(packet.data, [ON])
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
         REMOTE_CONTROL, 1, ON, 2, 42
     ])
Esempio n. 8
0
 def test_byte_construction_no_header_no_data_valid_checksum(self):
     packet = Packet([DST, SRC, GET_PUMP_STATUS, 0, 1, 45])
     self.assertEqual(packet.dst, DST)
     self.assertEqual(packet.src, SRC)
     self.assertEqual(packet.action, GET_PUMP_STATUS)
     self.assertEqual(packet.data_length, 0)
     self.assertEqual(packet.data, None)
     self.assertEqual(packet.bytes, [
         0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
         GET_PUMP_STATUS, 0, 1, 45
     ])
Esempio n. 9
0
 def test_data_length_with_multiple_data_bytes(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.data_length, 4)
Esempio n. 10
0
 def test_byte_construction_no_header_single_data_byte_invalid_checksum(
         self):
     with self.assertRaises(ValueError):
         Packet([DST, SRC, REMOTE_CONTROL, 1, ON, 2, 43])
Esempio n. 11
0
 def test_byte_construction_with_header_no_data_invalid_checksum(self):
     with self.assertRaises(ValueError):
         Packet([
             0xFF, 0x00, 0xFF, PAYLOAD_HEADER, VERSION, DST, SRC,
             GET_PUMP_STATUS, 0, 1, 46
         ])
Esempio n. 12
0
 def test_byte_construction_no_header_no_data_invalid_checksum(self):
     with self.assertRaises(ValueError):
         Packet([DST, SRC, GET_PUMP_STATUS, 0, 1, 46])
Esempio n. 13
0
 def test_payload_with_single_data_byte_list(self):
     packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON])
     self.assertEqual(
         packet.payload,
         [PAYLOAD_HEADER, VERSION, DST, SRC, REMOTE_CONTROL, 1, ON])
Esempio n. 14
0
 def test_data_length_with_single_data_byte_list(self):
     packet = Packet(dst=DST, action=REMOTE_CONTROL, data=[ON])
     self.assertEqual(packet.data_length, 1)
Esempio n. 15
0
 def test_checksum(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.checksum, 2 * 256 + 210)
Esempio n. 16
0
 def test_checkbytes(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.checkbytes, [2, 210])
Esempio n. 17
0
 def test_payload_with_multiple_data_bytes(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.payload, [
         PAYLOAD_HEADER, VERSION, DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5,
         220
     ])
Esempio n. 18
0
 def test_byte_construction_no_header_multiple_data_bytes_invalid_checksum(
         self):
     with self.assertRaises(ValueError):
         Packet([DST, SRC, PUMP_PROGRAM, 4, SET, RPM, 5, 220, 2, 211])
Esempio n. 19
0
 def test_data_length_with_no_data(self):
     packet = Packet(dst=DST, action=GET_PUMP_STATUS)
     self.assertEqual(packet.data_length, 0)
Esempio n. 20
0
 def test_payload_with_no_data(self):
     packet = Packet(dst=DST, action=GET_PUMP_STATUS)
     self.assertEqual(
         packet.payload,
         [PAYLOAD_HEADER, VERSION, DST, SRC, GET_PUMP_STATUS, 0])