Skip to content

Commit aae7f23

Browse files
authored
Merge pull request SmartThingsCommunity#1302 from SmartThingsCommunity/staging
Rolling up staging for production deployment
2 parents 8c4f7ed + aab3b8d commit aae7f23

File tree

5 files changed

+54
-56
lines changed

5 files changed

+54
-56
lines changed

devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ private Map parseIasMessage(String description) {
180180
def getTemperature(value) {
181181
def celsius = Integer.parseInt(value, 16).shortValue() / 100
182182
if(getTemperatureScale() == "C"){
183-
return celsius
183+
return Math.round(celsius)
184184
} else {
185-
return celsiusToFahrenheit(celsius) as Integer
185+
return Math.round(celsiusToFahrenheit(celsius))
186186
}
187187
}
188188

devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ private Map parseIasMessage(String description) {
194194
def getTemperature(value) {
195195
def celsius = Integer.parseInt(value, 16).shortValue() / 100
196196
if(getTemperatureScale() == "C"){
197-
return celsius
197+
return Math.round(celsius)
198198
} else {
199-
return celsiusToFahrenheit(celsius) as Integer
199+
return Math.round(celsiusToFahrenheit(celsius))
200200
}
201201
}
202202

devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def updated() {
261261
def getTemperature(value) {
262262
def celsius = Integer.parseInt(value, 16).shortValue() / 100
263263
if(getTemperatureScale() == "C"){
264-
return celsius
264+
return Math.round(celsius)
265265
} else {
266-
return celsiusToFahrenheit(celsius) as Integer
266+
return Math.round(celsiusToFahrenheit(celsius))
267267
}
268268
}
269269

smartapps/imbrianj/safe-watch.src/safe-watch.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ preferences {
2626
}
2727

2828
section("Temperature monitor?") {
29-
input "temp", "capability.temperatureMeasurement", title: "Temp Sensor", required: false
30-
input "maxTemp", "number", title: "Max Temp?", required: false
31-
input "minTemp", "number", title: "Min Temp?", required: false
29+
input "temp", "capability.temperatureMeasurement", title: "Temperature Sensor", required: false
30+
input "maxTemp", "number", title: "Max Temperature (°${location.temperatureScale})", required: false
31+
input "minTemp", "number", title: "Min Temperature (°${location.temperatureScale})", required: false
3232
}
3333

3434
section("When which people are away?") {

smartapps/smartthings/hue-connect.src/hue-connect.groovy

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def bridgeDiscovery(params=[:])
8383

8484
return dynamicPage(name:"bridgeDiscovery", title:"Discovery Started!", nextPage:"bridgeBtnPush", refreshInterval:refreshInterval, uninstall: true) {
8585
section("Please wait while we discover your Hue Bridge. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
86-
input "selectedHue", "enum", required:false, title:"Select Hue Bridge (${numFound} found)", multiple:false, options:options
86+
input "selectedHue", "enum", required:false, title:"Select Hue Bridge (${numFound} found)", multiple:false, options:options, submitOnChange: true
8787
}
8888
}
8989
}
@@ -963,6 +963,14 @@ private handleCommandResponse(body) {
963963
* @return empty array
964964
*/
965965
private handlePoll(body) {
966+
// Used to track "unreachable" time
967+
// Device is considered "offline" if it has been in the "unreachable" state for
968+
// 11 minutes (e.g. two poll intervals)
969+
// Note, Hue Bridge marks devices as "unreachable" often even when they accept commands
970+
Calendar time11 = Calendar.getInstance()
971+
time11.add(Calendar.MINUTE, -11)
972+
Calendar currentTime = Calendar.getInstance()
973+
966974
def bulbs = getChildDevices()
967975
for (bulb in body) {
968976
def device = bulbs.find{it.deviceNetworkId == "${app.id}/${bulb.key}"}
@@ -972,7 +980,10 @@ private handlePoll(body) {
972980
// light just came back online, notify device watch
973981
def lastActivity = now()
974982
device.sendEvent(name: "deviceWatch-status", value: "ONLINE", description: "Last Activity is on ${new Date((long) lastActivity)}", displayed: false, isStateChange: true)
983+
log.debug "$device is Online"
975984
}
985+
// Mark light as "online"
986+
state.bulbs[bulb.key]?.unreachableSince = null
976987
state.bulbs[bulb.key]?.online = true
977988

978989
// If user just executed commands, then do not send events to avoid confusing the turning on/off state
@@ -982,9 +993,18 @@ private handlePoll(body) {
982993
sendColorEvents(device, bulb.value?.state?.xy, bulb.value?.state?.hue, bulb.value?.state?.sat, bulb.value?.state?.ct, bulb.value?.state?.colormode)
983994
}
984995
} else {
985-
state.bulbs[bulb.key]?.online = false
986-
log.warn "$device is not reachable by Hue bridge"
987-
device.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", displayed: false, isStateChange: true)
996+
if (state.bulbs[bulb.key]?.unreachableSince == null) {
997+
// Store the first time where device was reported as "unreachable"
998+
state.bulbs[bulb.key]?.unreachableSince = currentTime.getTimeInMillis()
999+
} else if (state.bulbs[bulb.key]?.online) {
1000+
// Check if device was "unreachable" for more than 11 minutes and mark "offline" if necessary
1001+
if (state.bulbs[bulb.key]?.unreachableSince < time11.getTimeInMillis()) {
1002+
log.warn "$device went Offline"
1003+
state.bulbs[bulb.key]?.online = false
1004+
device.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", displayed: false, isStateChange: true)
1005+
}
1006+
}
1007+
log.warn "$device may not reachable by Hue bridge"
9881008
}
9891009
}
9901010
}
@@ -1019,9 +1039,6 @@ def hubVerification(bodytext) {
10191039
def on(childDevice) {
10201040
log.debug "Executing 'on'"
10211041
def id = getId(childDevice)
1022-
if (!isOnline(id)) {
1023-
return "Bulb is unreachable"
1024-
}
10251042
updateInProgress()
10261043
createSwitchEvent(childDevice, "on")
10271044
put("lights/$id/state", [on: true])
@@ -1031,9 +1048,6 @@ def on(childDevice) {
10311048
def off(childDevice) {
10321049
log.debug "Executing 'off'"
10331050
def id = getId(childDevice)
1034-
if (!isOnline(id)) {
1035-
return "Bulb is unreachable"
1036-
}
10371051
updateInProgress()
10381052
createSwitchEvent(childDevice, "off")
10391053
put("lights/$id/state", [on: false])
@@ -1043,9 +1057,6 @@ def off(childDevice) {
10431057
def setLevel(childDevice, percent) {
10441058
log.debug "Executing 'setLevel'"
10451059
def id = getId(childDevice)
1046-
if (!isOnline(id)) {
1047-
return "Bulb is unreachable"
1048-
}
10491060
updateInProgress()
10501061
// 1 - 254
10511062
def level
@@ -1070,10 +1081,6 @@ def setLevel(childDevice, percent) {
10701081
def setSaturation(childDevice, percent) {
10711082
log.debug "Executing 'setSaturation($percent)'"
10721083
def id = getId(childDevice)
1073-
if (!isOnline(id)) {
1074-
return "Bulb is unreachable"
1075-
}
1076-
10771084
updateInProgress()
10781085
// 0 - 254
10791086
def level = Math.min(Math.round(percent * 254 / 100), 254)
@@ -1086,9 +1093,6 @@ def setSaturation(childDevice, percent) {
10861093
def setHue(childDevice, percent) {
10871094
log.debug "Executing 'setHue($percent)'"
10881095
def id = getId(childDevice)
1089-
if (!isOnline(id)) {
1090-
return "Bulb is unreachable"
1091-
}
10921096
updateInProgress()
10931097
// 0 - 65535
10941098
def level = Math.min(Math.round(percent * 65535 / 100), 65535)
@@ -1101,9 +1105,6 @@ def setHue(childDevice, percent) {
11011105
def setColorTemperature(childDevice, huesettings) {
11021106
log.debug "Executing 'setColorTemperature($huesettings)'"
11031107
def id = getId(childDevice)
1104-
if (!isOnline(id)) {
1105-
return "Bulb is unreachable"
1106-
}
11071108
updateInProgress()
11081109
// 153 (6500K) to 500 (2000K)
11091110
def ct = hueSettings == 6500 ? 153 : Math.round(1000000/huesettings)
@@ -1115,9 +1116,6 @@ def setColorTemperature(childDevice, huesettings) {
11151116
def setColor(childDevice, huesettings) {
11161117
log.debug "Executing 'setColor($huesettings)'"
11171118
def id = getId(childDevice)
1118-
if (!isOnline(id)) {
1119-
return "Bulb is unreachable"
1120-
}
11211119
updateInProgress()
11221120

11231121
def value = [:]
@@ -1133,7 +1131,7 @@ def setColor(childDevice, huesettings) {
11331131
value.hue = Math.min(Math.round(huesettings.hue * 65535 / 100), 65535)
11341132
if (huesettings.saturation != null)
11351133
value.sat = Math.min(Math.round(huesettings.saturation * 254 / 100), 254)
1136-
} else if (huesettings.hex != null && false) {
1134+
} else if (huesettings.hex != null) {
11371135
// For now ignore model to get a consistent color if same color is set across multiple devices
11381136
// def model = state.bulbs[getId(childDevice)]?.modelid
11391137
// value.xy = calculateXY(huesettings.hex, model)
@@ -1237,7 +1235,7 @@ private getBridgeIP() {
12371235
if (d) {
12381236
if (d.getDeviceDataByName("networkAddress"))
12391237
host = d.getDeviceDataByName("networkAddress")
1240-
else
1238+
else
12411239
host = d.latestState('networkAddress').stringValue
12421240
}
12431241
if (host == null || host == "") {
@@ -1676,7 +1674,7 @@ private boolean checkPointInLampsReach(p, colorPoints) {
16761674
}
16771675

16781676
/**
1679-
* Converts an RGB color in hex to HSV.
1677+
* Converts an RGB color in hex to HSV/HSB.
16801678
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
16811679
*
16821680
* @param colorStr color value in hex (#ff03d3)
@@ -1686,32 +1684,32 @@ private boolean checkPointInLampsReach(p, colorPoints) {
16861684
def hexToHsv(colorStr){
16871685
def r = Integer.valueOf( colorStr.substring( 1, 3 ), 16 ) / 255
16881686
def g = Integer.valueOf( colorStr.substring( 3, 5 ), 16 ) / 255
1689-
def b = Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) / 255;
1687+
def b = Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) / 255
16901688

16911689
def max = Math.max(Math.max(r, g), b)
16921690
def min = Math.min(Math.min(r, g), b)
16931691

1694-
def h, s, v = max;
1692+
def h, s, v = max
16951693

1696-
def d = max - min;
1697-
s = max == 0 ? 0 : d / max;
1694+
def d = max - min
1695+
s = max == 0 ? 0 : d / max
16981696

16991697
if(max == min){
1700-
h = 0;
1698+
h = 0
17011699
}else{
17021700
switch(max){
1703-
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1704-
case g: h = (b - r) / d + 2; break;
1705-
case b: h = (r - g) / d + 4; break;
1701+
case r: h = (g - b) / d + (g < b ? 6 : 0); break
1702+
case g: h = (b - r) / d + 2; break
1703+
case b: h = (r - g) / d + 4; break
17061704
}
17071705
h /= 6;
17081706
}
17091707

1710-
return [(h * 100).round(), (s * 100).round(), (v * 100).round()];
1708+
return [Math.round(h * 100), Math.round(s * 100), Math.round(v * 100)]
17111709
}
17121710

17131711
/**
1714-
* Converts HSV color to RGB in hex.
1712+
* Converts HSV/HSB color to RGB in hex.
17151713
* Algorithm based on http://en.wikipedia.org/wiki/HSV_color_space.
17161714
*
17171715
* @param hue hue 0-100
@@ -1726,11 +1724,11 @@ def hsvToHex(hue, sat, value = 100){
17261724
def s = sat / 100
17271725
def v = value / 100
17281726

1729-
def i = Math.floor(h * 6);
1730-
def f = h * 6 - i;
1731-
def p = v * (1 - s);
1732-
def q = v * (1 - f * s);
1733-
def t = v * (1 - (1 - f) * s);
1727+
def i = Math.floor(h * 6)
1728+
def f = h * 6 - i
1729+
def p = v * (1 - s)
1730+
def q = v * (1 - f * s)
1731+
def t = v * (1 - (1 - f) * s)
17341732

17351733
switch (i % 6) {
17361734
case 0:
@@ -1766,9 +1764,9 @@ def hsvToHex(hue, sat, value = 100){
17661764
}
17671765

17681766
// Converting float components to int components.
1769-
def r1 = String.format("%02X", (int) (r * 255.0f));
1770-
def g1 = String.format("%02X", (int) (g * 255.0f));
1771-
def b1 = String.format("%02X", (int) (b * 255.0f));
1767+
def r1 = String.format("%02X", (int) (r * 255.0f))
1768+
def g1 = String.format("%02X", (int) (g * 255.0f))
1769+
def b1 = String.format("%02X", (int) (b * 255.0f))
17721770

17731771
return "#$r1$g1$b1"
17741772
}

0 commit comments

Comments
 (0)