SmartApp SDK

SmartApp and Client SDK

License

License

Categories

Categories

GUI User Interface Guice Application Layer Libs Dependency Injection
GroupId

GroupId

com.smartthings.sdk
ArtifactId

ArtifactId

smartapp-guice
Last Version

Last Version

0.0.4-PREVIEW
Release Date

Release Date

Type

Type

jar
Description

Description

SmartApp SDK
SmartApp and Client SDK
Project URL

Project URL

https://github.com/SmartThingsCommunity/smartapp-sdk-java
Project Organization

Project Organization

com.smartthings.sdk
Source Code Management

Source Code Management

https://github.com/SmartThingsCommunity/smartapp-sdk-java

Download smartapp-guice

How to add to project

<!-- https://jarcasting.com/artifacts/com.smartthings.sdk/smartapp-guice/ -->
<dependency>
    <groupId>com.smartthings.sdk</groupId>
    <artifactId>smartapp-guice</artifactId>
    <version>0.0.4-PREVIEW</version>
</dependency>
// https://jarcasting.com/artifacts/com.smartthings.sdk/smartapp-guice/
implementation 'com.smartthings.sdk:smartapp-guice:0.0.4-PREVIEW'
// https://jarcasting.com/artifacts/com.smartthings.sdk/smartapp-guice/
implementation ("com.smartthings.sdk:smartapp-guice:0.0.4-PREVIEW")
'com.smartthings.sdk:smartapp-guice:jar:0.0.4-PREVIEW'
<dependency org="com.smartthings.sdk" name="smartapp-guice" rev="0.0.4-PREVIEW">
  <artifact name="smartapp-guice" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.smartthings.sdk', module='smartapp-guice', version='0.0.4-PREVIEW')
)
libraryDependencies += "com.smartthings.sdk" % "smartapp-guice" % "0.0.4-PREVIEW"
[com.smartthings.sdk/smartapp-guice "0.0.4-PREVIEW"]

Dependencies

runtime (2)

Group / Artifact Type Version
com.smartthings.sdk : smartapp-core jar 0.0.4-PREVIEW
com.google.inject : guice jar 4.2.2

Project Modules

There are no modules declared in this project.

SmartThings SmartApp SDK Java (Preview) SmartThings Java

Known Vulnerabilities

Welcome! This SDK is currently in preview and is not recommended for use in production applications at this time. We welcome your bug reports, feature requests, and contributions.

This SDK includes a set of JVM libraries for building webhook and AWS Lambda SmartApps, and interacting with the public SmartThings REST API.

Prerequisites

Adding the SDK to your build

Several artifacts are published to the Maven central repository under the com.smartthings.sdk group.

  • smartapp-core - Core SmartApp Framework
    • smartapp-guice - Extension library for use with Google Guice
    • smartapp-spring - Extension library for use with Spring Dependency Injection
    • smartapp-contextstore-dynamodb - Extension library to use DynamoDB to store installed application context data.
  • smartthings-client - Library for working with SmartThings APIs

Import the library dependencies as needed:

Apache Maven
<dependency>
  <groupId>com.smartthings.sdk</groupId>
  <artifactId>smartapp-core</artifactId>
  <version>0.0.4-PREVIEW</version>
  <type>pom</type>
</dependency>
Gradle Groovy DSL
implementation 'com.smartthings.sdk:smartapp-core:0.0.4-PREVIEW'

If you prefer, the artifacts can be downloaded directly from Maven Central.

Getting Started

What is a SmartApp?

SmartApps are an example of a SmartThings Automation. Automations allow users to control the SmartThings ecosystem without manual intervention. Creating a SmartApp allows you to control and get status notifications from SmartThings devices using the SmartThings REST API.

Webhook SmartApps are any publicly-accessible web server that will receive a POST request payload.

AWS Lambda SmartApps are hosted in the Amazon Web Services cloud and are invoked by ARN instead of a public-DNS address.

automation smartapp

To learn more about what a SmartApp is and how you can create interesting automations, please visit the developer portal documentation.

Basics

