Beispiel #1
0
    def FetchDmx(self, universe, callback):
        """Fetch DMX data from the server

    Args:
      universe: the universe to fetch the data for
      callback: The function to call once complete, takes three arguments, a
        RequestStatus object, a universe number and a list of dmx data.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.UniverseRequest()
        request.universe = universe
        done = lambda x, y: self._GetDmxComplete(callback, x, y)
        try:
            self._stub.GetDmx(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
Beispiel #2
0
    def FetchDevices(self, callback, plugin_filter=Plugin.OLA_PLUGIN_ALL):
        """Fetch a list of devices from the server.

    Args:
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a list of Device objects.
      filter: a plugin id to filter by

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.DeviceInfoRequest()
        request.plugin_id = plugin_filter
        done = lambda x, y: self._DeviceInfoComplete(callback, x, y)
        try:
            self._stub.GetDeviceInfo(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
Beispiel #3
0
    def PluginDescription(self, callback, plugin_id):
        """Fetch the description of a plugin.

    Args:
      callback: the function to call once complete, takes two arguments, a
        RequestStatus object and the plugin description text.
      plugin_id: the id of the plugin

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.PluginDescriptionRequest()
        request.plugin_id = plugin_id
        done = lambda x, y: self._PluginDescriptionComplete(callback, x, y)
        try:
            self._stub.GetPluginDescription(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
Beispiel #4
0
 def _RDMMessage(self,
                 universe,
                 uid,
                 sub_device,
                 param_id,
                 callback,
                 data,
                 set=False):
     controller = SimpleRpcController()
     request = Ola_pb2.RDMRequest()
     request.universe = universe
     request.uid.esta_id = uid.manufacturer_id
     request.uid.device_id = uid.device_id
     request.sub_device = sub_device
     request.param_id = param_id
     request.data = data
     request.is_set = set
     done = lambda x, y: self._RDMCommandComplete(callback, x, y)
     try:
         self._stub.RDMCommand(controller, request, done)
     except socket.error:
         raise OLADNotRunningException()
     return True
Beispiel #5
0
    def FetchUIDList(self, universe, callback):
        """Used to get a list of UIDs for a particular universe.

    Args:
      universe: The universe to get the UID list for.
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a iterable of UIDs.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.UniverseRequest()
        request.universe = universe
        done = lambda x, y: self._FetchUIDsComplete(callback, x, y)
        try:
            self._stub.GetUIDs(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
Beispiel #6
0
    def PatchPort(self,
                  device_alias,
                  port,
                  is_output,
                  action,
                  universe,
                  callback=None):
        """Patch a port to a universe.

    Args:
      device_alias: the alias of the device of which to patch a port
      port: the id of the port
      is_output: select the input or output port
      action: OlaClient.PATCH or OlaClient.UNPATCH
      universe: the universe to set the name of
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.PatchPortRequest()
        request.device_alias = device_alias
        request.port_id = port
        request.action = action
        request.is_output = is_output
        request.universe = universe
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        try:
            self._stub.PatchPort(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
Beispiel #7
0
  def RegisterUniverse(self, universe, action,
                       data_callback=None, callback=None):
    """Register to receive dmx updates for a universe.

    Args:
      universe: the universe to register to
      action: OlaClient.REGISTER or OlaClient.UNREGISTER
      data_callback: the function to be called when there is new data, passed
        a single argument of type array.
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """

    if data_callback is None and action == self.REGISTER:
      raise TypeError("data_callback is None and action is REGISTER")

    if self._socket is None:
      return False

    controller = SimpleRpcController()
    request = Ola_pb2.RegisterDmxRequest()
    request.universe = universe
    request.action = action
    try:
      self._stub.RegisterForDmx(
          controller, request,
          lambda x, y: self._AckMessageComplete(callback, x, y))
    except socket.error:
      raise OLADNotRunningException()
    if action == self.REGISTER:
      self._universe_callbacks[universe] = data_callback
    elif universe in self._universe_callbacks:
      del self._universe_callbacks[universe]
    return True