Skip to content

Commit 024a6cb

Browse files
committed
Merge pull request SmartThingsCommunity#632 from SmartThingsCommunity/staging
Rolling up changes to production from staging 2016-03-17 Release
2 parents 62a965d + 410e9f4 commit 024a6cb

File tree

24 files changed

+1872
-262
lines changed

24 files changed

+1872
-262
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* BeaconThing
3+
*
4+
* Copyright 2015 obycode
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7+
* in compliance with the License. You may obtain a copy of the License at:
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13+
* for the specific language governing permissions and limitations under the License.
14+
*
15+
*/
16+
17+
import groovy.json.JsonSlurper
18+
19+
metadata {
20+
definition (name: "BeaconThing", namespace: "com.obycode", author: "obycode") {
21+
capability "Beacon"
22+
capability "Presence Sensor"
23+
capability "Sensor"
24+
25+
attribute "inRange", "json_object"
26+
attribute "inRangeFriendly", "string"
27+
28+
command "setPresence", ["string"]
29+
command "arrived", ["string"]
30+
command "left", ["string"]
31+
}
32+
33+
simulator {
34+
status "present": "presence: 1"
35+
status "not present": "presence: 0"
36+
}
37+
38+
tiles {
39+
standardTile("presence", "device.presence", width: 2, height: 2, canChangeBackground: true) {
40+
state("present", labelIcon:"st.presence.tile.present", backgroundColor:"#53a7c0")
41+
state("not present", labelIcon:"st.presence.tile.not-present", backgroundColor:"#ffffff")
42+
}
43+
valueTile("inRange", "device.inRangeFriendly", inactiveLabel: true, height:1, width:3, decoration: "flat") {
44+
state "default", label:'${currentValue}', backgroundColor:"#ffffff"
45+
}
46+
main "presence"
47+
details (["presence","inRange"])
48+
}
49+
}
50+
51+
// parse events into attributes
52+
def parse(String description) {
53+
log.debug "Parsing '${description}'"
54+
}
55+
56+
def installed() {
57+
sendEvent(name: "presence", value: "not present")
58+
def emptyList = []
59+
def json = new groovy.json.JsonBuilder(emptyList)
60+
sendEvent(name:"inRange", value:json.toString())
61+
}
62+
63+
def setPresence(status) {
64+
log.debug "Status is $status"
65+
sendEvent(name:"presence", value:status)
66+
}
67+
68+
def arrived(id) {
69+
log.debug "$id has arrived"
70+
def theList = device.latestValue("inRange")
71+
def inRangeList = new JsonSlurper().parseText(theList)
72+
if (inRangeList.contains(id)) {
73+
return
74+
}
75+
inRangeList += id
76+
def json = new groovy.json.JsonBuilder(inRangeList)
77+
log.debug "Now in range: ${json.toString()}"
78+
sendEvent(name:"inRange", value:json.toString())
79+
80+
// Generate human friendly string for tile
81+
def friendlyList = "Nearby: " + inRangeList.join(", ")
82+
sendEvent(name:"inRangeFriendly", value:friendlyList)
83+
84+
if (inRangeList.size() == 1) {
85+
setPresence("present")
86+
}
87+
}
88+
89+
def left(id) {
90+
log.debug "$id has left"
91+
def theList = device.latestValue("inRange")
92+
def inRangeList = new JsonSlurper().parseText(theList)
93+
inRangeList -= id
94+
def json = new groovy.json.JsonBuilder(inRangeList)
95+
log.debug "Now in range: ${json.toString()}"
96+
sendEvent(name:"inRange", value:json.toString())
97+
98+
// Generate human friendly string for tile
99+
def friendlyList = "Nearby: " + inRangeList.join(", ")
100+
101+
if (inRangeList.empty) {
102+
setPresence("not present")
103+
friendlyList = "No one is nearby"
104+
}
105+
106+
sendEvent(name:"inRangeFriendly", value:friendlyList)
107+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* Simple Sync
3+
*
4+
* Copyright 2015 Roomie Remote, Inc.
5+
*
6+
* Date: 2015-09-22
7+
*/
8+
metadata
9+
{
10+
definition (name: "Simple Sync", namespace: "roomieremote-agent", author: "Roomie Remote, Inc.")
11+
{
12+
capability "Media Controller"
13+
}
14+
15+
// simulator metadata
16+
simulator
17+
{
18+
}
19+
20+
// UI tile definitions
21+
tiles
22+
{
23+
standardTile("mainTile", "device.status", width: 1, height: 1, icon: "st.Entertainment.entertainment11")
24+
{
25+
state "default", label: "Simple Sync", icon: "st.Home.home2", backgroundColor: "#55A7FF"
26+
}
27+
28+
def detailTiles = ["mainTile"]
29+
30+
main "mainTile"
31+
details(detailTiles)
32+
}
33+
}
34+
35+
def parse(String description)
36+
{
37+
def results = []
38+
39+
try
40+
{
41+
def msg = parseLanMessage(description)
42+
43+
if (msg.headers && msg.body)
44+
{
45+
switch (msg.headers["X-Roomie-Echo"])
46+
{
47+
case "getAllActivities":
48+
handleGetAllActivitiesResponse(msg)
49+
break
50+
}
51+
}
52+
}
53+
catch (Throwable t)
54+
{
55+
sendEvent(name: "parseError", value: "$t", description: description)
56+
throw t
57+
}
58+
59+
results
60+
}
61+
62+
def handleGetAllActivitiesResponse(response)
63+
{
64+
def body = parseJson(response.body)
65+
66+
if (body.status == "success")
67+
{
68+
def json = new groovy.json.JsonBuilder()
69+
def root = json activities: body.data
70+
def data = json.toString()
71+
72+
sendEvent(name: "activities", value: data)
73+
}
74+
}
75+
76+
def getAllActivities(evt)
77+
{
78+
def host = getHostAddress(device.deviceNetworkId)
79+
80+
def action = new physicalgraph.device.HubAction(method: "GET",
81+
path: "/api/v1/activities",
82+
headers: [HOST: host, "X-Roomie-Echo": "getAllActivities"])
83+
84+
action
85+
}
86+
87+
def startActivity(evt)
88+
{
89+
def uuid = evt
90+
def host = getHostAddress(device.deviceNetworkId)
91+
def activity = new groovy.json.JsonSlurper().parseText(device.currentValue('activities') ?: "{ 'activities' : [] }").activities.find { it.uuid == uuid }
92+
def toggle = activity["toggle"]
93+
def jsonMap = ["activity_uuid": uuid]
94+
95+
if (toggle != null)
96+
{
97+
jsonMap << ["toggle_state": toggle ? "on" : "off"]
98+
}
99+
100+
def json = new groovy.json.JsonBuilder(jsonMap)
101+
def jsonBody = json.toString()
102+
def headers = [HOST: host, "Content-Type": "application/json"]
103+
104+
def action = new physicalgraph.device.HubAction(method: "POST",
105+
path: "/api/v1/runactivity",
106+
body: jsonBody,
107+
headers: headers)
108+
109+
action
110+
}
111+
112+
def getHostAddress(d)
113+
{
114+
def parts = d.split(":")
115+
def ip = convertHexToIP(parts[0])
116+
def port = convertHexToInt(parts[1])
117+
return ip + ":" + port
118+
}
119+
120+
def String convertHexToIP(hex)
121+
{
122+
[convertHexToInt(hex[0..1]),convertHexToInt(hex[2..3]),convertHexToInt(hex[4..5]),convertHexToInt(hex[6..7])].join(".")
123+
}
124+
125+
def Integer convertHexToInt(hex)
126+
{
127+
Integer.parseInt(hex,16)
128+
}

devicetypes/smartthings/cree-bulb.src/cree-bulb.groovy

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Cree Bulb
33
*
4-
* Copyright 2014 SmartThings
4+
* Copyright 2016 SmartThings
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
77
* in compliance with the License. You may obtain a copy of the License at:
@@ -15,29 +15,29 @@
1515
*/
1616

1717
metadata {
18-
definition (name: "Cree Bulb", namespace: "smartthings", author: "SmartThings") {
18+
definition (name: "Cree Bulb", namespace: "smartthings", author: "SmartThings") {
1919

20-
capability "Actuator"
20+
capability "Actuator"
2121
capability "Configuration"
22-
capability "Refresh"
23-
capability "Switch"
24-
capability "Switch Level"
22+
capability "Refresh"
23+
capability "Switch"
24+
capability "Switch Level"
2525

26-
fingerprint profileId: "C05E", inClusters: "0000,0003,0004,0005,0006,0008,1000", outClusters: "0000,0019"
27-
}
26+
fingerprint profileId: "C05E", inClusters: "0000,0003,0004,0005,0006,0008,1000", outClusters: "0000,0019"
27+
}
2828

29-
// simulator metadata
30-
simulator {
31-
// status messages
32-
status "on": "on/off: 1"
33-
status "off": "on/off: 0"
29+
// simulator metadata
30+
simulator {
31+
// status messages
32+
status "on": "on/off: 1"
33+
status "off": "on/off: 0"
3434

35-
// reply messages
36-
reply "zcl on-off on": "on/off: 1"
37-
reply "zcl on-off off": "on/off: 0"
38-
}
35+
// reply messages
36+
reply "zcl on-off on": "on/off: 1"
37+
reply "zcl on-off off": "on/off: 0"
38+
}
3939

40-
// UI tile definitions
40+
// UI tile definitions
4141
tiles(scale: 2) {
4242
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
4343
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
@@ -62,18 +62,12 @@ metadata {
6262
def parse(String description) {
6363
log.debug "description is $description"
6464

65-
def resultMap = zigbee.getKnownDescription(description)
65+
def resultMap = zigbee.getEvent(description)
6666
if (resultMap) {
67-
log.info resultMap
68-
if (resultMap.type == "update") {
69-
log.info "$device updates: ${resultMap.value}"
70-
}
71-
else {
72-
sendEvent(name: resultMap.type, value: resultMap.value)
73-
}
67+
sendEvent(resultMap)
7468
}
7569
else {
76-
log.warn "DID NOT PARSE MESSAGE for description : $description"
70+
log.debug "DID NOT PARSE MESSAGE for description : $description"
7771
log.debug zigbee.parseDescriptionAsMap(description)
7872
}
7973
}
@@ -87,7 +81,7 @@ def on() {
8781
}
8882

8983
def setLevel(value) {
90-
zigbee.setLevel(value)
84+
zigbee.setLevel(value) + ["delay 500"] + zigbee.levelRefresh() //adding refresh because of ZLL bulb not conforming to send-me-a-report
9185
}
9286

9387
def refresh() {

devicetypes/smartthings/ecobee-sensor.src/ecobee-sensor.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ metadata {
4848
}
4949

5050
standardTile("motion", "device.motion") {
51-
state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0")
5251
state("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#ffffff")
52+
state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0")
5353
}
5454

5555
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat") {

0 commit comments

Comments
 (0)