diff --git a/devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy b/devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy index 952b183..0c10c51 100644 --- a/devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy +++ b/devicetypes/smartthings/hue-bloom.src/hue-bloom.groovy @@ -37,9 +37,6 @@ metadata { tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel", range:"(0..100)" } - tileAttribute ("device.level", key: "SECONDARY_CONTROL") { - attributeState "level", label: 'Level ${currentValue}%' - } tileAttribute ("device.color", key: "COLOR_CONTROL") { attributeState "color", action:"setAdjustedColor" } diff --git a/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy b/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy index 950ac51..d533006 100644 --- a/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy +++ b/devicetypes/smartthings/hue-bulb.src/hue-bulb.groovy @@ -38,9 +38,6 @@ metadata { tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel", range:"(0..100)" } - tileAttribute ("device.level", key: "SECONDARY_CONTROL") { - attributeState "level", label: 'Level ${currentValue}%' - } tileAttribute ("device.color", key: "COLOR_CONTROL") { attributeState "color", action:"setAdjustedColor" } diff --git a/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy b/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy index a1d7f33..2944ce3 100644 --- a/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy +++ b/devicetypes/smartthings/hue-lux-bulb.src/hue-lux-bulb.groovy @@ -33,9 +33,6 @@ metadata { tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel", range:"(0..100)" } - tileAttribute ("device.level", key: "SECONDARY_CONTROL") { - attributeState "level", label: 'Level ${currentValue}%' - } } controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") { diff --git a/devicetypes/smartthings/hue-white-ambiance-bulb/hue-white-ambiance-bulb.groovy b/devicetypes/smartthings/hue-white-ambiance-bulb/hue-white-ambiance-bulb.groovy new file mode 100644 index 0000000..c9bedb7 --- /dev/null +++ b/devicetypes/smartthings/hue-white-ambiance-bulb/hue-white-ambiance-bulb.groovy @@ -0,0 +1,110 @@ +/** + * Hue White Ambiance Bulb + * + * Philips Hue Type "Color Temperature Light" + * + * Author: SmartThings + */ + +// for the UI +metadata { + // Automatically generated. Make future change here. + definition (name: "Hue White Ambiance Bulb", namespace: "smartthings", author: "SmartThings") { + capability "Switch Level" + capability "Actuator" + capability "Color Temperature" + capability "Switch" + capability "Refresh" + + command "refresh" + } + + simulator { + // TODO: define status and reply messages here + } + + tiles (scale: 2){ + multiAttributeTile(name:"rich-control", type: "lighting", width: 6, height: 4, canChangeIcon: true){ + tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { + attributeState "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + attributeState "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" + attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" + } + tileAttribute ("device.level", key: "SLIDER_CONTROL") { + attributeState "level", action:"switch level.setLevel", range:"(0..100)" + } + } + + controlTile("colorTempSliderControl", "device.colorTemperature", "slider", width: 4, height: 2, inactiveLabel: false, range:"(2000..6500)") { + state "colorTemperature", action:"color temperature.setColorTemperature" + } + + valueTile("colorTemp", "device.colorTemperature", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { + state "colorTemperature", label: '${currentValue} K' + } + + standardTile("refresh", "device.refresh", height: 2, width: 2, inactiveLabel: false, decoration: "flat") { + state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" + } + + main(["rich-control"]) + details(["rich-control", "colorTempSliderControl", "colorTemp", "refresh"]) + } +} + +// parse events into attributes +def parse(description) { + log.debug "parse() - $description" + def results = [] + + def map = description + if (description instanceof String) { + log.debug "Hue Ambience Bulb stringToMap - ${map}" + map = stringToMap(description) + } + + if (map?.name && map?.value) { + results << createEvent(name: "${map?.name}", value: "${map?.value}") + } + results +} + +// handle commands +void on() { + log.trace parent.on(this) + sendEvent(name: "switch", value: "on") +} + +void off() { + log.trace parent.off(this) + sendEvent(name: "switch", value: "off") +} + +void setLevel(percent) { + log.debug "Executing 'setLevel'" + if (percent != null && percent >= 0 && percent <= 100) { + parent.setLevel(this, percent) + sendEvent(name: "level", value: percent) + sendEvent(name: "switch", value: "on") + } else { + log.warn "$percent is not 0-100" + } +} + +void setColorTemperature(value) { + if (value) { + log.trace "setColorTemperature: ${value}k" + parent.setColorTemperature(this, value) + sendEvent(name: "colorTemperature", value: value) + sendEvent(name: "switch", value: "on") + } else { + log.warn "Invalid color temperature" + } +} + +void refresh() { + log.debug "Executing 'refresh'" + parent.manualRefresh() +} + diff --git a/devicetypes/smartthings/osram-lightify-led-tunable-white-60w.src/osram-lightify-led-tunable-white-60w.groovy b/devicetypes/smartthings/osram-lightify-led-tunable-white-60w.src/osram-lightify-led-tunable-white-60w.groovy index 8253582..80fa3ba 100644 --- a/devicetypes/smartthings/osram-lightify-led-tunable-white-60w.src/osram-lightify-led-tunable-white-60w.groovy +++ b/devicetypes/smartthings/osram-lightify-led-tunable-white-60w.src/osram-lightify-led-tunable-white-60w.groovy @@ -19,11 +19,6 @@ metadata { capability "Sensor" attribute "colorName", "string" - - // indicates that device keeps track of heartbeat (in state.heartbeat) - attribute "heartbeat", "string" - - } // simulator metadata @@ -75,9 +70,6 @@ metadata { def parse(String description) { //log.trace description - // save heartbeat (i.e. last time we got a message from device) - state.heartbeat = Calendar.getInstance().getTimeInMillis() - if (description?.startsWith("catchall:")) { if(description?.endsWith("0100") ||description?.endsWith("1001") || description?.matches("on/off\\s*:\\s*1")) { @@ -132,7 +124,6 @@ def off() { } def refresh() { - sendEvent(name: "heartbeat", value: "alive", displayed:false) [ "st rattr 0x${device.deviceNetworkId} ${endpointId} 6 0", "delay 500", "st rattr 0x${device.deviceNetworkId} ${endpointId} 8 0", "delay 500", diff --git a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy index 1b47c3e..11febf1 100644 --- a/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy +++ b/devicetypes/smartthings/smartpower-outlet.src/smartpower-outlet.groovy @@ -16,7 +16,7 @@ metadata { // Automatically generated. Make future change here. - definition (name: "SmartPower Outlet", namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartPower Outlet", namespace: "smartthings", author: "SmartThings", category: "C1") { capability "Actuator" capability "Switch" capability "Power Meter" @@ -25,9 +25,6 @@ metadata { capability "Sensor" capability "Health Check" - // indicates that device keeps track of heartbeat (in state.heartbeat) - attribute "heartbeat", "string" - fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0B04,0B05", outClusters: "0019", manufacturer: "CentraLite", model: "3200", deviceJoinName: "Outlet" fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0B04,0B05", outClusters: "0019", manufacturer: "CentraLite", model: "3200-Sgb", deviceJoinName: "Outlet" fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0B04,0B05", outClusters: "0019", manufacturer: "CentraLite", model: "4257050-RZHAC", deviceJoinName: "Outlet" @@ -81,9 +78,6 @@ metadata { def parse(String description) { log.debug "description is $description" - // save heartbeat (i.e. last time we got a message from device) - state.heartbeat = Calendar.getInstance().getTimeInMillis() - def finalResult = zigbee.getKnownDescription(description) //TODO: Remove this after getKnownDescription can parse it automatically @@ -124,7 +118,6 @@ def on() { } def refresh() { - sendEvent(name: "heartbeat", value: "alive", displayed:false) zigbee.onOffRefresh() + zigbee.refreshData("0x0B04", "0x050B") } diff --git a/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy b/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy index de0526b..8248bf0 100644 --- a/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy +++ b/devicetypes/smartthings/smartsense-moisture-sensor.src/smartsense-moisture-sensor.groovy @@ -15,7 +15,7 @@ */ metadata { - definition (name: "SmartSense Moisture Sensor",namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartSense Moisture Sensor",namespace: "smartthings", author: "SmartThings", category: "C2") { capability "Configuration" capability "Battery" capability "Refresh" diff --git a/devicetypes/smartthings/smartsense-motion-sensor.src/.st-ignore b/devicetypes/smartthings/smartsense-motion-sensor.src/.st-ignore new file mode 100644 index 0000000..f78b46e --- /dev/null +++ b/devicetypes/smartthings/smartsense-motion-sensor.src/.st-ignore @@ -0,0 +1,2 @@ +.st-ignore +README.md diff --git a/devicetypes/smartthings/smartsense-motion-sensor.src/README.md b/devicetypes/smartthings/smartsense-motion-sensor.src/README.md new file mode 100644 index 0000000..82bff3f --- /dev/null +++ b/devicetypes/smartthings/smartsense-motion-sensor.src/README.md @@ -0,0 +1,30 @@ +# 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 + + + + + + diff --git a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy index 29d9dd0..660b0b7 100644 --- a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy +++ b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy @@ -15,7 +15,7 @@ */ metadata { - definition (name: "SmartSense Motion Sensor", namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartSense Motion Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { capability "Motion Sensor" capability "Configuration" capability "Battery" diff --git a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy index 892e5ad..1e30759 100644 --- a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy +++ b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy @@ -15,7 +15,7 @@ */ metadata { - definition (name: "SmartSense Multi Sensor", namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartSense Multi Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { capability "Three Axis" capability "Battery" diff --git a/devicetypes/smartthings/smartsense-open-closed-accelerometer-sensor.src/smartsense-open-closed-accelerometer-sensor.groovy b/devicetypes/smartthings/smartsense-open-closed-accelerometer-sensor.src/smartsense-open-closed-accelerometer-sensor.groovy index eb2bfdd..9f03f17 100644 --- a/devicetypes/smartthings/smartsense-open-closed-accelerometer-sensor.src/smartsense-open-closed-accelerometer-sensor.groovy +++ b/devicetypes/smartthings/smartsense-open-closed-accelerometer-sensor.src/smartsense-open-closed-accelerometer-sensor.groovy @@ -16,7 +16,7 @@ //DEPRECATED - Using the smartsense-multi-sensor.groovy DTH for this device. Users need to be moved before deleting this DTH metadata { - definition (name: "SmartSense Open/Closed Accelerometer Sensor", namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartSense Open/Closed Accelerometer Sensor", namespace: "smartthings", author: "SmartThings", category: "C2") { capability "Battery" capability "Configuration" capability "Contact Sensor" diff --git a/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy b/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy index a938cb9..0479b5d 100644 --- a/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy +++ b/devicetypes/smartthings/smartsense-temp-humidity-sensor.src/smartsense-temp-humidity-sensor.groovy @@ -14,7 +14,7 @@ * */ metadata { - definition (name: "SmartSense Temp/Humidity Sensor",namespace: "smartthings", author: "SmartThings") { + definition (name: "SmartSense Temp/Humidity Sensor",namespace: "smartthings", author: "SmartThings", category: "C2") { capability "Configuration" capability "Battery" capability "Refresh" diff --git a/devicetypes/smartthings/tile-ux/README.md b/devicetypes/smartthings/tile-ux/README.md new file mode 100644 index 0000000..ac1b48b --- /dev/null +++ b/devicetypes/smartthings/tile-ux/README.md @@ -0,0 +1,42 @@ +# Device Tiles Examples and Reference + +This package contains examples of Device tiles, organized by tile type. + +## Purpose + +Each Device Handler shows example usages of a specific tile, and is meant to represent the variety of permutations that a tile can be configured. + +The various tiles can be used by QA to test tiles on all supported mobile devices, and by developers as a reference implementation. + +## Installation + +1. Self-publish the Device Handlers in this package. +2. Self-publish the Device Tile Controller SmartApp. The SmartApp can be found [here](https://github.com/SmartThingsCommunity/SmartThingsPublic/blob/master/smartapps/smartthings/tile-ux/device-tile-controller.src/device-tile-controller.groovy). +3. Install the SmartApp from the Marketplace, under "My Apps". +4. Select the simulated devices you want to install and press "Done". + +The simulated devices can then be found in the "Things" view of "My Home" in the mobile app. +You may wish to create a new room for these simulated devices for easy access. + +## Usage + +Each simulated device can be interacted with like other devices. +You can use the mobile app to interact with the tiles to see how they look and behave. + +## Troubleshooting + +If you get an error when installing the simulated devices using the controller SmartApp, ensure that you have published all the Device Handlers for yourself. +Also check live logging to see if there is a specific tile that is causing installation issues. + +## FAQ + +*Question: A tile isn't behaving as expected. What should I do?* + +QA should create a JIRA ticket for any issues or inconsistencies of tiles across devices. + +Developers may file a support ticket, and reference the specific tile and issue observed. + +*Question: I'd like to contribute an example tile usage that would be helpful for testing and reference purposes. Can I do that?* + +We recommend that you open an issue in the SmartThingsPublic repository describing the example tile and usage. +That way we can discuss with you the proposed change, and then if appropriate you can create a PR associated to the issue. diff --git a/devicetypes/smartthings/tile-ux/tile-basic-colorwheel.src/tile-basic-colorwheel.groovy b/devicetypes/smartthings/tile-ux/tile-basic-colorwheel.src/tile-basic-colorwheel.groovy index 8086c2c..102f9e3 100644 --- a/devicetypes/smartthings/tile-ux/tile-basic-colorwheel.src/tile-basic-colorwheel.groovy +++ b/devicetypes/smartthings/tile-ux/tile-basic-colorwheel.src/tile-basic-colorwheel.groovy @@ -22,7 +22,7 @@ metadata { tiles(scale: 2) { valueTile("currentColor", "device.color") { - state "default", label: '${currentValue}' + state "color", label: '${currentValue}', defaultState: true } controlTile("rgbSelector", "device.color", "color", height: 6, width: 6, inactiveLabel: false) { @@ -41,6 +41,13 @@ def parse(String description) { log.debug "Parsing '${description}'" } +def setColor(value) { + log.debug "setting color: $value" + if (value.hex) { sendEvent(name: "color", value: value.hex) } + if (value.hue) { sendEvent(name: "hue", value: value.hue) } + if (value.saturation) { sendEvent(name: "saturation", value: value.saturation) } +} + def setSaturation(percent) { log.debug "Executing 'setSaturation'" sendEvent(name: "saturation", value: percent) diff --git a/devicetypes/smartthings/tile-ux/tile-basic-slider.src/tile-basic-slider.groovy b/devicetypes/smartthings/tile-ux/tile-basic-slider.src/tile-basic-slider.groovy index 12e30be..923b4d4 100644 --- a/devicetypes/smartthings/tile-ux/tile-basic-slider.src/tile-basic-slider.groovy +++ b/devicetypes/smartthings/tile-ux/tile-basic-slider.src/tile-basic-slider.groovy @@ -39,7 +39,7 @@ metadata { } valueTile("rangeValue", "device.rangedLevel", height: 2, width: 2) { - state "default", label:'${currentValue}' + state "range", label:'${currentValue}', defaultState: true } controlTile("rangeSliderConstrained", "device.rangedLevel", "slider", height: 2, width: 4, range: "(40..60)") { diff --git a/devicetypes/smartthings/tile-ux/tile-basic-standard.src/tile-basic-standard.groovy b/devicetypes/smartthings/tile-ux/tile-basic-standard.src/tile-basic-standard.groovy index d2b7e35..1f4f029 100644 --- a/devicetypes/smartthings/tile-ux/tile-basic-standard.src/tile-basic-standard.groovy +++ b/devicetypes/smartthings/tile-ux/tile-basic-standard.src/tile-basic-standard.groovy @@ -41,17 +41,17 @@ metadata { // standard flat tile with only a label standardTile("flatLabel", "device.switch", width: 2, height: 2, decoration: "flat") { - state "default", label: 'On Action', action: "switch.on", backgroundColor: "#ffffff" + state "label", label: 'On Action', action: "switch.on", backgroundColor: "#ffffff", defaultState: true } // standard flat tile with icon and label standardTile("flatIconLabel", "device.switch", width: 2, height: 2, decoration: "flat") { - state "default", label: 'Off Action', action: "switch.off", icon:"st.switches.switch.off", backgroundColor: "#ffffff" + state "iconLabel", label: 'Off Action', action: "switch.off", icon:"st.switches.switch.off", backgroundColor: "#ffffff", defaultState: true } // standard flat tile with only icon (Refreh text is IN the icon file) standardTile("flatIcon", "device.switch", width: 2, height: 2, decoration: "flat") { - state "default", action:"refresh.refresh", icon:"st.secondary.refresh" + state "icon", action:"refresh.refresh", icon:"st.secondary.refresh", defaultState: true } // standard with defaultState = true @@ -74,19 +74,19 @@ metadata { // utility tiles to fill the spaces standardTile("empty2x2", "null", width: 2, height: 2, decoration: "flat") { - state "default", label:'' + state "emptySmall", label:'', defaultState: true } standardTile("empty4x2", "null", width: 4, height: 2, decoration: "flat") { - state "default", label:'' + state "emptyBigger", label:'', defaultState: true } // multi-line text (explicit newlines) standardTile("multiLine", "device.multiLine", width: 2, height: 2) { - state "default", label: '${currentValue}' + state "multiLine", label: '${currentValue}', defaultState: true } standardTile("multiLineWithIcon", "device.multiLine", width: 2, height: 2) { - state "default", label: '${currentValue}', icon: "st.switches.switch.off" + state "multiLineIcon", label: '${currentValue}', icon: "st.switches.switch.off", defaultState: true } main("actionRings") diff --git a/devicetypes/smartthings/tile-ux/tile-basic-value.src/tile-basic-value.groovy b/devicetypes/smartthings/tile-ux/tile-basic-value.src/tile-basic-value.groovy index 8ea7dee..e1efb8a 100644 --- a/devicetypes/smartthings/tile-ux/tile-basic-value.src/tile-basic-value.groovy +++ b/devicetypes/smartthings/tile-ux/tile-basic-value.src/tile-basic-value.groovy @@ -22,68 +22,68 @@ metadata { tiles(scale: 2) { valueTile("text", "device.text", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("longText", "device.longText", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("integer", "device.integer", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("integerFloat", "device.integerFloat", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("pi", "device.pi", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("floatAsText", "device.floatAsText", width: 2, height: 2) { - state "default", label:'${currentValue}' + state "val", label:'${currentValue}', defaultState: true } valueTile("bgColor", "device.integer", width: 2, height: 2) { - state "default", label:'${currentValue}', backgroundColor: "#e86d13" + state "val", label:'${currentValue}', backgroundColor: "#e86d13", defaultState: true } valueTile("bgColorRange", "device.integer", width: 2, height: 2) { - state "default", label:'${currentValue}', backgroundColors: [ + state "val", label:'${currentValue}', defaultState: true, backgroundColors: [ [value: 10, color: "#ff0000"], [value: 90, color: "#0000ff"] ] } valueTile("bgColorRangeSingleItem", "device.integer", width: 2, height: 2) { - state "default", label:'${currentValue}', backgroundColors: [ + state "val", label:'${currentValue}', defaultState: true, backgroundColors: [ [value: 10, color: "#333333"] ] } valueTile("bgColorRangeConflict", "device.integer", width: 2, height: 2) { - state "default", label:'${currentValue}', backgroundColors: [ + state "valWithConflict", label:'${currentValue}', defaultState: true, backgroundColors: [ [value: 10, color: "#990000"], [value: 10, color: "#000099"] ] } valueTile("noValue", "device.nada", width: 4, height: 2) { - state "default", label:'${currentValue}' + state "noval", label:'${currentValue}', defaultState: true } valueTile("multiLine", "device.multiLine", width: 3, height: 2) { - state "default", label: '${currentValue}' + state "val", label: '${currentValue}', defaultState: true } valueTile("multiLineWithIcon", "device.multiLine", width: 3, height: 2) { - state "default", label: '${currentValue}', icon: "st.switches.switch.off" + state "val", label: '${currentValue}', icon: "st.switches.switch.off", defaultState: true } main("text") details([ - "text", "longText", "integer", + "text", "longText", "integer", "integerFloat", "pi", "floatAsText", "bgColor", "bgColorRange", "bgColorRangeSingleItem", "bgColorRangeConflict", "noValue", diff --git a/devicetypes/smartthings/tile-ux/tile-multiattribute-generic.src/tile-multiattribute-generic.groovy b/devicetypes/smartthings/tile-ux/tile-multiattribute-generic.src/tile-multiattribute-generic.groovy index 61f09d9..d535647 100644 --- a/devicetypes/smartthings/tile-ux/tile-multiattribute-generic.src/tile-multiattribute-generic.groovy +++ b/devicetypes/smartthings/tile-ux/tile-multiattribute-generic.src/tile-multiattribute-generic.groovy @@ -39,15 +39,15 @@ metadata { attributeState "turningOff", label:'${name}', backgroundColor:"#ffffff", nextState:"turningOn" } tileAttribute("device.level", key: "SECONDARY_CONTROL") { - attributeState "default", icon: 'st.Weather.weather1', action:"randomizeLevel" + attributeState "level", icon: 'st.Weather.weather1', action:"randomizeLevel", defaultState: true } tileAttribute("device.level", key: "SLIDER_CONTROL") { - attributeState "default", action:"switch level.setLevel" + attributeState "level", action:"switch level.setLevel", defaultState: true } } multiAttributeTile(name:"valueTile", type:"generic", width:6, height:4) { tileAttribute("device.level", key: "PRIMARY_CONTROL") { - attributeState "default", label:'${currentValue}', backgroundColors:[ + attributeState "level", label:'${currentValue}', defaultState: true, backgroundColors:[ [value: 0, color: "#ff0000"], [value: 20, color: "#ffff00"], [value: 40, color: "#00ff00"], @@ -69,34 +69,34 @@ metadata { } multiAttributeTile(name:"lengthyTile", type:"generic", width:6, height:4) { tileAttribute("device.lengthyText", key: "PRIMARY_CONTROL") { - attributeState "default", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821" + attributeState "lengthyText", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", defaultState: true } tileAttribute("device.lengthyText", key: "SECONDARY_CONTROL") { - attributeState "default", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821" + attributeState "lengthyText", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", defaultState: true } } multiAttributeTile(name:"multilineTile", type:"generic", width:6, height:4) { tileAttribute("device.multilineText", key: "PRIMARY_CONTROL") { - attributeState "default", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821" + attributeState "multiLineText", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", defaultState: true } tileAttribute("device.multilineText", key: "SECONDARY_CONTROL") { - attributeState "default", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821" + attributeState "multiLineText", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", defaultState: true } } multiAttributeTile(name:"lengthyTileWithIcon", type:"generic", width:6, height:4) { tileAttribute("device.lengthyText", key: "PRIMARY_CONTROL") { - attributeState "default", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", icon: "st.switches.switch.on" + attributeState "lengthyText", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", icon: "st.switches.switch.on", defaultState: true } tileAttribute("device.lengthyText", key: "SECONDARY_CONTROL") { - attributeState "default", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", icon: "st.switches.switch.on" + attributeState "lengthyText", label:'The value of this tile is long and should wrap to two lines', backgroundColor:"#79b821", icon: "st.switches.switch.on", defaultState: true } } multiAttributeTile(name:"multilineTileWithIcon", type:"generic", width:6, height:4) { tileAttribute("device.multilineText", key: "PRIMARY_CONTROL") { - attributeState "default", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", icon: "st.switches.switch.on" + attributeState "multilineText", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", icon: "st.switches.switch.on", defaultState: true } tileAttribute("device.multilineText", key: "SECONDARY_CONTROL") { - attributeState "default", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", icon: "st.switches.switch.on" + attributeState "multilineText", label:'Line 1 YES\nLine 2 YES\nLine 3 NO', backgroundColor:"#79b821", icon: "st.switches.switch.on", defaultState: true } } diff --git a/devicetypes/smartthings/tile-ux/tile-multiattribute-lighting.src/tile-multiattribute-lighting.groovy b/devicetypes/smartthings/tile-ux/tile-multiattribute-lighting.src/tile-multiattribute-lighting.groovy index 6ebbb3e..7ffaabc 100644 --- a/devicetypes/smartthings/tile-ux/tile-multiattribute-lighting.src/tile-multiattribute-lighting.groovy +++ b/devicetypes/smartthings/tile-ux/tile-multiattribute-lighting.src/tile-multiattribute-lighting.groovy @@ -96,10 +96,10 @@ metadata { } standardTile("reset", "device.reset", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { - state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single" + state "reset", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single", defaultState: true } standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { - state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" + state "refresh", label:"", action:"refresh.refresh", icon:"st.secondary.refresh", defaultState: true } main(["switch"]) @@ -173,7 +173,6 @@ def setColor(value) { def reset() { log.debug "Executing 'reset'" setAdjustedColor([level:100, hex:"#90C638", saturation:56, hue:23]) - //parent.poll() } def setAdjustedColor(value) { @@ -189,7 +188,6 @@ def setAdjustedColor(value) { def refresh() { log.debug "Executing 'refresh'" - //parent.manualRefresh() } def adjustOutgoingHue(percent) { @@ -208,4 +206,3 @@ def adjustOutgoingHue(percent) { log.info "percent: $percent, adjusted: $adjusted" adjusted } - diff --git a/devicetypes/smartthings/tile-ux/tile-multiattribute-mediaplayer.src/tile-multiattribute-mediaplayer.groovy b/devicetypes/smartthings/tile-ux/tile-multiattribute-mediaplayer.src/tile-multiattribute-mediaplayer.groovy index b22c3f7..2ad41f4 100644 --- a/devicetypes/smartthings/tile-ux/tile-multiattribute-mediaplayer.src/tile-multiattribute-mediaplayer.groovy +++ b/devicetypes/smartthings/tile-ux/tile-multiattribute-mediaplayer.src/tile-multiattribute-mediaplayer.groovy @@ -37,10 +37,10 @@ metadata { attributeState("stopped", label:"Stopped", action:"music Player.play", nextState: "playing") } tileAttribute("device.status", key: "PREVIOUS_TRACK") { - attributeState("default", action:"music Player.previousTrack") + attributeState("status", action:"music Player.previousTrack", defaultState: true) } tileAttribute("device.status", key: "NEXT_TRACK") { - attributeState("default", action:"music Player.nextTrack") + attributeState("status", action:"music Player.nextTrack", defaultState: true) } tileAttribute ("device.level", key: "SLIDER_CONTROL") { attributeState("level", action:"music Player.setLevel") @@ -50,7 +50,7 @@ metadata { attributeState("muted", action:"music Player.unmute", nextState: "unmuted") } tileAttribute("device.trackDescription", key: "MARQUEE") { - attributeState("default", label:"${currentValue}") + attributeState("trackDescription", label:"${currentValue}", defaultState: true) } } diff --git a/devicetypes/smartthings/tile-ux/tile-multiattribute-thermostat.src/tile-multiattribute-thermostat.groovy b/devicetypes/smartthings/tile-ux/tile-multiattribute-thermostat.src/tile-multiattribute-thermostat.groovy index 6f8d979..6fb57bd 100644 --- a/devicetypes/smartthings/tile-ux/tile-multiattribute-thermostat.src/tile-multiattribute-thermostat.groovy +++ b/devicetypes/smartthings/tile-ux/tile-multiattribute-thermostat.src/tile-multiattribute-thermostat.groovy @@ -32,14 +32,14 @@ metadata { tiles(scale: 2) { multiAttributeTile(name:"thermostatFull", type:"thermostat", width:6, height:4) { tileAttribute("device.temperature", key: "PRIMARY_CONTROL") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("temp", label:'${currentValue}', unit:"dF", defaultState: true) } tileAttribute("device.temperature", key: "VALUE_CONTROL") { attributeState("VALUE_UP", action: "tempUp") attributeState("VALUE_DOWN", action: "tempDown") } tileAttribute("device.humidity", key: "SECONDARY_CONTROL") { - attributeState("default", label:'${currentValue}%', unit:"%") + attributeState("humidity", label:'${currentValue}%', unit:"%", defaultState: true) } tileAttribute("device.thermostatOperatingState", key: "OPERATING_STATE") { attributeState("idle", backgroundColor:"#44b621") @@ -53,15 +53,16 @@ metadata { attributeState("auto", label:'${name}') } tileAttribute("device.heatingSetpoint", key: "HEATING_SETPOINT") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("heatingSetpoint", label:'${currentValue}', unit:"dF", defaultState: true) } tileAttribute("device.coolingSetpoint", key: "COOLING_SETPOINT") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("coolingSetpoint", label:'${currentValue}', unit:"dF", defaultState: true) } } multiAttributeTile(name:"thermostatNoHumidity", type:"thermostat", width:6, height:4) { tileAttribute("device.temperature", key: "PRIMARY_CONTROL") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("coolingSetpoint", label:'${currentValue}', unit:"dF", defaultState: true) + attributeState("temp", label:'${currentValue}', unit:"dF") } tileAttribute("device.temperature", key: "VALUE_CONTROL") { attributeState("VALUE_UP", action: "tempUp") @@ -79,15 +80,16 @@ metadata { attributeState("auto", label:'${name}') } tileAttribute("device.heatingSetpoint", key: "HEATING_SETPOINT") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("coolingSetpoint", label:'${currentValue}', unit:"dF", defaultState: true) + attributeState("heatingSetpoint", label:'${currentValue}', unit:"dF") } tileAttribute("device.coolingSetpoint", key: "COOLING_SETPOINT") { - attributeState("default", label:'${currentValue}', unit:"dF") + attributeState("coolingSetpoint", label:'${currentValue}', unit:"dF", defaultState: true) } } multiAttributeTile(name:"thermostatBasic", type:"thermostat", width:6, height:4) { tileAttribute("device.temperature", key: "PRIMARY_CONTROL") { - attributeState("default", label:'${currentValue}', unit:"dF", + attributeState("temp", label:'${currentValue}', unit:"dF", defaultState: true, backgroundColors:[ [value: 31, color: "#153591"], [value: 44, color: "#1e9cbb"], @@ -118,30 +120,30 @@ metadata { ) } standardTile("tempDown", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'down', action:"tempDown" + state "tempDown", label:'down', action:"tempDown", defaultState: true } standardTile("tempUp", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'up', action:"tempUp" + state "tempUp", label:'up', action:"tempUp", defaultState: true } valueTile("heatingSetpoint", "device.heatingSetpoint", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { state "heat", label:'${currentValue} heat', unit: "F", backgroundColor:"#ffffff" } standardTile("heatDown", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'down', action:"heatDown" + state "heatDown", label:'down', action:"heatDown", defaultState: true } standardTile("heatUp", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'up', action:"heatUp" + state "heatUp", label:'up', action:"heatUp", defaultState: true } valueTile("coolingSetpoint", "device.coolingSetpoint", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { state "cool", label:'${currentValue} cool', unit:"F", backgroundColor:"#ffffff" } standardTile("coolDown", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'down', action:"coolDown" + state "coolDown", label:'down', action:"coolDown", defaultState: true } standardTile("coolUp", "device.temperature", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { - state "default", label:'up', action:"coolUp" + state "coolUp", label:'up', action:"coolUp", defaultState: true } standardTile("mode", "device.thermostatMode", width: 2, height: 2, inactiveLabel: false, decoration: "flat") { diff --git a/smartapps/com-gidjit-smartthings-hub/gidjit-hub.src/gidjit-hub.groovy b/smartapps/com-gidjit-smartthings-hub/gidjit-hub.src/gidjit-hub.groovy new file mode 100644 index 0000000..a1f84b2 --- /dev/null +++ b/smartapps/com-gidjit-smartthings-hub/gidjit-hub.src/gidjit-hub.groovy @@ -0,0 +1,252 @@ +/** + * Gidjit Hub + * + * Copyright 2016 Matthew Page + * + * 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: "Gidjit Hub", + namespace: "com.gidjit.smartthings.hub", + author: "Matthew Page", + description: "Act as an endpoint so user's of Gidjit can quickly access and control their devices and execute routines. Users can do this quickly as Gidjit filters these actions based on their environment", + category: "Convenience", + iconUrl: "http://www.gidjit.com/appicon.png", + iconX2Url: "http://www.gidjit.com/appicon@2x.png", + iconX3Url: "http://www.gidjit.com/appicon@3x.png", + oauth: [displayName: "Gidjit", displayLink: "www.gidjit.com"]) + + + +preferences { + section ("Allow Gidjit to have access, there by allowing you to quickly control and monitor the following devices") { + input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false + input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false + input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade + //input "bulbs", "capability.colorControl", title: "Control your lights", multiple: true, required: false //windowShade + + } +} +mappings { + path("/structureinfo") { + action: [ + GET: "structureInfo" + ] + } + path("/helloactions") { + action: [ + GET: "helloActions" + ] + } + path("/helloactions/:label") { + action: [ + PUT: "executeAction" + ] + } + + path("/switch/:id/:command") { + action: [ + PUT: "updateSwitch" + ] + } + + path("/thermostat/:id/:command") { + action: [ + PUT: "updateThermostat" + ] + } + + path("/windowshade/:id/:command") { + action: [ + PUT: "updateWindowShade" + ] + } + path("/acquiredata/:id") { + action: [ + GET: "acquiredata" + ] + } +} + + +def installed() { + log.debug "Installed with settings: ${settings}" + + initialize() +} + +def updated() { + log.debug "Updated with settings: ${settings}" + + unsubscribe() + initialize() +} + +def initialize() { + // subscribe to attributes, devices, locations, etc. +} +def helloActions() { + def actions = location.helloHome?.getPhrases()*.label + if(!actions) { + return [] + } + return actions +} +def executeAction() { + def actions = location.helloHome?.getPhrases()*.label + def a = actions?.find() { it == params.label } + if (!a) { + httpError(400, "invalid label $params.label") + return + } + location.helloHome?.execute(params.label) +} +/* this is the primary function called to query at the structure and its devices */ +def structureInfo() { //list all devices + def list = [:] + def currId = location.id + list[currId] = [:] + list[currId].name = location.name + list[currId].id = location.id + list[currId].temperatureScale = location.temperatureScale + list[currId].devices = [:] + + def setValues = { + if (params.brief) { + return [id: it.id, name: it.displayName] + } + def newList = [id: it.id, name: it.displayName, suppCapab: it.capabilities.collect { + "$it.name" + }, suppAttributes: it.supportedAttributes.collect { + "$it.name" + }, suppCommands: it.supportedCommands.collect { + "$it.name" + }] + + return newList + } + switches?.each { + list[currId].devices[it.id] = setValues(it) + } + thermostats?.each { + list[currId].devices[it.id] = setValues(it) + } + windowShades?.each { + list[currId].devices[it.id] = setValues(it) + } + + return list + +} +/* This function returns all of the current values of the specified Devices attributes */ +def acquiredata() { + def resp = [:] + if (!params.id) { + httpError(400, "invalid id $params.id") + return + } + def dev = switches.find() { it.id == params.id } ?: windowShades.find() { it.id == params.id } ?: + thermostats.find() { it.id == params.id } + + if (!dev) { + httpError(400, "invalid id $params.id") + return + } + def att = dev.supportedAttributes + att.each { + resp[it.name] = dev.currentValue("$it.name") + } + return resp +} + +void updateSwitch() { + // use the built-in request object to get the command parameter + def command = params.command + def sw = switches.find() { it.id == params.id } + if (!sw) { + httpError(400, "invalid id $params.id") + return + } + switch(command) { + case "on": + if ( sw.currentSwitch != "on" ) { + sw.on() + } + break + case "off": + if ( sw.currentSwitch != "off" ) { + sw.off() + } + break + default: + httpError(400, "$command is not a valid") + } +} + + +void updateThermostat() { + // use the built-in request object to get the command parameter + def command = params.command + def therm = thermostats.find() { it.id == params.id } + if (!therm || !command) { + httpError(400, "invalid id $params.id") + return + } + def passComm = [ + "off", + "heat", + "emergencyHeat", + "cool", + "fanOn", + "fanAuto", + "fanCirculate", + "auto" + + ] + def passNumParamComm = [ + "setHeatingSetpoint", + "setCoolingSetpoint", + ] + def passStringParamComm = [ + "setThermostatMode", + "setThermostatFanMode", + ] + if (command in passComm) { + therm."$command"() + } else if (command in passNumParamComm && params.p1 && params.p1.isFloat()) { + therm."$command"(Float.parseFloat(params.p1)) + } else if (command in passStringParamComm && params.p1) { + therm."$command"(params.p1) + } else { + httpError(400, "$command is not a valid command") + } +} + +void updateWindowShade() { + // use the built-in request object to get the command parameter + def command = params.command + def ws = windowShades.find() { it.id == params.id } + if (!ws || !command) { + httpError(400, "invalid id $params.id") + return + } + def passComm = [ + "open", + "close", + "presetPosition", + ] + if (command in passComm) { + ws."$command"() + } else { + httpError(400, "$command is not a valid command") + } +} +// TODO: implement event handlers \ No newline at end of file diff --git a/smartapps/dianoga/netatmo-connect.src/netatmo-connect.groovy b/smartapps/dianoga/netatmo-connect.src/netatmo-connect.groovy index 905cdde..a127d5b 100644 --- a/smartapps/dianoga/netatmo-connect.src/netatmo-connect.groovy +++ b/smartapps/dianoga/netatmo-connect.src/netatmo-connect.groovy @@ -4,29 +4,33 @@ import java.text.DecimalFormat import groovy.json.JsonSlurper -private apiUrl() { "https://api.netatmo.com" } -private getVendorName() { "netatmo" } -private getVendorAuthPath() { "https://api.netatmo.com/oauth2/authorize?" } -private getVendorTokenPath(){ "https://api.netatmo.com/oauth2/token" } +private getApiUrl() { "https://api.netatmo.com" } +private getVendorName() { "netatmo" } +private getVendorAuthPath() { "${apiUrl}/oauth2/authorize?" } +private getVendorTokenPath(){ "${apiUrl}/oauth2/token" } private getVendorIcon() { "https://s3.amazonaws.com/smartapp-icons/Partner/netamo-icon-1%402x.png" } -private getClientId() { appSettings.clientId } -private getClientSecret() { appSettings.clientSecret } -private getServerUrl() { "https://graph.api.smartthings.com" } +private getClientId() { appSettings.clientId } +private getClientSecret() { appSettings.clientSecret } +private getServerUrl() { appSettings.serverUrl } +private getShardUrl() { return getApiServerUrl() } +private getCallbackUrl() { "${serverUrl}/oauth/callback" } +private getBuildRedirectUrl() { "${serverUrl}/oauth/initialize?appId=${app.id}&access_token=${state.accessToken}&apiServerUrl=${shardUrl}" } // Automatically generated. Make future change here. definition( - name: "Netatmo (Connect)", - namespace: "dianoga", - author: "Brian Steere", - description: "Netatmo Integration", - category: "SmartThings Labs", - iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/netamo-icon-1.png", - iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/netamo-icon-1%402x.png", - oauth: true, - singleInstance: true + name: "Netatmo (Connect)", + namespace: "dianoga", + author: "Brian Steere", + description: "Netatmo Integration", + category: "SmartThings Labs", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/netamo-icon-1.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/netamo-icon-1%402x.png", + oauth: true, + singleInstance: true ){ appSetting "clientId" appSetting "clientSecret" + appSetting "serverUrl" } preferences { @@ -35,35 +39,52 @@ preferences { } mappings { - path("/receivedToken"){action: [POST: "receivedToken", GET: "receivedToken"]} - path("/receiveToken"){action: [POST: "receiveToken", GET: "receiveToken"]} - path("/auth"){action: [GET: "auth"]} + path("/oauth/initialize") {action: [GET: "oauthInitUrl"]} + path("/oauth/callback") {action: [GET: "callback"]} } def authPage() { log.debug "In authPage" - if(canInstallLabs()) { - def description = null - if (state.vendorAccessToken == null) { - log.debug "About to create access token." + def description + def uninstallAllowed = false + def oauthTokenProvided = false - createAccessToken() - description = "Tap to enter Credentials." + if (!state.accessToken) { + log.debug "About to create access token." + state.accessToken = createAccessToken() + } - return dynamicPage(name: "Credentials", title: "Authorize Connection", nextPage:"listDevices", uninstall: true, install:false) { - section { href url:buildRedirectUrl("auth"), style:"embedded", required:false, title:"Connect to ${getVendorName()}:", description:description } + if (canInstallLabs()) { + + def redirectUrl = getBuildRedirectUrl() + log.debug "Redirect url = ${redirectUrl}" + + if (state.authToken) { + description = "Tap 'Next' to proceed" + uninstallAllowed = true + oauthTokenProvided = true + } else { + description = "Click to enter Credentials." + } + + if (!oauthTokenProvided) { + log.debug "Show the login page" + return dynamicPage(name: "Credentials", title: "Authorize Connection", nextPage:"listDevices", uninstall: uninstallAllowed, install:false) { + section() { + paragraph "Tap below to log in to the netatmo and authorize SmartThings access." + href url:redirectUrl, style:"embedded", required:false, title:"Connect to ${getVendorName()}:", description:description + } } } else { - description = "Tap 'Next' to proceed" - - return dynamicPage(name: "Credentials", title: "Credentials Accepted!", nextPage:"listDevices", uninstall: true, install:false) { - section { href url: buildRedirectUrl("receivedToken"), style:"embedded", required:false, title:"${getVendorName()} is now connected to SmartThings!", description:description } + log.debug "Show the devices page" + return dynamicPage(name: "Credentials", title: "Credentials Accepted!", nextPage:"listDevices", uninstall: uninstallAllowed, install:false) { + section() { + input(name:"Devices", style:"embedded", required:false, title:"${getVendorName()} is now connected to SmartThings!", description:description) + } } } - } - else - { + } else { def upgradeNeeded = """To use SmartThings Labs, your Hub should be completely up to date. To update your Hub, access Location Settings in the Main Menu (tap the gear next to your location name), select your Hub, and choose "Update Hub".""" @@ -78,229 +99,175 @@ To update your Hub, access Location Settings in the Main Menu (tap the gear next } } -def auth() { - redirect location: oauthInitUrl() -} - def oauthInitUrl() { log.debug "In oauthInitUrl" - /* OAuth Step 1: Request access code with our client ID */ - state.oauthInitState = UUID.randomUUID().toString() - def oauthParams = [ response_type: "code", - client_id: getClientId(), - state: state.oauthInitState, - redirect_uri: buildRedirectUrl("receiveToken") , - scope: "read_station" - ] - - return getVendorAuthPath() + toQueryString(oauthParams) -} - -def buildRedirectUrl(endPoint) { - log.debug "In buildRedirectUrl" - - return getServerUrl() + "/api/token/${state.accessToken}/smartapps/installations/${app.id}/${endPoint}" -} - -def receiveToken() { - log.debug "In receiveToken" - def oauthParams = [ - client_secret: getClientSecret(), + response_type: "code", client_id: getClientId(), - grant_type: "authorization_code", - redirect_uri: buildRedirectUrl('receiveToken'), - code: params.code, + client_secret: getClientSecret(), + state: state.oauthInitState, + redirect_uri: getCallbackUrl(), scope: "read_station" - ] - - def tokenUrl = getVendorTokenPath() - def params = [ - uri: tokenUrl, - contentType: 'application/x-www-form-urlencoded', - body: oauthParams, ] - log.debug params + log.debug "REDIRECT URL: ${getVendorAuthPath() + toQueryString(oauthParams)}" - /* OAuth Step 2: Request access token with our client Secret and OAuth "Code" */ - try { - httpPost(params) { response -> - log.debug response.data - def slurper = new JsonSlurper(); + redirect (location: getVendorAuthPath() + toQueryString(oauthParams)) +} - response.data.each {key, value -> - def data = slurper.parseText(key); - log.debug "Data: $data" +def callback() { + log.debug "callback()>> params: $params, params.code ${params.code}" - state.vendorRefreshToken = data.refresh_token - state.vendorAccessToken = data.access_token - state.vendorTokenExpires = now() + (data.expires_in * 1000) - return + def code = params.code + def oauthState = params.state + + if (oauthState == state.oauthInitState) { + + def tokenParams = [ + client_secret: getClientSecret(), + client_id : getClientId(), + grant_type: "authorization_code", + redirect_uri: getCallbackUrl(), + code: code, + scope: "read_station" + ] + + log.debug "TOKEN URL: ${getVendorTokenPath() + toQueryString(tokenParams)}" + + def tokenUrl = getVendorTokenPath() + def params = [ + uri: tokenUrl, + contentType: 'application/x-www-form-urlencoded', + body: tokenParams + ] + + log.debug "PARAMS: ${params}" + + httpPost(params) { resp -> + + def slurper = new JsonSlurper() + + resp.data.each { key, value -> + def data = slurper.parseText(key) + + state.refreshToken = data.refresh_token + state.authToken = data.access_token + state.tokenExpires = now() + (data.expires_in * 1000) + log.debug "swapped token: $resp.data" } - } - } catch (Exception e) { - log.debug "Error: $e" + + // Handle success and failure here, and render stuff accordingly + if (state.authToken) { + success() + } else { + fail() + } + + } else { + log.error "callback() failed oauthState != state.oauthInitState" } +} - log.debug "State: $state" +def success() { + log.debug "in success" + def message = """ +
We have located your """ + getVendorName() + """ account.
+Tap 'Done' to continue to Devices.
+ """ + connectionStatus(message) +} - if ( !state.vendorAccessToken ) { //We didn't get an access token, bail on install - return +def fail() { + log.debug "in fail" + def message = """ +The connection could not be established!
+Click 'Done' to return to the menu.
+ """ + connectionStatus(message) +} + +def connectionStatus(message, redirectUrl = null) { + def redirectHtml = "" + if (redirectUrl) { + redirectHtml = """ + + """ } - /* OAuth Step 3: Use the access token to call into the vendor API throughout your code using state.vendorAccessToken. */ - def html = """ - - - - -We have located your """ + getVendorName() + """ account.
-Tap 'Done' to process your credentials.
+ + + + +Tap 'Done' to continue to Devices.
-