Example #1
0
	def test_get_payload_empty(self):
		msg = SetProgramMessage('122b65', 1, 1, [])

		b64payload = msg.to_bytes()[2:]
		data = base64.b64decode(b64payload)

		expected = bytearray([
			0x00, 0x04, 0x10, 0x00, 0x00, 0x00, # base string
			0x12, 0x2b, 0x65, # rf addr
			0x01, # room
			0x03, # weekday (*cube* weekday)
		])
		self.assertEqual(data, expected)
Example #2
0
	def test_get_payload_one(self):
		msg = SetProgramMessage('122b65', 1, 6, [
			ProgramSchedule(16, 0, datetime.time(6, 5))
		])

		b64payload = msg.to_bytes()[2:]
		data = base64.b64decode(b64payload)

		expected = bytearray([
			0x00, 0x04, 0x10, 0x00, 0x00, 0x00, # base string
			0x12, 0x2b, 0x65, # rf addr
			0x01, # room
			0x01, # weekday (*cube* weekday)
			0x40, 0x49,
		])
		self.assertEqual(data, expected)
Example #3
0
    def test_set_program_same_payload(self):
        c = self._mocked_cube()
        rfaddr = RFAddr('122b56')

        response1 = c.set_program(1, rfaddr, 1, [])
        setmessage1 = SetProgramMessage(rfaddr, 1, 1, [])
        payload1 = setmessage1.get_payload()
        c.send_message.assert_called_with(setmessage1)
        self.assertIsInstance(response1, SetResponse)

        response2 = c.set_program(1, '122b56', 1, [])
        setmessage2 = SetProgramMessage('122b56', 1, 1, [])
        payload2 = setmessage1.get_payload()
        c.send_message.assert_called_with(setmessage2)
        self.assertIsInstance(response2, SetResponse)

        self.assertEqual(payload1, payload2)
Example #4
0
    def test_set_program_with_rfaddr(self):
        c = self._mocked_cube()
        rfaddr = RFAddr('122b56')
        response = c.set_program(1, rfaddr, 1, [])
        setmessage = SetProgramMessage(rfaddr, 1, 1, [])
        c.send_message.assert_called_with(setmessage)

        self.assertIsInstance(response, SetResponse)
Example #5
0
	def test_stupid_payload(self):
		expected = bytearray([int(x, 16) for x in "00 04 10 00 00 00 12 2b 65 01 02 40 49 4c 6e 40 cb 4d 20".split()])
		#                                             base string | rf addr |r| d  |s1   |s2   |s3   |s4
		msg = SetProgramMessage('122b65', 1, 0, [
			ProgramSchedule(16, datetime.time(), datetime.time(6, 5)),
			ProgramSchedule(19, datetime.time(6, 5), datetime.time(9, 10)),
			ProgramSchedule(16, datetime.time(9, 10), datetime.time(16, 55)),
			ProgramSchedule(19, datetime.time(16, 55), 1440),
		])
		data = msg.get_payload()

		# print("")
		# print(" ".join(["{0}".format(str(i).rjust(2, ' ')) for i in range(0, max(len(data), len(expected)))]))
		# print(" ".join(["{0:2X}".format(i) for i in bytearray(data)]))
		# print(" ".join(["{0:2X}".format(i) for i in expected]))
		# print("")

		self.assertEqual(data, expected)
Example #6
0
    def test_get_payload_empty(self):
        msg = SetProgramMessage('122b65', 1, 1, [])

        b64payload = msg.to_bytes()[2:]
        data = base64.b64decode(b64payload)

        expected = bytearray([
            0x00,
            0x04,
            0x10,
            0x00,
            0x00,
            0x00,  # base string
            0x12,
            0x2b,
            0x65,  # rf addr
            0x01,  # room
            0x03,  # weekday (*cube* weekday)
        ])
        self.assertEqual(data, expected)
Example #7
0
    def test_stupid_payload(self):
        expected = bytearray([
            int(x, 16) for x in
            "00 04 10 00 00 00 12 2b 65 01 02 40 49 4c 6e 40 cb 4d 20".split()
        ])
        #                                             base string | rf addr |r| d  |s1   |s2   |s3   |s4
        msg = SetProgramMessage('122b65', 1, 0, [
            ProgramSchedule(16, datetime.time(), datetime.time(6, 5)),
            ProgramSchedule(19, datetime.time(6, 5), datetime.time(9, 10)),
            ProgramSchedule(16, datetime.time(9, 10), datetime.time(16, 55)),
            ProgramSchedule(19, datetime.time(16, 55), 1440),
        ])
        data = msg.get_payload()

        # print("")
        # print(" ".join(["{0}".format(str(i).rjust(2, ' ')) for i in range(0, max(len(data), len(expected)))]))
        # print(" ".join(["{0:2X}".format(i) for i in bytearray(data)]))
        # print(" ".join(["{0:2X}".format(i) for i in expected]))
        # print("")

        self.assertEqual(data, expected)
Example #8
0
    def test_get_payload_one(self):
        msg = SetProgramMessage('122b65', 1, 6,
                                [ProgramSchedule(16, 0, datetime.time(6, 5))])

        b64payload = msg.to_bytes()[2:]
        data = base64.b64decode(b64payload)

        expected = bytearray([
            0x00,
            0x04,
            0x10,
            0x00,
            0x00,
            0x00,  # base string
            0x12,
            0x2b,
            0x65,  # rf addr
            0x01,  # room
            0x01,  # weekday (*cube* weekday)
            0x40,
            0x49,
        ])
        self.assertEqual(data, expected)
Example #9
0
 def test_constructor_empty_schedule(self):
     msg = SetProgramMessage('foo', 1, 1, [])
     self.assertEqual(msg.program, [])
Example #10
0
 def test_set_program(self):
     c = self._mocked_cube()
     response = c.set_program(1, '122b56', 1, [])
     c.send_message.assert_called_with(SetProgramMessage(
         '122b56', 1, 1, []))
     self.assertIsInstance(response, SetResponse)
Example #11
0
 def set_program(self, room, rf_addr, weekday, program):
     self.send_message(SetProgramMessage(rf_addr, room, weekday, program))
     return self.get_message(SET_RESPONSE)