4 * Copyright 2015 Daniel
8 name: "Vinli Home Connect",
9 namespace: "com.vinli.smartthings",
11 description: "Allows Vinli users to connect their car to SmartThings",
12 category: "SmartThings Labs",
13 iconUrl: "https://d3azp77rte0gip.cloudfront.net/smartapps/baeb2e5d-ebd0-49fe-a4ec-e92417ae20bb/images/vinli_oauth_60.png",
14 iconX2Url: "https://d3azp77rte0gip.cloudfront.net/smartapps/baeb2e5d-ebd0-49fe-a4ec-e92417ae20bb/images/vinli_oauth_120.png",
15 iconX3Url: "https://d3azp77rte0gip.cloudfront.net/smartapps/baeb2e5d-ebd0-49fe-a4ec-e92417ae20bb/images/vinli_oauth_120.png",
19 section ("Allow external service to control these things...") {
20 input "switches", "capability.switch", multiple: true, required: true
21 input "locks", "capability.lock", multiple: true, required: true
38 path("/switches/:command") {
43 path("/switches/:id/:command") {
48 path("/locks/:command") {
53 path("/locks/:id/:command") {
59 path("/devices/:id/:command") {
66 // returns a list of all devices
67 def listAllDevices() {
70 resp << [name: it.name, label: it.label, value: it.currentValue("switch"), type: "switch", id: it.id, hub: it.hub?.name]
74 resp << [name: it.name, label: it.label, value: it.currentValue("lock"), type: "lock", id: it.id, hub: it.hub?.name]
79 // returns a list like
80 // [[name: "kitchen lamp", value: "off"], [name: "bathroom", value: "on"]]
84 resp << [name: it.displayName, value: it.currentValue("switch"), type: "switch", id: it.id]
90 // use the built-in request object to get the command parameter
91 def command = params.command
95 // check that the switch supports the specified command
96 // If not, return an error using httpError, providing a HTTP status code.
98 if (!it.hasCommand(command)) {
99 httpError(501, "$command is not a valid command for all switches specified")
103 // all switches have the comand
104 // execute the command on all switches
105 // (note we can do this on the array - the command will be invoked on every element
111 def command = params.command
114 if (!it.hasCommand(command)) {
115 httpError(400, "$command is not a valid command for all lock specified")
118 if (it.id == params.id) {
124 void updateSwitch() {
125 def command = params.command
128 if (!it.hasCommand(command)) {
129 httpError(400, "$command is not a valid command for all switches specified")
132 if (it.id == params.id) {
138 void commandDevice() {
139 def command = params.command
151 if (it.id == params.id) {
152 if (!it.hasCommand(command)) {
153 httpError(400, "$command is not a valid command for specified device")
160 void updateSwitches() {
161 // use the built-in request object to get the command parameter
162 def command = params.command
166 // check that the switch supports the specified command
167 // If not, return an error using httpError, providing a HTTP status code.
169 if (!it.hasCommand(command)) {
170 httpError(400, "$command is not a valid command for all switches specified")
174 // all switches have the comand
175 // execute the command on all switches
176 // (note we can do this on the array - the command will be invoked on every element
177 switches."$command"()
182 log.debug "Installed with settings: ${settings}"
186 log.debug "Updated with settings: ${settings}"