Esempio n. 1
0
 def test_set_text(self):
     """Test set_text method."""
     mock_text = "abcd"
     self.display.text = mock_text
     clear_message = parse_message(0x04, 21, -1, (0, 0))
     text_message = parse_message(0x04, 17, -1,
                                  parse_data(mock_text + '\0', 'string'))
     self.assertEqual(self.conn.send_list[0], clear_message)
     self.assertEqual(self.conn.send_list[1], text_message)
Esempio n. 2
0
 def test_set_text(self):
     """Test set_text method."""
     mock_text = "abcd"
     self.display.text = mock_text
     clear_message = parse_message(0x04, 21, -1, (0, 0))
     text_message = parse_message(0x04, 17, -1,
                                  parse_data(mock_text, 'string'))
     self.assertEqual(self.send_q.get(), clear_message)
     self.assertEqual(self.send_q.get(), text_message)
Esempio n. 3
0
 def test_set_motor_channel(self):
     """Test set_motor_channel method"""
     expected_values = motor_channel, control_mode, control_value = 0, 0, 50
     self.motor.set_motor_channel(*expected_values)
     self.assertEqual(
         self.send_q.get_nowait(),
         parse_message(0x04, 19, -1, parse_data(
             (motor_channel, control_mode, control_value), 'int'))
     )
Esempio n. 4
0
 def test_show_variable(self):
     """Test set_variable method."""
     mock_variable = 123
     mock_position = 5
     self.display.show_variable(mock_variable, mock_position, mock_position)
     self.assertEqual(
         self.send_q.get(),
         parse_message(
             0x04, 22, -1,
             parse_data((mock_variable, mock_position, mock_position),
                        'display_var')))
Esempio n. 5
0
 def test_set_rgb(self):
     """Test set_rgb method with user-defined inputs."""
     expected_color = (10, 20, 255)
     self.led.rgb = expected_color
     set_message = parse_message(
         0x04, 16, -1, parse_data(self.to_true_color(expected_color),
                                  'int'))
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(set_message in sent_messages)
Esempio n. 6
0
 def test_on(self):
     """Test on method."""
     expected_color = (255, 255, 255)
     self.led.rgb = expected_color
     set_message = parse_message(
         0x04, 16, -1, parse_data(self.to_true_color(expected_color),
                                  'int'))
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(set_message in sent_messages)
Esempio n. 7
0
 def test_set_green(self):
     """Test set_green method."""
     expected_color = (0, 20, 0)
     set_message = parse_message(
         0x04, 16, -1, parse_data(self.to_true_color(expected_color),
                                  'int'))
     sent_messages = []
     self.led.green = 20
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(set_message in sent_messages)
Esempio n. 8
0
 def test_set_speed(self):
     """Test set_speed method."""
     expected_values = first_speed_value, second_speed_value = 50, 50
     self.motor.speed = expected_values
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.FIRST_SPEED, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.SECOND_SPEED, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 0, 1, first_speed_value), 'int')) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 1, 1, second_speed_value), 'int')) in sent_messages)
Esempio n. 9
0
 def test_set_degree(self):
     """Test set_degree method."""
     expected_values = first_degree_value, second_degree_value = 50, 50
     self.motor.degree = expected_values
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.FIRST_DEGREE, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.SECOND_DEGREE, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 0, 2, first_degree_value), 'int')) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 1, 2, second_degree_value), 'int')) in sent_messages)
Esempio n. 10
0
 def test_set_torque(self):
     """Test set_torque method."""
     expected_values = first_torque_value, second_torque_value = 50, 50
     self.motor.torque = expected_values
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(
         Motor.request_property(
             -1, Motor.PropertyType.FIRST_TORQUE) in sent_messages)
     self.assertTrue(
         Motor.request_property(
             -1, Motor.PropertyType.SECOND_TORQUE) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 19, -1, parse_data(
             (0, 0, first_torque_value), 'int'
         )) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 19, -1, parse_data(
             (1, 0, second_torque_value), 'int'
         )) in sent_messages)
Esempio n. 11
0
 def test_set_second_degree(self):
     """Test set_second_degree method."""
     second_degree_value = 50
     self.motor.second_degree = second_degree_value
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(
         Motor.request_property(
             -1, Motor.PropertyType.SECOND_DEGREE) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 19, -1, parse_data(
             (1, 2, second_degree_value), 'int'
         )) in sent_messages)
Esempio n. 12
0
 def test_set_first_speed(self):
     """Test set_first_speed method."""
     first_speed_value = 50
     self.motor.first_speed = first_speed_value
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(
         Motor.request_property(
             -1, Motor.PropertyType.FIRST_SPEED) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 19, -1, parse_data(
             (0, 1, first_speed_value), 'int'
         )) in sent_messages)
Esempio n. 13
0
 def test_set_second_torque(self):
     """Test set_second_torque method."""
     second_torque_value = 50
     self.motor.second_torque = second_torque_value
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.SECOND_TORQUE, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 16, -1, parse_data((
                 0, second_torque_value), 'int')) in sent_messages)
Esempio n. 14
0
 def test_set_first_torque(self):
     """Test set_first_torque method."""
     first_torque_value = 50
     self.motor.first_torque = first_torque_value
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.FIRST_TORQUE, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 16, -1,
                       parse_data((first_torque_value,
                                   0), 'int')) in sent_messages)