Take a quick look at how SmartApps are declared in various languages.

Kotlin (click to toggle)
package app

val smartApp: SmartApp = SmartApp.of { spec ->
    spec
        .configuration(Configuration())
        .install {
            Response.ok(InstallResponseData())
        }
        .update {
            Response.ok(UpdateResponseData())
        }
        .event {
            Response.ok(EventResponseData())
        }
        .uninstall {
            Response.ok(UninstallResponseData())
        }
}

fun Application.main() {
    install(Routing) {
        post("/smartapp") {
            call.respond(smartApp.execute(call.receive()))
        }
    }
}
Groovy (click to toggle)
    SmartApp smartApp = SmartApp.of { spec ->
        spec
            .install({ req ->
                // create subscriptions
                Response.ok()
            })
            .update({ req ->
                // delete subscriptions
                // create subscriptions
                Response.ok()
            })
            .configuration({ req ->
                ConfigurationResponseData data = ...// build config
                Response.ok(data)
            })
            .event(EventHandler.of { eventSpec ->
                eventSpec
                    .onSubscription("switch", { event ->
                       // do something
                    })
                    .onSchedule("nightly", { event ->
                       // do something
                    })
                    .onEvent(
                        { event ->
                            // test event
                            true
                        },
                        { event ->
                            // do something
                        }
                    )
            })
    }
Java (click to toggle)
    private final SmartApp smartApp = SmartApp.of(spec ->
        spec
            .install(request -> {
                return Response.ok();
            })
            .update(request -> {
                return Response.ok(UpdateResponseData.newInstance());
            })
            .configuration(request -> {
                return Response.ok(ConfigurationReponseData.newInstance());
            })
            .event(request -> {
                EventData eventData = request.getEventData();
                EventHandler.of(eventSpec ->
                        eventSpec
                                .onEvent(event -> {
                                    // when this predicate is true...
                                    return true;
                                }, event -> {
                                    // ...do something with event
                                })
                                .onSchedule("nightly", event -> {
                                    // do something
                                })
                                .onSubscription("switch", event -> {
                                    // do something
                                })
                );
                return Response.ok(EventResponseData.newInstance());
            })
        );

Runnable Examples

Several simple examples of using the sdk are included in the examples directory.

kotlin-smartapp (Documentation) kotlin-logo ktor-logo

This Kotlin example implements the Java smartapp-core library with a simple Ktor server.

java-ratpack-guice-smartapp (Documentation) java-logo ratpack-logo

This Java example implements the Java smartapp-core library with a Ratpack server and uses Guice for dependency management.

java-springboot-smartapp (Documentation) java-logo spring-logo

This Java example implements the Java smartapp-core library using Spring Boot.

java-lambda-smartapp (Documentation) java-logo aws-logo

This Java example implements the Java smartapp-core library as an AWS Lambda.

Documentation

Modules

smartapp-core (Documentation)

Core SmartApp framework. Provides abilities for defining a SmartApp that could be used in many environments - AWS Lambda / Dropwizard / Ratpack / etc

smartthings-client (Documentation)

An API library that provides useful utilities for working with the Subscription / Schedules / Device APIs

Extension Libraries

smartapp-guice (Documentation)

An extension library that provides support for building a SmartApp with Guice dependency injection.

smartapp-spring (Documentation)

An extension library that provides support for building a SmartApp with Spring dependency injection.

smartapp-contextstore-dynamodb (Documentation)

An extension library that implements a context store using DynamoDB.

More about SmartThings

If you are not familiar with SmartThings, we have extensive on-line documentation.

To create and manage your services and devices on SmartThings, create an account in the developer workspace.

The SmartThings Community is a good place share and ask questions.

There is also a SmartThings reddit community where you can read and share information.

License and Copyright

Licensed under the Apache License, Version 2.0

Copyright 2019 SmartThings, Inc.

com.smartthings.sdk

SmartThings Community

APIs, SDKs and open source projects from SmartThings

Versions

Version
0.0.4-PREVIEW
0.0.3-PREVIEW
0.0.2-PREVIEW
0.0.1-PREVIEW