Modifying 'LaMetric Time device handler and smart apps'

This commit is contained in:
Nazar Bilous
2016-06-24 11:18:02 -05:00
parent ab61db3699
commit 6e32676fe5
2 changed files with 392 additions and 432 deletions

View File

@@ -15,14 +15,12 @@
* *
*/ */
import groovy.json.JsonOutput
definition( definition(
name: "LaMetric (Connect)", name: "LaMetric (Connect)",
namespace: "com.lametric", namespace: "com.lametric",
author: "Mykola Kirichuk", author: "Mykola Kirichuk",
description: "Lametric connect", description: "Control your LaMetric Time smart display",
category: "Fun & Social", category: "Family",
iconUrl: "https://developer.lametric.com/assets/smart_things/smart_things_60.png", iconUrl: "https://developer.lametric.com/assets/smart_things/smart_things_60.png",
iconX2Url: "https://developer.lametric.com/assets/smart_things/smart_things_120.png", iconX2Url: "https://developer.lametric.com/assets/smart_things/smart_things_120.png",
iconX3Url: "https://developer.lametric.com/assets/smart_things/smart_things_120.png", iconX3Url: "https://developer.lametric.com/assets/smart_things/smart_things_120.png",
@@ -42,6 +40,7 @@ mappings {
path("/oauth/callback") {action: [GET: "callback"]} path("/oauth/callback") {action: [GET: "callback"]}
} }
import groovy.json.JsonOutput
def getEventNameListOfUserDeviceParsed(){ "EventListOfUserRemoteDevicesParsed" } def getEventNameListOfUserDeviceParsed(){ "EventListOfUserRemoteDevicesParsed" }
def getEventNameTokenRefreshed(){ "EventAuthTokenRefreshed" } def getEventNameTokenRefreshed(){ "EventAuthTokenRefreshed" }
@@ -290,7 +289,7 @@ def locationHandler(evt)
if (parsedJsonBody) if (parsedJsonBody)
{ {
log.trace (parsedJsonBody) log.trace (parsedJsonBody)
log.debug("responce for device ${parsedJsonBody?.server_id}") log.debug("responce for device ${parsedJsonBody?.id}")
//put or post response //put or post response
if (parsedJsonBody.success) if (parsedJsonBody.success)
{ {
@@ -298,8 +297,8 @@ def locationHandler(evt)
} else { } else {
//poll response //poll response
log.debug "poll responce" log.debug "poll responce"
log.debug ("poll responce ${parsedJsonBody?.info}") log.debug ("poll responce ${parsedJsonBody}")
def deviceId = parsedJsonBody?.info?.server_id; def deviceId = parsedJsonBody?.id;
if (deviceId) if (deviceId)
{ {
def devices = getDevices(); def devices = getDevices();
@@ -430,27 +429,6 @@ def authPage() {
subscribeNetworkEvents() subscribeNetworkEvents()
listOfUserRemoteDevices() listOfUserRemoteDevices()
return deviceDiscovery(); return deviceDiscovery();
/*
return deviceDiscovery();
def stats = getEcobeeThermostats()
log.debug "thermostat list: $stats"
log.debug "sensor list: ${sensorsDiscovered()}"
return dynamicPage(name: "auth", title: "Select Your Thermostats", uninstall: true) {
section(""){
paragraph "Tap below to see the list of ecobee thermostats available in your ecobee account and select the ones you want to connect to SmartThings."
input(name: "thermostats", title:"", type: "enum", required:true, multiple:true, description: "Tap to choose", metadata:[values:stats])
}
def options = sensorsDiscovered() ?: []
def numFound = options.size() ?: 0
if (numFound > 0) {
section(""){
paragraph "Tap below to see the list of ecobee sensors available in your ecobee account and select the ones you want to connect to SmartThings."
input(name: "ecobeesensors", title:"Select Ecobee Sensors (${numFound} found)", type: "enum", required:false, description: "Tap to choose", multiple:true, options:options)
}
}
}*/
} }
} }
@@ -713,8 +691,8 @@ def connectionStatus(message, redirectUrl = null) {
//****************************************************************************************************************** //******************************************************************************************************************
def getLocalApiDeviceInfoPath() { "/api/v2/info" } def getLocalApiDeviceInfoPath() { "/api/v2/info" }
def getLocalApiSendNotificationPath() { "/api/v2/notifications" } def getLocalApiSendNotificationPath() { "/api/v2/device/notifications" }
def getLocalApiIndexPath() { "/api/v2" } def getLocalApiIndexPath() { "/api/v2/device" }
def getLocalApiUser() { "dev" } def getLocalApiUser() { "dev" }
@@ -765,14 +743,15 @@ def getAllInfoFromDevice(localIp, apiKey)
log.debug "send something" log.debug "send something"
if (localIp && apiKey) if (localIp && apiKey)
{ {
sendHubCommand(new physicalgraph.device.HubAction([ def hubCommand = new physicalgraph.device.HubAction([
method: "GET", method: "GET",
path: localApiIndexPath, path: localApiIndexPath+"?fields=info,wifi,volume,bluetooth,id,name,mode,model,serial_number,os_version",
query:["fields": ["info","wifi", "volume", "bluetooth"]],
headers: [ headers: [
HOST: "${localIp}:8080", HOST: "${localIp}:8080",
Authorization: "Basic ${"${localApiUser}:${apiKey}".bytes.encodeBase64()}" Authorization: "Basic ${"${localApiUser}:${apiKey}".bytes.encodeBase64()}"
]])) ]])
log.debug "sending request ${hubCommand}"
sendHubCommand(hubCommand)
} }
} }
//****************************************************************************************************************** //******************************************************************************************************************
@@ -837,13 +816,7 @@ void listOfUserRemoteDevices()
log.debug ("empty device info") log.debug ("empty device info")
} }
} }
// state.remoteDevices = remoteDevices;
verifyDevices(); verifyDevices();
// return
// def serializedData = new JsonOutput().toJson(notification);
// app.sendEvent(name: "EventListOfUserRemoteDevicesParsed", value: serializedData)
// app.sendEvent(name: "parsed", value: true)
// log.debug "Sending 'save new list' event ${result}"
} else { } else {
log.debug "http status: ${resp.status}" log.debug "http status: ${resp.status}"
} }

