From 8561a95d14179d42597190b33aeebc819936eb05 Mon Sep 17 00:00:00 2001 From: gussery3 Date: Mon, 4 Apr 2016 19:24:49 -0400 Subject: [PATCH 1/3] Update to provide amazon echo support --- .../myq-garage-door-opener.groovy | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/devicetypes/copy-ninja/myq-garage-door-opener.src/myq-garage-door-opener.groovy b/devicetypes/copy-ninja/myq-garage-door-opener.src/myq-garage-door-opener.groovy index 37ba5d91..eec84a57 100644 --- a/devicetypes/copy-ninja/myq-garage-door-opener.src/myq-garage-door-opener.groovy +++ b/devicetypes/copy-ninja/myq-garage-door-opener.src/myq-garage-door-opener.groovy @@ -12,8 +12,10 @@ * 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. * - * Last Updated : 7/15/2015 - * + * Last Updated : 4/4/2016 + * + * 20160404 - Modified by Gene Ussery - Perform refresh before running on or off functions. Added logic to push to only run open if the garage is closed + * and run closed if the garage is open or stopped. */ metadata { definition (name: "MyQ Garage Door Opener", namespace: "copy-ninja", author: "Jason Mok") { @@ -66,35 +68,44 @@ metadata { def parse(String description) {} def on() { - push() + log.debug("Running On") + refresh() + push("open") sendEvent(name: "button", value: "on", isStateChange: true, display: false, displayed: false) } def off() { + log.debug("Running Off") + refresh() + push("closed") sendEvent(name: "button", value: "off", isStateChange: true, display: false, displayed: false) } -def push() { +def push(String desiredstate) { + log.debug("Running Push") def doorState = device.currentState("door")?.value - if (doorState == "open" || doorState == "stopped") { + if ((doorState == "open" || doorState == "stopped") && desiredstate == "closed") { close() - } else if (doorState == "closed") { + } else if (doorState == "closed" && desiredstate == "open") { open() } sendEvent(name: "momentary", value: "pushed", display: false, displayed: false) } def open() { + log.debug("Running Open") parent.sendCommand(this, "desireddoorstate", 1) updateDeviceStatus(4) updateDeviceLastActivity(parent.getDeviceLastActivity(this)) } def close() { + log.debug("Running Close") parent.sendCommand(this, "desireddoorstate", 0) updateDeviceStatus(5) updateDeviceLastActivity(parent.getDeviceLastActivity(this)) } def refresh() { + log.debug("Running Refresh") parent.refresh() updateDeviceLastActivity(parent.getDeviceLastActivity(this)) } @@ -103,6 +114,7 @@ def poll() { refresh() } // update status def updateDeviceStatus(status) { + log.debug("Running UpdateStatus") def currentState = device.currentState("door")?.value if (status == "1" || status == "9") { sendEvent(name: "door", value: "open", display: true, descriptionText: device.displayName + " is open") @@ -125,6 +137,7 @@ def updateDeviceStatus(status) { } def updateDeviceLastActivity(long lastActivity) { + log.debug("Running UpdateLastActivity") def lastActivityValue = "" def diffTotal = now() - lastActivity def diffDays = (diffTotal / 86400000) as long @@ -141,4 +154,4 @@ def updateDeviceLastActivity(long lastActivity) { else if (diffMins > 1) lastActivityValue += "${diffMins} Mins" sendEvent(name: "lastActivity", value: lastActivityValue, display: false , displayed: false) -} +} \ No newline at end of file From 03101cca0261bca1fa936ce1cfbc12f788b41ff6 Mon Sep 17 00:00:00 2001 From: gussery3 Date: Wed, 15 Feb 2017 13:15:48 -0500 Subject: [PATCH 2/3] Update myq-connect.groovy --- .../myq-connect.src/myq-connect.groovy | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy b/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy index 9db9d341..e4c163f2 100644 --- a/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy +++ b/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy @@ -12,8 +12,9 @@ * 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. * - * Last Updated : 03/08/2016 + * Last Updated : 02/15/2017 * + * 20170215 - Gene Ussery - Changed to work with API changes from Chamberlain */ definition( name: "MyQ (Connect)", @@ -161,7 +162,10 @@ private forceLogin() { private login() { return (!(state.session.expiration > now())) ? doLogin() : true } private doLogin() { - apiGet("/api/user/validate", [username: settings.username, password: settings.password] ) { response -> +// apiGet("/api/v4/user/validate", [username: settings.username, password: settings.password] ) { response -> + + apiPost("/api/v4/user/validate", [username: settings.username, password: settings.password] ) { response -> + log.debug "got login response data: ${response.data}" if (response.status == 200) { if (response.data.SecurityToken != null) { state.session.brandID = response.data.BrandId @@ -282,6 +286,18 @@ private apiPut(apiPath, apiBody = [], callback = {}) { } } +// HTTP POST call +private apiPost(apiPath, apiBody = [], callback = {}) { + if (state.session.securityToken) { apiBody = apiBody + [SecurityToken: state.session.securityToken ] } + + try { + httpPost([ uri: getApiURL(), path: apiPath, contentType: "application/json; charset=utf-8", body: apiBody, + headers: [MyQApplicationId: getApiAppID()], ]) { response -> callback(response) } + } catch (SocketException e) { + //sendAlert("API Error: $e") + log.debug "API Error: $e" + } +} // Updates data for devices private updateDeviceData() { // automatically checks if the token has expired, if so login again From 98e42a0ff96ef1a983a20bb21fdc7f29e786fb10 Mon Sep 17 00:00:00 2001 From: gussery3 Date: Wed, 15 Feb 2017 13:39:27 -0500 Subject: [PATCH 3/3] Update myq-connect.groovy --- smartapps/copy-ninja/myq-connect.src/myq-connect.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy b/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy index e4c163f2..ac677bfc 100644 --- a/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy +++ b/smartapps/copy-ninja/myq-connect.src/myq-connect.groovy @@ -22,9 +22,9 @@ definition( author: "Jason Mok", description: "Connect MyQ to control your devices", category: "SmartThings Labs", - iconUrl: "http://smartthings.copyninja.net/icons/MyQ@1x.png", - iconX2Url: "http://smartthings.copyninja.net/icons/MyQ@2x.png", - iconX3Url: "http://smartthings.copyninja.net/icons/MyQ@3x.png" + iconUrl: "https://s3.amazonaws.com/gu-smartapp-icons/myq.png", + iconX2Url: "https://s3.amazonaws.com/gu-smartapp-icons/myq@2x.png", + iconX3Url: "https://s3.amazonaws.com/gu-smartapp-icons/myq@3x.png" ) preferences {