mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-23 13:14:11 +00:00
Compare commits
1 Commits
MSA-1327-2
...
MSA-1319-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83418069cd |
@@ -21,7 +21,6 @@ metadata {
|
|||||||
attribute "tamper", "enum", ["detected", "clear"]
|
attribute "tamper", "enum", ["detected", "clear"]
|
||||||
attribute "heatAlarm", "enum", ["overheat detected", "clear", "rapid temperature rise", "underheat detected"]
|
attribute "heatAlarm", "enum", ["overheat detected", "clear", "rapid temperature rise", "underheat detected"]
|
||||||
fingerprint deviceId: "0x0701", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x59, 0x85, 0x73, 0x84, 0x80, 0x71, 0x56, 0x70, 0x31, 0x8E, 0x22, 0x9C, 0x98, 0x7A", outClusters: "0x20, 0x8B"
|
fingerprint deviceId: "0x0701", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x59, 0x85, 0x73, 0x84, 0x80, 0x71, 0x56, 0x70, 0x31, 0x8E, 0x22, 0x9C, 0x98, 0x7A", outClusters: "0x20, 0x8B"
|
||||||
fingerprint mfr:"010F", prod:"0C02", model:"1002"
|
|
||||||
}
|
}
|
||||||
simulator {
|
simulator {
|
||||||
//battery
|
//battery
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
.st-ignore
|
|
||||||
README.md
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# Smartsense Motion Sensor
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Works with:
|
|
||||||
|
|
||||||
* [Samsung SmartThings Motion Sensor](https://shop.smartthings.com/#!/products/samsung-smartthings-motion-sensor)
|
|
||||||
|
|
||||||
## Table of contents
|
|
||||||
|
|
||||||
* [Capabilities](#capabilities)
|
|
||||||
* [Health]($health)
|
|
||||||
|
|
||||||
## Capabilities
|
|
||||||
|
|
||||||
* **Configuration** - _configure()_ command called when device is installed or device preferences updated
|
|
||||||
* **Motion Sensor** - can detect motion
|
|
||||||
* **Battery** - defines device uses a battery
|
|
||||||
* **Refresh** - _refresh()_ command for status updates
|
|
||||||
* **Health Check** - indicates ability to get device health notifications
|
|
||||||
|
|
||||||
## Device Health
|
|
||||||
|
|
||||||
A Category C2 motion sensor that has 120min check-in interval
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -155,4 +155,4 @@ private getIncludeArticle() {
|
|||||||
def name = location.name.toLowerCase()
|
def name = location.name.toLowerCase()
|
||||||
def segs = name.split(" ")
|
def segs = name.split(" ")
|
||||||
!(["work","home"].contains(name) || (segs.size() > 1 && (["the","my","a","an"].contains(segs[0]) || segs[0].endsWith("'s"))))
|
!(["work","home"].contains(name) || (segs.size() > 1 && (["the","my","a","an"].contains(segs[0]) || segs[0].endsWith("'s"))))
|
||||||
}
|
}
|
||||||
@@ -107,8 +107,8 @@ mappings {
|
|||||||
path("/locks") {
|
path("/locks") {
|
||||||
action: [
|
action: [
|
||||||
GET: "listLocks",
|
GET: "listLocks",
|
||||||
PUT: "updateLocks",
|
PUT: "updateLock",
|
||||||
POST: "updateLocks"
|
POST: "updateLock"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
path("/locks/:id") {
|
path("/locks/:id") {
|
||||||
@@ -442,87 +442,31 @@ def executePhrase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAll(devices) {
|
private void updateAll(devices) {
|
||||||
def type = params.param1
|
|
||||||
def command = request.JSON?.command
|
def command = request.JSON?.command
|
||||||
if (!devices) {
|
if (command)
|
||||||
httpError(404, "Devices not found")
|
{
|
||||||
}
|
command = command.toLowerCase()
|
||||||
if (command){
|
devices."$command"()
|
||||||
devices.each { device ->
|
|
||||||
executeCommand(device, type, command)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(devices) {
|
private void update(devices) {
|
||||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
||||||
def type = params.param1
|
//def command = request.JSON?.command
|
||||||
def command = request.JSON?.command
|
def command = params.command
|
||||||
def device = devices?.find { it.id == params.id }
|
if (command)
|
||||||
|
{
|
||||||
if (!device) {
|
command = command.toLowerCase()
|
||||||
|
def device = devices.find { it.id == params.id }
|
||||||
|
if (!device)
|
||||||
|
{
|
||||||
httpError(404, "Device not found")
|
httpError(404, "Device not found")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
device."$command"()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command) {
|
|
||||||
executeCommand(device, type, command)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validating the command passed by the user based on capability.
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
def validateCommand(device, deviceType, command) {
|
|
||||||
def capabilityCommands = getDeviceCapabilityCommands(device.capabilities)
|
|
||||||
def currentDeviceCapability = getCapabilityName(deviceType)
|
|
||||||
if (capabilityCommands[currentDeviceCapability]) {
|
|
||||||
return command in capabilityCommands[currentDeviceCapability] ? true : false
|
|
||||||
} else {
|
|
||||||
// Handling other device types here, which don't accept commands
|
|
||||||
httpError(400, "Bad request.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Need to get the attribute name to do the lookup. Only
|
|
||||||
* doing it for the device types which accept commands
|
|
||||||
* @return attribute name of the device type
|
|
||||||
*/
|
|
||||||
def getCapabilityName(type) {
|
|
||||||
switch(type) {
|
|
||||||
case "switches":
|
|
||||||
return "Switch"
|
|
||||||
case "locks":
|
|
||||||
return "Lock"
|
|
||||||
default:
|
|
||||||
return type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructing the map over here of
|
|
||||||
* supported commands by device capability
|
|
||||||
* @return a map of device capability -> supported commands
|
|
||||||
*/
|
|
||||||
def getDeviceCapabilityCommands(deviceCapabilities) {
|
|
||||||
def map = [:]
|
|
||||||
deviceCapabilities.collect {
|
|
||||||
map[it.name] = it.commands.collect{ it.name.toString() }
|
|
||||||
}
|
|
||||||
return map
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates and executes the command
|
|
||||||
* on the device or devices
|
|
||||||
*/
|
|
||||||
def executeCommand(device, type, command) {
|
|
||||||
if (validateCommand(device, type, command)) {
|
|
||||||
device."$command"()
|
|
||||||
} else {
|
|
||||||
httpError(403, "Access denied. This command is not supported by current capability.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private show(devices, type) {
|
private show(devices, type) {
|
||||||
|
|||||||
@@ -1,129 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2015 SmartThings
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* Alfred Workflow
|
|
||||||
*
|
|
||||||
* Author: SmartThings
|
|
||||||
*/
|
|
||||||
|
|
||||||
definition(
|
|
||||||
name: "김신동",
|
|
||||||
namespace: "vlaminck",
|
|
||||||
author: "SmartThings",
|
|
||||||
description: "This SmartApp allows you to interact with the things in your physical graph through Alfred.",
|
|
||||||
category: "Convenience",
|
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app.png",
|
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app@2x.png",
|
|
||||||
oauth: [displayName: "SmartThings Alfred Workflow", displayLink: ""]
|
|
||||||
)
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
section("Allow Alfred to Control These Things...") {
|
|
||||||
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
|
|
||||||
input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mappings {
|
|
||||||
path("/switches") {
|
|
||||||
action: [
|
|
||||||
GET: "listSwitches",
|
|
||||||
PUT: "updateSwitches"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/switches/:id") {
|
|
||||||
action: [
|
|
||||||
GET: "showSwitch",
|
|
||||||
PUT: "updateSwitch"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/locks") {
|
|
||||||
action: [
|
|
||||||
GET: "listLocks",
|
|
||||||
PUT: "updateLocks"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/locks/:id") {
|
|
||||||
action: [
|
|
||||||
GET: "showLock",
|
|
||||||
PUT: "updateLock"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {}
|
|
||||||
|
|
||||||
def updated() {}
|
|
||||||
|
|
||||||
def listSwitches() {
|
|
||||||
switches.collect { device(it,"switch") }
|
|
||||||
}
|
|
||||||
void updateSwitches() {
|
|
||||||
updateAll(switches)
|
|
||||||
}
|
|
||||||
def showSwitch() {
|
|
||||||
show(switches, "switch")
|
|
||||||
}
|
|
||||||
void updateSwitch() {
|
|
||||||
update(switches)
|
|
||||||
}
|
|
||||||
|
|
||||||
def listLocks() {
|
|
||||||
locks.collect { device(it, "lock") }
|
|
||||||
}
|
|
||||||
void updateLocks() {
|
|
||||||
updateAll(locks)
|
|
||||||
}
|
|
||||||
def showLock() {
|
|
||||||
show(locks, "lock")
|
|
||||||
}
|
|
||||||
void updateLock() {
|
|
||||||
update(locks)
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateAll(devices) {
|
|
||||||
def command = request.JSON?.command
|
|
||||||
if (command) {
|
|
||||||
devices."$command"()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update(devices) {
|
|
||||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
|
||||||
def command = request.JSON?.command
|
|
||||||
if (command) {
|
|
||||||
def device = devices.find { it.id == params.id }
|
|
||||||
if (!device) {
|
|
||||||
httpError(404, "Device not found")
|
|
||||||
} else {
|
|
||||||
device."$command"()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private show(devices, name) {
|
|
||||||
def device = devices.find { it.id == params.id }
|
|
||||||
if (!device) {
|
|
||||||
httpError(404, "Device not found")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
def s = device.currentState(name)
|
|
||||||
[id: device.id, label: device.displayName, name: device.displayName, state: s]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private device(it, name) {
|
|
||||||
if (it) {
|
|
||||||
def s = it.currentState(name)
|
|
||||||
[id: it.id, label: it.displayName, name: it.displayName, state: s]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user