Пример #1
0
    def SetParameter(self, request: SetParameterRequest, context: Any) -> None:
        """
        Sends a SetParameterValues message. Used for testing only.

        Different data models will have different names for the same
        parameter. Whatever name that the data model uses, we call the
        'parameter path', eg. "Device.DeviceInfo.X_BAICELLS_COM_GPS_Status"
        We denote 'ParameterName' to be a standard string name for
        equivalent parameters between different data models
        """
        # Parse the request
        if request.HasField('value_int'):
            value = (request.value_int, 'int')
        elif request.HasField('value_bool'):
            value = (request.value_bool, 'boolean')
        elif request.HasField('value_string'):
            value = (request.value_string, 'string')
        else:
            context.set_details('SetParameter: Unsupported type %d',
                                request.type)
            context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            return

        # Update the handler so it will set the parameter value
        parameter_path = request.parameter_name
        handler = self._get_handler(request.device_serial)
        data_model = handler.data_model
        param_name = data_model.get_parameter_name_from_path(parameter_path)
        handler.set_parameter_asap(param_name, value)
Пример #2
0
def set_parameter(client, args):
    message = SetParameterRequest()
    message.device_serial = args.device_serial
    message.parameter_name = args.parameter_name
    if args.data_type == 'bool':
        if args.value.lower() == 'true':
            message.value_bool = True
        elif args.value.lower() == 'false':
            message.value_bool = False
        else:
            raise TypeError("Bool values should be True or False")
    elif args.data_type == 'string':
        message.value_string = str(args.value)
    elif args.data_type == 'int':
        message.value_int = int(args.value)
    else:
        raise TypeError('Unknown type %s' % args.data_type)
    client.SetParameter(message)