smartapp.interface¶
Classes that are part of the SmartApp interface.
Module Contents¶
- smartapp.interface.AUTHORIZATION_HEADER = 'authorization'¶
- smartapp.interface.CORRELATION_ID_HEADER = 'x-st-correlation'¶
- smartapp.interface.DATE_HEADER = 'date'¶
- class smartapp.interface.LifecyclePhase(*args, **kwds)¶
Bases:
enum.EnumLifecycle phases.
- CONFIRMATION = 'CONFIRMATION'¶
- CONFIGURATION = 'CONFIGURATION'¶
- INSTALL = 'INSTALL'¶
- UPDATE = 'UPDATE'¶
- UNINSTALL = 'UNINSTALL'¶
- OAUTH_CALLBACK = 'OAUTH_CALLBACK'¶
- EVENT = 'EVENT'¶
- class smartapp.interface.ConfigValueType(*args, **kwds)¶
Bases:
enum.EnumTypes of config values.
- DEVICE = 'DEVICE'¶
- STRING = 'STRING'¶
- class smartapp.interface.ConfigPhase(*args, **kwds)¶
Bases:
enum.EnumSub-phases within the CONFIGURATION phase.
- INITIALIZE = 'INITIALIZE'¶
- PAGE = 'PAGE'¶
- class smartapp.interface.ConfigSettingType(*args, **kwds)¶
Bases:
enum.EnumTypes of config settings.
- DEVICE = 'DEVICE'¶
- TEXT = 'TEXT'¶
- BOOLEAN = 'BOOLEAN'¶
- ENUM = 'ENUM'¶
- LINK = 'LINK'¶
- PAGE = 'PAGE'¶
- IMAGE = 'IMAGE'¶
- ICON = 'ICON'¶
- TIME = 'TIME'¶
- PARAGRAPH = 'PARAGRAPH'¶
- EMAIL = 'EMAIL'¶
- DECIMAL = 'DECIMAL'¶
- NUMBER = 'NUMBER'¶
- PHONE = 'PHONE'¶
- OAUTH = 'OAUTH'¶
- class smartapp.interface.EventType(*args, **kwds)¶
Bases:
enum.EnumSupported event types.
- DEVICE_COMMANDS_EVENT = 'DEVICE_COMMANDS_EVENT'¶
- DEVICE_EVENT = 'DEVICE_EVENT'¶
- DEVICE_HEALTH_EVENT = 'DEVICE_HEALTH_EVENT'¶
- DEVICE_LIFECYCLE_EVENT = 'DEVICE_LIFECYCLE_EVENT'¶
- HUB_HEALTH_EVENT = 'HUB_HEALTH_EVENT'¶
- INSTALLED_APP_LIFECYCLE_EVENT = 'INSTALLED_APP_LIFECYCLE_EVENT'¶
- MODE_EVENT = 'MODE_EVENT'¶
- SCENE_LIFECYCLE_EVENT = 'SCENE_LIFECYCLE_EVENT'¶
- SECURITY_ARM_STATE_EVENT = 'SECURITY_ARM_STATE_EVENT'¶
- TIMER_EVENT = 'TIMER_EVENT'¶
- WEATHER_EVENT = 'WEATHER_EVENT'¶
- class smartapp.interface.SubscriptionType(*args, **kwds)¶
Bases:
enum.EnumSupported subscription types.
- DEVICE = 'DEVICE'¶
- CAPABILITY = 'CAPABILITY'¶
- MODE = 'MODE'¶
- DEVICE_LIFECYCLE = 'DEVICE_LIFECYCLE'¶
- DEVICE_HEALTH = 'DEVICE_HEALTH'¶
- SECURITY_ARM_STATE = 'SECURITY_ARM_STATE'¶
- HUB_HEALTH = 'HUB_HEALTH'¶
- SCENE_LIFECYCLE = 'SCENE_LIFECYCLE'¶
- class smartapp.interface.BooleanValue¶
Bases:
enum.StrEnumString boolean values.
- TRUE = 'true'¶
- FALSE = 'false'¶
- class smartapp.interface.AbstractRequest¶
Bases:
abc.ABCAbstract parent class for all types of lifecycle requests.
- lifecycle: LifecyclePhase¶
- class smartapp.interface.AbstractSetting¶
Bases:
abc.ABCAbstract parent class for all types of config settings.
- class smartapp.interface.DeviceSetting¶
Bases:
AbstractSettingA DEVICE setting.
- type: ConfigSettingType¶
- class smartapp.interface.TextSetting¶
Bases:
AbstractSettingA TEXT setting.
- type: ConfigSettingType¶
- class smartapp.interface.BooleanSetting¶
Bases:
AbstractSettingA BOOLEAN setting.
- type: ConfigSettingType¶
- default_value: BooleanValue¶
- class smartapp.interface.EnumOptionGroup¶
A group of options within an ENUM setting
- options: list[EnumOption]¶
- class smartapp.interface.EnumSetting¶
Bases:
AbstractSettingAn ENUM setting.
- type: ConfigSettingType¶
- options: list[EnumOption] | None = None¶
- grouped_options: list[EnumOptionGroup] | None = None¶
- class smartapp.interface.LinkSetting¶
Bases:
AbstractSettingA LINK setting.
- type: ConfigSettingType¶
- class smartapp.interface.PageSetting¶
Bases:
AbstractSettingA PAGE setting.
- type: ConfigSettingType¶
- class smartapp.interface.ImageSetting¶
Bases:
AbstractSettingAn IMAGE setting.
- type: ConfigSettingType¶
- class smartapp.interface.IconSetting¶
Bases:
AbstractSettingAn ICON setting.
- type: ConfigSettingType¶
- class smartapp.interface.TimeSetting¶
Bases:
AbstractSettingA TIME setting.
- type: ConfigSettingType¶
- class smartapp.interface.ParagraphSetting¶
Bases:
AbstractSettingA PARAGRAPH setting.
- type: ConfigSettingType¶
- class smartapp.interface.EmailSetting¶
Bases:
AbstractSettingAn EMAIL setting.
- type: ConfigSettingType¶
- class smartapp.interface.DecimalSetting¶
Bases:
AbstractSettingA DECIMAL setting.
- type: ConfigSettingType¶
- class smartapp.interface.NumberSetting¶
Bases:
AbstractSettingA NUMBER setting.
- type: ConfigSettingType¶
- class smartapp.interface.PhoneSetting¶
Bases:
AbstractSettingA PHONE setting.
- type: ConfigSettingType¶
- class smartapp.interface.OauthSetting¶
Bases:
AbstractSettingAn OAUTH setting.
- type: ConfigSettingType¶
- smartapp.interface.ConfigSetting¶
- class smartapp.interface.DeviceConfigValue¶
DEVICE configuration value.
- device_config: DeviceValue¶
- value_type: ConfigValueType¶
- class smartapp.interface.StringConfigValue¶
STRING configuration value.
- string_config: StringValue¶
- value_type: ConfigValueType¶
- smartapp.interface.ConfigValue¶
- class smartapp.interface.InstalledApp¶
Installed application.
- as_devices(key: str) list[DeviceValue]¶
Return a list of devices for a named configuration value.
- class smartapp.interface.Event¶
Holds the triggered event, one of several different attributes depending on event type.
- class smartapp.interface.ConfigInit¶
Initialization data.
- class smartapp.interface.ConfigRequestData¶
Configuration data provided on the request.
- phase: ConfigPhase¶
- class smartapp.interface.ConfigInitData¶
Configuration data provided in an INITIALIZATION response.
- initialize: ConfigInit¶
- class smartapp.interface.ConfigSection¶
A section within a configuration page.
- class smartapp.interface.ConfigPage¶
A page of configuration data for the CONFIGURATION phase.
- sections: list[ConfigSection]¶
- class smartapp.interface.ConfigPageData¶
Configuration data provided in an PAGE response.
- page: ConfigPage¶
- class smartapp.interface.InstallData¶
Install data.
- installed_app: InstalledApp¶
- as_devices(key: str) list[DeviceValue]¶
Return a list of devices for a named configuration value.
- class smartapp.interface.UpdateData¶
Update data.
- installed_app: InstalledApp¶
- as_devices(key: str) list[DeviceValue]¶
Return a list of devices for a named configuration value.
- class smartapp.interface.UninstallData¶
Install data.
- installed_app: InstalledApp¶
- class smartapp.interface.EventData¶
Event data.
- installed_app: InstalledApp¶
- class smartapp.interface.ConfirmationRequest¶
Bases:
AbstractRequestRequest for CONFIRMATION phase
- confirmation_data: ConfirmationData¶
- class smartapp.interface.ConfigurationRequest¶
Bases:
AbstractRequestRequest for CONFIGURATION phase
- configuration_data: ConfigRequestData¶
- class smartapp.interface.ConfigurationInitResponse¶
Response for CONFIGURATION/INITIALIZE phase
- configuration_data: ConfigInitData¶
- class smartapp.interface.ConfigurationPageResponse¶
Response for CONFIGURATION/PAGE phase
- configuration_data: ConfigPageData¶
- class smartapp.interface.InstallRequest¶
Bases:
AbstractRequestRequest for INSTALL phase
- install_data: InstallData¶
- as_devices(key: str) list[DeviceValue]¶
Return a list of devices for a named configuration value.
- class smartapp.interface.UpdateRequest¶
Bases:
AbstractRequestRequest for UPDATE phase
- update_data: UpdateData¶
- as_devices(key: str) list[DeviceValue]¶
Return a list of devices for a named configuration value.
- class smartapp.interface.UninstallRequest¶
Bases:
AbstractRequestRequest for UNINSTALL phase
- uninstall_data: UninstallData¶
- class smartapp.interface.UninstallResponse¶
Response for UNINSTALL phase
- class smartapp.interface.OauthCallbackRequest¶
Bases:
AbstractRequestRequest for OAUTH_CALLBACK phase
- o_auth_callback_data: OauthCallbackData¶
- class smartapp.interface.OauthCallbackResponse¶
Response for OAUTH_CALLBACK phase
- class smartapp.interface.EventRequest¶
Bases:
AbstractRequestRequest for EVENT phase
- smartapp.interface.LifecycleRequest¶
- smartapp.interface.LifecycleResponse¶
- smartapp.interface.REQUEST_BY_PHASE¶
- smartapp.interface.CONFIG_VALUE_BY_TYPE¶
- smartapp.interface.CONFIG_SETTING_BY_TYPE¶
- exception smartapp.interface.SmartAppError¶
Bases:
ExceptionAn error tied to the SmartApp implementation.
- exception smartapp.interface.InternalError¶
Bases:
SmartAppErrorAn internal error was encountered processing a lifecycle event.
- exception smartapp.interface.BadRequestError¶
Bases:
SmartAppErrorA lifecycle event was invalid.
- exception smartapp.interface.SignatureError¶
Bases:
SmartAppErrorThe request signature on a lifecycle event was invalid.
- class smartapp.interface.SmartAppDispatcherConfig¶
Configuration for the SmartAppDispatcher.
Any production SmartApp should always check signatures. We support disabling that feature to make local testing easier during development.
BEWARE: setting log_json to True will potentially place secrets (such as authorization keys) in your logs. This is intended for use during development and debugging only.
- clock_skew_sec¶
Amount of clock skew allowed when verifying digital signatures, or None to allow any skew
- Type:
- class smartapp.interface.SmartAppEventHandler¶
Bases:
abc.ABCApplication event handler for SmartApp lifecycle events.
Inherit from this class to implement your own application-specific event handler. The application-specific event handler is always called first, before any default event handler logic in the dispatcher itself.
The correlation id is an optional value that you can associate with your log messages. It may aid in debugging if you need to contact SmartThings for support.
Some lifecycle events do not require you to implement any custom event handler logic:
CONFIRMATION: normally no callback needed, since the dispatcher logs the app id and confirmation URL
CONFIGURATION: normally no callback needed, since the dispatcher has the information it needs to respond
INSTALL/UPDATE: set up or replace subscriptions and schedules and persist required data, if any
UNINSTALL: remove persisted data, if any
OAUTH_CALLBACK: coordinate with your oauth provider as needed
EVENT: handle SmartThings events or scheduled triggers
The EventRequest object that you receive for the EVENT callback includes an authorization token and also the entire configuration bundle for the installed application. So, if your SmartApp is built around event handling and scheduled actions triggered by SmartThings, your handler can probably be stateless. There is probably is not any need to persist any of the data returned in the INSTALL or UPDATE lifecycle events into your own data store.
Note that SmartAppHandler is a synchronous and single-threaded interface. The assumption is that if you need high-volume asynchronous or multi-threaded processing, you will implement that at the tier above this where the actual POST requests are accepted from remote callers.
- abstractmethod handle_confirmation(correlation_id: str | None, request: ConfirmationRequest) None¶
Handle a CONFIRMATION lifecycle request
- abstractmethod handle_configuration(correlation_id: str | None, request: ConfigurationRequest) None¶
Handle a CONFIGURATION lifecycle request.
- abstractmethod handle_install(correlation_id: str | None, request: InstallRequest) None¶
Handle an INSTALL lifecycle request.
- abstractmethod handle_update(correlation_id: str | None, request: UpdateRequest) None¶
Handle an UPDATE lifecycle request.
- abstractmethod handle_uninstall(correlation_id: str | None, request: UninstallRequest) None¶
Handle an UNINSTALL lifecycle request.
- abstractmethod handle_oauth_callback(correlation_id: str | None, request: OauthCallbackRequest) None¶
Handle an OAUTH_CALLBACK lifecycle request.
- abstractmethod handle_event(correlation_id: str | None, request: EventRequest) None¶
Handle an EVENT lifecycle request.
- class smartapp.interface.SmartAppConfigPage¶
A page of configuration for the SmartApp.
- sections: list[ConfigSection]¶
- class smartapp.interface.SmartAppDefinition¶
The definition of the SmartApp.
All of this data would normally be static for any given version of your application. If you wish, you can maintain the definition in YAML or JSON in your source tree and parse it with smartapp.converter.CONVERTER.
Keep in mind that the JSON or YAML format on disk will be consistent with the SmartThings lifecycle API, so it will use camel case attribute names (like configPages) rather than the Python attribute names you see in source code (like config_pages).
- config_pages¶
Configuration pages that the SmartApp will offer users
- Type:
List[SmartAppConfigPage]
- config_pages: list[SmartAppConfigPage] | None¶
- class smartapp.interface.SmartAppConfigManager¶
Bases:
abc.ABCConfiguration manager, used by the dispatcher to respond to CONFIGURATION events.
The dispatcher has a default configuration manager. However, you can implement your own if that default behavior does not meet your needs. For instance, a static config 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.
This abstract class also includes several convenience methods to make it easier to build responses.
- handle_initialize(_request: ConfigurationRequest, definition: SmartAppDefinition) ConfigurationInitResponse¶
Handle a CONFIGURATION INITIALIZE lifecycle request.
- abstractmethod handle_page(request: ConfigurationRequest, definition: SmartAppDefinition, page_id: int) ConfigurationPageResponse¶
Handle a CONFIGURATION PAGE lifecycle request.
- class smartapp.interface.SmartAppRequestContext¶
The context for a SmartApp lifecycle request.
- headers: collections.abc.Mapping[str, str]¶
- normalized: collections.abc.Mapping[str, str]¶