mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-22 05:10:52 +00:00
Compare commits
1 Commits
MSA-2022-1
...
PROD_2017.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b645872d8f |
@@ -108,20 +108,11 @@ def updated(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x26: 1, // SwitchMultilevel
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x70: 1, // Configuration
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
if (description != "updated") {
|
if (description != "updated") {
|
||||||
log.debug "parse() >> zwave.parse($description)"
|
log.debug "parse() >> zwave.parse($description)"
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x26: 1, 0x70: 1])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = zwaveEvent(cmd)
|
result = zwaveEvent(cmd)
|
||||||
}
|
}
|
||||||
@@ -188,16 +179,6 @@ def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelS
|
|||||||
[createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
|
[createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
// Handles all Z-Wave commands we aren't interested in
|
// Handles all Z-Wave commands we aren't interested in
|
||||||
[:]
|
[:]
|
||||||
|
|||||||
@@ -88,20 +88,11 @@ def updated(){
|
|||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x26: 1, // SwitchMultilevel
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x70: 1, // Configuration
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
if (description != "updated") {
|
if (description != "updated") {
|
||||||
log.debug "parse() >> zwave.parse($description)"
|
log.debug "parse() >> zwave.parse($description)"
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x26: 1, 0x70: 1])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = zwaveEvent(cmd)
|
result = zwaveEvent(cmd)
|
||||||
}
|
}
|
||||||
@@ -168,16 +159,6 @@ def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelS
|
|||||||
[createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
|
[createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
// Handles all Z-Wave commands we aren't interested in
|
// Handles all Z-Wave commands we aren't interested in
|
||||||
[:]
|
[:]
|
||||||
|
|||||||
@@ -85,21 +85,11 @@ metadata {
|
|||||||
details(["switch", "power", "energy", "levelSliderControl", "refresh", "reset"])
|
details(["switch", "power", "energy", "levelSliderControl", "refresh", "reset"])
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x26: 3, // SwitchMultilevel
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x70: 1, // Configuration
|
|
||||||
0x32: 3, // Meter
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse events into attributes
|
// parse events into attributes
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
if (description != "updated") {
|
if (description != "updated") {
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x32:3])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = zwaveEvent(cmd)
|
result = zwaveEvent(cmd)
|
||||||
log.debug("'$description' parsed to $result")
|
log.debug("'$description' parsed to $result")
|
||||||
@@ -134,21 +124,6 @@ def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelR
|
|||||||
dimmerEvents(cmd)
|
dimmerEvents(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
|
||||||
// Handles all Z-Wave commands we aren't interested in
|
|
||||||
[:]
|
|
||||||
}
|
|
||||||
|
|
||||||
def dimmerEvents(physicalgraph.zwave.Command cmd) {
|
def dimmerEvents(physicalgraph.zwave.Command cmd) {
|
||||||
def result = []
|
def result = []
|
||||||
def value = (cmd.value ? "on" : "off")
|
def value = (cmd.value ? "on" : "off")
|
||||||
|
|||||||
@@ -89,19 +89,10 @@ def updated() {
|
|||||||
} catch (e) { log.debug e }
|
} catch (e) { log.debug e }
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x32: 1, // SwitchMultilevel
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x72: 2, // ManufacturerSpecific
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
if(description == "updated") return
|
if(description == "updated") return
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x32: 1, 0x72: 2])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = zwaveEvent(cmd)
|
result = zwaveEvent(cmd)
|
||||||
}
|
}
|
||||||
@@ -166,16 +157,6 @@ def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerS
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
log.debug "$device.displayName: Unhandled: $cmd"
|
log.debug "$device.displayName: Unhandled: $cmd"
|
||||||
[:]
|
[:]
|
||||||
|
|||||||
@@ -71,17 +71,9 @@ def updated(){
|
|||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x70: 1, // Configuration
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = createEvent(zwaveEvent(cmd))
|
result = createEvent(zwaveEvent(cmd))
|
||||||
}
|
}
|
||||||
@@ -128,15 +120,6 @@ def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerS
|
|||||||
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
|
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
// Handles all Z-Wave commands we aren't interested in
|
// Handles all Z-Wave commands we aren't interested in
|
||||||
|
|||||||
@@ -89,17 +89,9 @@ def updated(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommandClassVersions() {
|
|
||||||
[
|
|
||||||
0x20: 1, // Basic
|
|
||||||
0x56: 1, // Crc16Encap
|
|
||||||
0x70: 1, // Configuration
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse(String description) {
|
def parse(String description) {
|
||||||
def result = null
|
def result = null
|
||||||
def cmd = zwave.parse(description, commandClassVersions)
|
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
result = createEvent(zwaveEvent(cmd))
|
result = createEvent(zwaveEvent(cmd))
|
||||||
}
|
}
|
||||||
@@ -146,16 +138,6 @@ def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerS
|
|||||||
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
|
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
|
||||||
}
|
}
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
|
|
||||||
def versions = commandClassVersions
|
|
||||||
def version = versions[cmd.commandClass as Integer]
|
|
||||||
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
|
|
||||||
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
|
|
||||||
if (encapsulatedCommand) {
|
|
||||||
zwaveEvent(encapsulatedCommand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
// Handles all Z-Wave commands we aren't interested in
|
// Handles all Z-Wave commands we aren't interested in
|
||||||
|
|||||||
@@ -1,145 +0,0 @@
|
|||||||
/**
|
|
||||||
* JSON
|
|
||||||
*
|
|
||||||
* Copyright 2015 Jesse Newland
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
|
||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing permissions and limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
definition(
|
|
||||||
name: "JSON API",
|
|
||||||
namespace: "jnewland",
|
|
||||||
author: "Jesse Newland",
|
|
||||||
description: "A JSON API for SmartThings",
|
|
||||||
category: "SmartThings Labs",
|
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
|
||||||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
|
||||||
oauth: true)
|
|
||||||
|
|
||||||
|
|
||||||
def installed() {
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
unsubscribe()
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def initialize() {
|
|
||||||
if (!state.accessToken) {
|
|
||||||
createAccessToken()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
page(name: "copyConfig")
|
|
||||||
}
|
|
||||||
|
|
||||||
def copyConfig() {
|
|
||||||
if (!state.accessToken) {
|
|
||||||
createAccessToken()
|
|
||||||
}
|
|
||||||
dynamicPage(name: "copyConfig", title: "Config", install:true) {
|
|
||||||
section("Select devices to include in the /devices API call") {
|
|
||||||
input "switches", "capability.switch", title: "Switches", multiple: true, required: false
|
|
||||||
input "hues", "capability.colorControl", title: "Hues", multiple: true, required: false
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
paragraph "View this SmartApp's configuration to use it in other places."
|
|
||||||
href url:"https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations/${app.id}/config?access_token=${state.accessToken}", style:"embedded", required:false, title:"Config", description:"Tap, select, copy, then click \"Done\""
|
|
||||||
}
|
|
||||||
|
|
||||||
section() {
|
|
||||||
href url:"https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations/${app.id}/devices?access_token=${state.accessToken}", style:"embedded", required:false, title:"Debug", description:"View accessories JSON"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def renderConfig() {
|
|
||||||
def configJson = new groovy.json.JsonOutput().toJson([
|
|
||||||
description: "JSON API",
|
|
||||||
platforms: [
|
|
||||||
[
|
|
||||||
platform: "SmartThings",
|
|
||||||
name: "SmartThings",
|
|
||||||
app_id: app.id,
|
|
||||||
access_token: state.accessToken
|
|
||||||
]
|
|
||||||
],
|
|
||||||
])
|
|
||||||
|
|
||||||
def configString = new groovy.json.JsonOutput().prettyPrint(configJson)
|
|
||||||
render contentType: "text/plain", data: configString
|
|
||||||
}
|
|
||||||
|
|
||||||
def deviceCommandMap(device, type) {
|
|
||||||
device.supportedCommands.collectEntries { command->
|
|
||||||
def commandUrl = "https://graph-eu01-euwest1.api.smartthings.com/api/smartapps/installations/${app.id}/${type}/${device.id}/command/${command.name}?access_token=${state.accessToken}"
|
|
||||||
[
|
|
||||||
(command.name): commandUrl
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def authorizedDevices() {
|
|
||||||
[
|
|
||||||
switches: switches,
|
|
||||||
hues: hues
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
def renderDevices() {
|
|
||||||
def deviceData = authorizedDevices().collectEntries { devices->
|
|
||||||
[
|
|
||||||
(devices.key): devices.value.collect { device->
|
|
||||||
[
|
|
||||||
name: device.displayName,
|
|
||||||
commands: deviceCommandMap(device, devices.key)
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
def deviceJson = new groovy.json.JsonOutput().toJson(deviceData)
|
|
||||||
def deviceString = new groovy.json.JsonOutput().prettyPrint(deviceJson)
|
|
||||||
render contentType: "application/json", data: deviceString
|
|
||||||
}
|
|
||||||
|
|
||||||
def deviceCommand() {
|
|
||||||
def device = authorizedDevices()[params.type].find { it.id == params.id }
|
|
||||||
def command = params.command
|
|
||||||
if (!device) {
|
|
||||||
httpError(404, "Device not found")
|
|
||||||
} else {
|
|
||||||
if (params.value) {
|
|
||||||
device."$command"(params.value)
|
|
||||||
} else {
|
|
||||||
device."$command"()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mappings {
|
|
||||||
if (!params.access_token || (params.access_token && params.access_token != state.accessToken)) {
|
|
||||||
path("/devices") { action: [GET: "authError"] }
|
|
||||||
path("/config") { action: [GET: "authError"] }
|
|
||||||
path("/:type/:id/command/:command") { action: [PUT: "authError"] }
|
|
||||||
} else {
|
|
||||||
path("/devices") { action: [GET: "renderDevices"] }
|
|
||||||
path("/config") { action: [GET: "renderConfig"] }
|
|
||||||
path("/:type/:id/command/:command") { action: [PUT: "deviceCommand"] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def authError() {
|
|
||||||
[error: "Permission denied"]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user