smartapp.dispatcher

Manage the requests and responses that are part of the SmartApp lifecycle.

Module Contents

class smartapp.dispatcher.StaticConfigManager

Bases: smartapp.interface.SmartAppConfigManager

Configuration manager that operates on static data.

This is the configuration manager used by default in the dispatcher. It operates on a static set of config pages. This sort of static definition is adequate for lots of SmartApps, but it doesn’t work for some types of complex configuration, where the responses need to be generated dynamically. In that case, you can implement your own configuration manager with that specialized behavior.

handle_page(_request: smartapp.interface.ConfigurationRequest, definition: smartapp.interface.SmartAppDefinition, page_id: int) smartapp.interface.ConfigurationPageResponse

Handle a CONFIGURATION PAGE lifecycle request.

class smartapp.dispatcher.SmartAppDispatcher

Dispatcher to manage the requests and responses that are part of the SmartApp lifecycle.

You must provide both a definition and an event handler, but in some cases the handler methods will probably be no-ops without any custom logic. For more information, see SmartAppEventHandler.

definition

The static definition for the SmartApp

Type:

SmartAppDefinition

event_handler

Application event handler for SmartApp lifecycle events

Type:

SmartAppEventHandler

definition: smartapp.interface.SmartAppDefinition
event_handler: smartapp.interface.SmartAppEventHandler
config: smartapp.interface.SmartAppDispatcherConfig
manager: smartapp.interface.SmartAppConfigManager
dispatch(context: smartapp.interface.SmartAppRequestContext) str

Dispatch a request, responding to SmartThings and invoking callbacks as needed.

Parameters:

context (SmartAppRequestContext) – The request context

Returns:

Response JSON payload that to be returned to the POST caller

Return type:

str

Raises:

SmartAppError – If processing fails