View File

@@ -20,8 +20,8 @@ definition(
name: "LaMetric Notifier", name: "LaMetric Notifier",
namespace: "com.lametric", namespace: "com.lametric",
author: "Mykola Kirichuk", author: "Mykola Kirichuk",
description: "Notify about changes with sound and message on your LaMetric", description: "Allows you to send notifications to your LaMetric Time when something happens in your home to notify the whole family.",
category: "Fun & Social", category: "Family",
iconUrl: "https://developer.lametric.com/assets/smart_things/weather_60.png", iconUrl: "https://developer.lametric.com/assets/smart_things/weather_60.png",
iconX2Url: "https://developer.lametric.com/assets/smart_things/weather_120.png", iconX2Url: "https://developer.lametric.com/assets/smart_things/weather_120.png",
iconX3Url: "https://developer.lametric.com/assets/smart_things/weather_120.png") iconX3Url: "https://developer.lametric.com/assets/smart_things/weather_120.png")
@@ -388,21 +388,8 @@ def eventHandler(evt) {
if (allOk) { if (allOk) {
log.trace "allOk" log.trace "allOk"
// def lastTime = state[frequencyKey(evt)]
// if (oncePerDayOk(lastTime)) {
/*
if (frequency) {
if (lastTime == null || now() - lastTime >= frequency * 60000) {
takeAction(evt) takeAction(evt)
} }
else {
log.debug "Not taking action because $frequency minutes have not elapsed since last action"
}
/* }
else {*/
takeAction(evt)
// }
}
else { else {
log.debug "Not taking action because it was already taken today" log.debug "Not taking action because it was already taken today"
} }