def enable(self, brightness: float) -> Any:
        """
        Create a LedCommand to be send to the simulator with the given address of the led to
        be turned on and the brightness to run at.
        """

        command = LedCommand(self.address, brightness)
        return self.client_socket.send_command(command)
    def _process_led_command(self, d: dict) -> Any:
        """
        Deserialize the given dictionary into a LedCommand and send it to the MessageProcessor.
        :param d: to process.
        """

        command = LedCommand(d['address'], d['brightness'])
        self.message_processor.process_led_command(command)

        return None
Example #3
0
    def test_process_right_led_command(self):
        robot_state = RobotState()
        message_processor = MessageProcessor('right_brick', robot_state)

        command1 = LedCommand('led0:red:brick-status', 1)
        command2 = LedCommand('led0:green:brick-status', 1)

        message_processor.process_led_command(command1)
        message_processor.process_led_command(command2)

        self.assertEqual(robot_state.right_brick_left_led_color, 0)
        self.assertEqual(robot_state.right_brick_right_led_color, 1)

        command3 = LedCommand('led1:red:brick-status', 1)
        command4 = LedCommand('led1:green:brick-status', 0.5)

        message_processor.process_led_command(command3)
        message_processor.process_led_command(command4)

        self.assertEqual(robot_state.right_brick_left_led_color, 0)
        self.assertEqual(robot_state.right_brick_right_led_color, 4)
Example #4
0
    def test_process_led_command(self):
        robot_sim = create_robot_sim()
        message_processor = MessageProcessor(0, robot_sim)

        command1 = LedCommand('led0:red:brick-status', 1)
        command2 = LedCommand('led0:green:brick-status', 1)

        message_processor.process_led_command(command1)
        message_processor.process_led_command(command2)

        self.assertEqual(robot_sim.robot.led_colors[(0, 'led0')], 0)
        self.assertEqual(robot_sim.robot.led_colors[(0, 'led1')], 1)

        command3 = LedCommand('led1:red:brick-status', 1)
        command4 = LedCommand('led1:green:brick-status', 0.5)

        message_processor.process_led_command(command3)
        message_processor.process_led_command(command4)

        self.assertEqual(robot_sim.robot.led_colors[(0, 'led0')], 0)
        self.assertEqual(robot_sim.robot.led_colors[(0, 'led1')], 4)