The manager module

The manager module contains the PluginManager class which encapsulates the functionality of loading and managing a series of plugins. The PluginManager is also responsible for processing the speech rules and object filters for all the loaded plugins.

The BasePlugin class

Inheritance diagram of pysiriproxy.plugins.manager.BasePlugin

class pysiriproxy.plugins.manager.BasePlugin(manager, logger)

The BasePlugin class encapsulates the basic features of a plugin. This class provides the ability to load the set of filter functions, and then process them with a received object and an received direction.

A filter function is created by decorating a class function with either the From_iPhone decorator, or the From_Server decorator. These filters will be processed in the event that an object is received from the given decorated direction. These functions can have any publicly visible name (i.e., do not start with __).

Example:

def Plugin(BasePlugin):
    @From_iPhone
    def exampleFilter(self, obj):
        self.log.debug("This will process all iPhone objects!")

Filter functions can also be created to catch a specific object type by using specific object class decorators. The object class decorators are defined in the objectClasses module.

Example:

def Plugin(BasePlugin):
    @StartRequest
    @From_iPhone
    def exampleFilter(self, obj):
        self.log.debug("This will process iPhone StartRequest objects!")

In the above example, the exampleFilter function will be called in the event that a StartRequest object is received from the iPhone. Custom decorators can be created by calling the objectClasses.createDecorator() function.

Speech rules are created in a similar manner to object filters. Two decorators exist which allow a speech rule function to be called in the event that a given string matches the recognized speech, or if a regular expression matches the recognized speech.

Example:

def Plugin(BasePlugin):
    @matches("Test Siri Proxy")
    def testMatch(self, text):
        print "Matched the recognized speech!"

    @regex(".*Siri Proxy.*")
    def testRegex(self, text):
        print "Matched a regular expression!"

The @matches decorator takes a string which it will compare to the recognized speech. A function using this decorator will be called in the event that the recognized speech matches the given string (it is case insensitive).

The @regex decorator takes a regular expression which will use to match the recognized speech. A function using this decorator will be called in the event that the regular expression matches the recognized speech (it is case insensitive).

Custom speech rule decorators can be created by creating a subclass of the speechRules.Rule class, and then calling the speechRules.createDecorator() function with the speechRules.Rule subclass.

ask(question, spoken=None)

Command Siri to ask the user a question.

  • question – The question to ask
  • spoken – The text Siri will say
completeRequest()

Complete a request to Siri.

Note

This function should always be called by speech rules otherwise Siri will continue to spin.

customCommand(obj, direction)

Create a default object filter for the start request command received from the iPhone. This allows the plugins to define a set of custom command names and map them to specific callback functions.

  • commandName – The name of the object
  • direction – The direction the object traveled to be received
customCommandMap

The customCommandMap property defines a dictionary of custom command names mapped to the concrete plugin class function names that get called when the custom command is received from the iPhone.

getName()

Get the name of this Plugin.

init()

Called after the BasePlugin is created.

Note

This function can be overridden by concrete plugins.

makeView(views)

Create a view and send it to the iPhone user.

  • views – The list of views to create
processFilters(obj, direction)

Process the filters for this Plugin.

Note

This function should return False if the object should be dropped, return None if the object is ignored by this filter, or return the new object corresponding to the response.

  • commandName – The name of the object
  • direction – The direction the object traveled to be received
processSpeechRules(text)

Process all of the speech rules for the recognized speech text.

  • text – The recognized speech text
resetContext()

Reset the context.

say(text, spoken=None)

Command Siri to speak a piece of text.

  • text – The text that Siri will display
  • spoken – The text that Siri will speak
showDirections(directionsType, source, destination, utterance=None)

Create a directions object and display it to the iPhone user.

  • directionsType – The type of directions to show
  • source – The starting location
  • destination – The destination location
  • utterance – The utterance to include
showDrivingDirections(source, destination, utterance=None)

Create driving directions object and display it to the iPhone user.

  • source – The starting location
  • destination – The destination location
  • utterance – The utterance to include
showPublicTransitDirections(source, destination, utterance=None)

Create public tranportation directions object and display it to the iPhone user.

  • source – The starting location
  • destination – The destination location
  • utterance – The utterance to include
showWalkingDirections(source, destination, utterance=None)

Create walking directions object and display it to the iPhone user.

  • source – The starting location
  • destination – The destination location
  • utterance – The utterance to include

The PluginManager class

Inheritance diagram of pysiriproxy.plugins.manager.PluginManager

class pysiriproxy.plugins.manager.PluginManager(connectionManager, logger=None)[source]

The PluginManager is responsible for loading all of the available plugins as well as processing the object filters and speech rules for each of the loaded plugins.

ask(question, spoken=None)[source]

Command Siri to ask the user a question.

  • question – The question to ask
  • spoken – The text Siri will say
completeRequest(refId=None, resetContext=True)[source]

Complete a request to Siri.

  • refId – The reference ID
loadPlugins(directory)[source]

Load all of the plugins from the plugins directory.

  • directory – The plugins directory
makeView(views)[source]

Create a view and send it to the iPhone.

  • views – The list of views to create
processFilters(obj, direction)[source]

Process all the plugin filters for this object and data direction.

  • obj – The object
  • direction – The data direction
processSpeechRules(text)[source]

Process all the plugin speech rules for this recognized text.

  • text – The recognized text
resetContext()[source]

Reset the context.

say(text, spoken=None, prompt=False, refId=None)[source]

Command Siri to speak a piece of text.

  • text – The text that Siri will display
  • spoken – The text that Siri will speak
  • prompt – True to have Siri prompt for a response
showDirections(directionsType, source, destination, utterance=None)[source]

Show the given type of directions between the two locations to the user.

  • directionsType – The type of directions
  • source – The source location
  • destination – The destination location
  • utterance – The utterance to speak
showDrivingDirections(source, destination, utterance=None)[source]

Show driving directions between the two locations to the user.

  • source – The source location
  • destination – The destination location
  • utterance – The utterance to speak
showPublicTransitDirections(source, destination, utterance=None)[source]

Show public transportation directions between the two locations to the user.

  • source – The source location
  • destination – The destination location
  • utterance – The utterance to speak
showWalkingDirections(source, destination, utterance=None)[source]

Show walking directions between the two locations to the user.

  • source – The source location
  • destination – The destination location
  • utterance – The utterance to speak

Table Of Contents

Previous topic

The plugins module

Next topic

The plugin module

This Page