Esempio n. 15
0
    def __parse_set_message(destination_id: int, property_type: int,
                            property_values: Tuple,
                            property_data_type: int) -> List[str]:
        """Generate set_property json serialized message

        :param destination_id: Id of the destination module
        :type destination_id: int
        :param property_type: Property Type
        :type property_type: int
        :param property_values: Property values
        :type property_values: Tuple
        :param property_data_type: Property Data Type
        :type property_data_type: int
        :return: List of json messages
        :rtype: List[str]
        """
        data_list = []
        if property_data_type == OutputModule.INT:
            data_list.append(parse_data(property_values, 'int'))
        elif property_data_type == OutputModule.FLOAT:
            data_list.append(parse_data(property_values, 'float'))
        elif property_data_type == OutputModule.STRING:
            for i in range(0, len(property_values), 8):
                chunk = str(property_values)[i:i + 8]
                data_list.append(parse_data(chunk, 'string'))
        elif property_data_type == OutputModule.RAW:
            data_list.append(parse_data(property_values, 'raw'))
        elif property_data_type == OutputModule.DISPLAY_VAR:
            data_list.append(parse_data(property_values, 'display_var'))
        else:
            raise RuntimeError("Not supported property data type.")

        messages = []
        for data in data_list:
            messages.append(
                parse_message(0x04, property_type, destination_id, data))
        return messages
Esempio n. 16
0
 def test_set_second_degree(self):
     """Test set_second_degree method."""
     second_degree_value = 50
     self.motor.second_degree = second_degree_value
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.SECOND_DEGREE, None,
                                     self.motor.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 1, 2, second_degree_value), 'int')) in sent_messages)
Esempio n. 17
0
 def test_set_first_speed(self):
     """Test set_first_speed method."""
     first_speed_value = 50
     self.motor.first_speed = first_speed_value
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.FIRST_SPEED, None,
                                     self.motor.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 19, -1, parse_data((
                 0, 1, first_speed_value), 'int')) in sent_messages)
Esempio n. 18
0
 def test_set_green(self):
     """Test set_green method."""
     expected_color = (0, 20, 0)
     set_message = parse_message(0x04, 16, -1, parse_data(
         expected_color, 'int'))
     sent_messages = []
     self.led.green = 20
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.RED) in sent_messages)
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.GREEN) in sent_messages)
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.BLUE) in sent_messages)
     self.assertTrue(set_message in sent_messages)
Esempio n. 19
0
 def test_set_rgb(self):
     """Test set_rgb method with user-defined inputs."""
     expected_color = (10, 100, 200)
     self.led.rgb = expected_color
     set_message = parse_message(0x04, 16, -1, parse_data(
         expected_color, 'int'))
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.RED) in sent_messages)
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.GREEN) in sent_messages)
     self.assertTrue(Led.request_property(
         -1, Led.PropertyType.BLUE) in sent_messages)
     self.assertTrue(set_message in sent_messages)
Esempio n. 20
0
 def test_set_tune(self):
     """Test set_tune method."""
     expected_values = frequency, volume = (500, 30)
     self.speaker.tune = expected_values
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.FREQUENCY, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.VOLUME, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 16, -1, parse_data(expected_values, 'float'))
         in sent_messages)
Esempio n. 21
0
 def test_set_off(self):
     """Test set_off method"""
     expected_values = (0, 0)
     self.speaker.tune = 100, 100
     self.speaker.tune = expected_values
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.FREQUENCY, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.VOLUME, None, 95,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 16, -1, parse_data(expected_values, 'float'))
         in sent_messages)
Esempio n. 22
0
 def test_set_off(self):
     """Test set_off method"""
     expected_values = (0, 0)
     self.speaker.tune = expected_values
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(
         Speaker.request_property(
             -1, Speaker.PropertyType.FREQUENCY) in sent_messages)
     self.assertTrue(
         Speaker.request_property(
             -1, Speaker.PropertyType.VOLUME) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 16, -1, parse_data(
                 expected_values, 'float')) in sent_messages)
Esempio n. 23
0
 def test_set_torque(self):
     """Test set_torque method."""
     expected_values = first_torque_value, second_torque_value = 50, 50
     self.motor.torque = expected_values
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.FIRST_TORQUE, None,
                                     self.motor.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Motor.SECOND_TORQUE, None,
                                     self.motor.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 16, -1, parse_data(expected_values, 'int')) in
         sent_messages)
Esempio n. 24
0
 def test_set_volume(self):
     """Test set_volume method."""
     expected_volume = 50
     expected_values = (1318, 50)
     self.speaker.volume = expected_volume
     sent_messages = []
     while self.conn.send_list:
         sent_messages.append(self.conn.send_list.pop())
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.FREQUENCY, None,
                                     self.speaker.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x03, 0, -1, (Speaker.VOLUME, None,
                                     self.speaker.prop_samp_freq,
                                     None)) in sent_messages)
     self.assertTrue(
         parse_message(0x04, 16, -1, parse_data(expected_values, 'float'))
         in sent_messages)
Esempio n. 25
0
 def test_set_tune(self):
     """Test set_tune method."""
     expected_values = frequency, volume = (
         self.speaker.Scale.F_RA_6.value, 30
     )
     self.speaker.tune = expected_values
     sent_messages = []
     while not self.send_q.empty():
         sent_messages.append(self.send_q.get_nowait())
     self.assertTrue(
         Speaker.request_property(
             -1, Speaker.PropertyType.FREQUENCY) in sent_messages)
     self.assertTrue(
         Speaker.request_property(
             -1, Speaker.PropertyType.VOLUME) in sent_messages)
     self.assertTrue(
         parse_message(
             0x04, 16, -1, parse_data(
                 expected_values, 'float')) in sent_messages)