Beispiel #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
         ])
Beispiel #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
         ])
Beispiel #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
     ])
Beispiel #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
     ])
Beispiel #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
     ])
Beispiel #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
     ])
Beispiel #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
     ])
Beispiel #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
     ])
Beispiel #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)
Beispiel #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])
Beispiel #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
         ])
Beispiel #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])
Beispiel #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])
Beispiel #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)
Beispiel #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)
Beispiel #16
0
 def test_checkbytes(self):
     packet = Packet(dst=DST, action=PUMP_PROGRAM, data=[SET, RPM, 5, 220])
     self.assertEqual(packet.checkbytes, [2, 210])
Beispiel #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
     ])
Beispiel #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])
Beispiel #19
0
 def test_data_length_with_no_data(self):
     packet = Packet(dst=DST, action=GET_PUMP_STATUS)
     self.assertEqual(packet.data_length, 0)
Beispiel #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])