Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubitat smarthings merge #70

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3eb8129
Update webcore-dashboard.groovy
ajayjohn Mar 25, 2018
078f1ad
Update webcore-piston.groovy
ajayjohn Mar 25, 2018
48d5408
Update webcore-storage.groovy
ajayjohn Mar 25, 2018
6b23e57
Update webcore.groovy
ajayjohn Mar 25, 2018
6c604c3
Update webcore-piston.groovy
ajayjohn Mar 25, 2018
da6f7f7
Fix piston pause, delete, schedules, and dash
jp0550 Mar 28, 2018
5a98729
Support routine events
jp0550 Apr 9, 2018
71748cc
Hubitat button implementation
jp0550 Apr 9, 2018
2a020ea
Fix momentary capability
jp0550 Apr 9, 2018
f9fe08b
Support custom urls
jp0550 Apr 9, 2018
796f7a4
Fix non https local urls
jp0550 Apr 13, 2018
9e19adf
Add colors
jp0550 Apr 13, 2018
e01ce0f
Fix for virtual flash, and looser restrictions on timing
jp0550 Apr 16, 2018
9acafbd
Start porting hsm
jp0550 Apr 9, 2018
6d084ab
Fix execute links
jp0550 May 4, 2018
504d40c
Disable registration and fuel stream testing
jp0550 May 4, 2018
d13aa07
Fix dashboard js error
jp0550 May 5, 2018
680d659
Add back missing line to fix save state error
jp0550 May 7, 2018
575b7f4
Fix UTC offset issues in relation to restrictions and variables
jp0550 May 23, 2018
5f1fb86
Fix ifttt
jp0550 May 29, 2018
99f8338
Performance improvements and timeout fixes for cloud
jp0550 Jun 26, 2018
693ff3f
Dashboard async, Custom Endpoint dynamic UI, Data saver remote only
jp0550 Jul 19, 2018
b8377c6
Merge remote-tracking branch 'ady624/master' into hubitat-patches
jp0550 Jul 19, 2018
663b81f
Fix npe on routine phrases
jp0550 Jul 19, 2018
d8cfdb6
Hsm Changes
jp0550 Aug 2, 2018
77f1e05
Merge remote-tracking branch 'ady/master' into hubitat-hsm
jp0550 Aug 2, 2018
e17d20a
Change version and add fallback for installed method
jp0550 Aug 5, 2018
769b7ba
Hsm fixes
jp0550 Aug 6, 2018
e35ca9b
Add support for hsm rule arm/disarming
jp0550 Aug 6, 2018
7340d72
Merge remote-tracking branch 'ady624/master' into hubitat-dev
jp0550 Aug 7, 2018
5fefc65
Null check on stats
jp0550 Aug 8, 2018
f504c05
Common codebase
jp0550 Aug 13, 2018
df2eec6
Use app per fuelstream
jp0550 Aug 13, 2018
c0259e7
Work around ST parent state/app bug
jp0550 Aug 13, 2018
f4114f2
Fix location id = 1 for Hubitat
jp0550 Aug 13, 2018
fcc066f
Merge remote-tracking branch 'ady/master' into hubitat-dev
jp0550 Aug 14, 2018
02cf0cc
Fix flash commands
jp0550 Aug 14, 2018
d2bb739
Fix fuel stream trimming
jp0550 Aug 14, 2018
6dc1ffd
Disable dashboard
jp0550 Aug 14, 2018
1f507ab
Hide instance url message
jp0550 Aug 14, 2018
571a88f
Merge branch 'hubitat-dev' into hubitat-patches
jp0550 Aug 14, 2018
c029cc8
Enable smartthings compatibility
jp0550 Aug 14, 2018
ac1ddb7
Fix null pointer on first write for Hubitat
jp0550 Aug 19, 2018
c806d5e
Remove unsupported methods
jp0550 Aug 21, 2018
eddbb68
Reduce fuel stream size
jp0550 Aug 21, 2018
05aea0d
Add logs for missing setting
jp0550 Aug 21, 2018
74d417f
Add HSM api changes
jp0550 Aug 21, 2018
c94d11e
Fix hsmStatus evaluation
jp0550 Aug 22, 2018
be31359
Remove debug statement
jp0550 Aug 23, 2018
91173cd
Performance improvements
jp0550 Aug 26, 2018
970035d
Remove hubUID references
jp0550 Aug 26, 2018
2ef00db
Fix ST Import format
jp0550 Aug 26, 2018
f64c7e5
Fix global variable subscriptions and add higher log limit
jp0550 Aug 26, 2018
d043dd0
Fix method call
jp0550 Aug 26, 2018
3fea6a2
Fix NPE on Protocol
jp0550 Aug 26, 2018
ae488e3
Merge branch 'hubitat-dev' into hubitat-smarthings-merge
jp0550 Aug 26, 2018
c65cf36
Fix default fuel streams
jp0550 Aug 27, 2018
a02305b
Check null settings before migrating
jp0550 Aug 28, 2018
c310be5
Add select all devices category
jp0550 Aug 28, 2018
af532c2
Add safer timeToday method for Hubitat
jp0550 Aug 29, 2018
1d7a94f
Don't fail on http exception
jp0550 Sep 4, 2018
69c9854
Merge remote-tracking branch 'ady624/master' into hubitat-dev
jp0550 Sep 6, 2018
b5cefd4
Merge remote-tracking branch 'ady624/master' into hubitat-dev
jp0550 Sep 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 92 additions & 29 deletions dashboard/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
if (!si || !si.token) {
if ((app.initialInstanceUri && app.initialInstanceUri.length) || (uri && uri.length)) {
uri = app.initialInstanceUri ? app.initialInstanceUri : uri;
if (!uri.startsWith('https://')) {
if (!uri.startsWith('https://') && !uri.startsWith('http://')) {
if (uri && (uri.indexOf('tat.comapi') > 0)) {
var parts = uri.split('api');
if (parts[1].length >= 33) {
Expand Down Expand Up @@ -1375,21 +1375,51 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
dataService.listFuelStreams = function() {
var instance = dataService.getInstance();
if (instance) {
var iid = instance.id;
var si = store[instance.id];
if (!si) si = {};
var region = (si && si.uri && si.uri.startsWith('https://graph-eu')) ? 'eu' : 'us';
var req = {
method: 'POST',
url: 'https://api-' + region + '-' + iid[32] + '.webcore.co:9287/fuelStreams/list',
headers: {
'Auth-Token': '|'+ iid
},
data: { i: iid }
var urls = instance.fuelStreamUrls;
var jsonp = false;
var req;

if(urls){
var params = urls.list;

if(params.l){
jsonp = true;
req = params.u;
}
else {
req = {
method: params.m,
url: params.u,
headers: params.h,
data: params.d
}
}
}
else {
var iid = instance.id;
var si = store[instance.id];
if (!si) si = {};
var region = (si && si.uri && si.uri.startsWith('https://graph-eu')) ? 'eu' : 'us';
req = {
method: 'POST',
url: 'https://api-' + region + '-' + iid[32] + '.webcore.co:9287/fuelStreams/list',
headers: {
'Auth-Token': '|'+ iid
},
data: { i: iid }
}
}

if(jsonp){
return $http.jsonp(req,{jsonpCallbackParam: 'callback'}).then(function(response) {
return response.data;
});
}
else {
return $http(req).then(function(response) {
return response.data;
});
}
return $http(req).then(function(response) {
return response.data;
});
}
}

Expand Down Expand Up @@ -1438,21 +1468,54 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
dataService.listFuelStreamData = function(fuelStreamId) {
var instance = dataService.getInstance();
if (instance) {
var iid = instance.id;
var si = store[instance.id];
if (!si) si = {};
var region = (si && si.uri && si.uri.startsWith('https://graph-eu')) ? 'eu' : 'us';
var req = {
method: 'POST',
url: 'https://api-' + region + '-' + iid[32] + '.webcore.co:9287/fuelStreams/get',
headers: {
'Auth-Token': '|'+iid
},
data: { i: iid, f: fuelStreamId }
var urls = instance.fuelStreamUrls;
var jsonp = false;
var req;

if(urls){
var params = urls.get;

if(params.l){
jsonp = true;
req = params.u.replace("{" + params.p + "}", fuelStreamId);
}
else {
var data = params.d
data[params.p] = fuelStreamId;

req = {
method: params.m,
url: params.u,
headers: params.h,
data: data
}
}
}
else {
var iid = instance.id;
var si = store[instance.id];
if (!si) si = {};
var region = (si && si.uri && si.uri.startsWith('https://graph-eu')) ? 'eu' : 'us';
req = {
method: 'POST',
url: 'https://api-' + region + '-' + iid[32] + '.webcore.co:9287/fuelStreams/get',
headers: {
'Auth-Token': '|'+iid
},
data: { i: iid, f: fuelStreamId }
}
}

if(jsonp){
return $http.jsonp(req,{jsonpCallbackParam: 'callback'}).then(function(response) {
return response.data;
});
}
else {
return $http(req).then(function(response) {
return response.data;
});
}
return $http(req).then(function(response) {
return response.data;
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion dashboard/js/modules/dashboard.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ config.controller('dashboard', ['$scope', '$rootScope', 'dataService', '$timeout
if ($scope.$$destroyed) return;
if (currentRequestId != $scope.requestId) { return };
if (data) {
$scope.endpoint=data.endpoint + 'execute/:pistonId:';
$scope.endpoint=data.endpoint + 'execute/:pistonId:' + (data.accessToken ? '?access_token=' + data.accessToken : '');
$scope.rawEndpoint=data.endpoint;
$scope.rawAccessToken=data.accessToken;
if (data.error) {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/js/modules/piston.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
if ($scope.piston) $scope.loading = true;
dataService.getPiston($scope.pistonId).then(function (response) {
if ($scope.$$destroyed) return;
$scope.endpoint = data.endpoint + 'execute/' + $scope.pistonId;
$scope.endpoint = data.endpoint + 'execute/' + $scope.pistonId + (si.accessToken ? '?access_token=' + si.accessToken : '');
try {
var showOptions = $scope.piston ? !!$scope.showOptions : false;
if (!response || !response.data || !response.data.piston) {
Expand Down Expand Up @@ -853,7 +853,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
$scope.getIFTTTUri = function(eventName) {
var uri = dataService.getApiUri();
if (!uri) return "An error has occurred retrieving the IFTTT Maker URL";
return uri + 'ifttt/' + eventName;
return uri + 'ifttt/' + eventName + (si.accessToken ? '?access_token=' + si.accessToken : '');
}

$scope.toggleAdvancedOptions = function() {
Expand Down Expand Up @@ -5377,4 +5377,4 @@ function test(value, parseAsString, dataType) {
scope.evaluateExpression(scope.parseExpression(value, parseAsString, dataType));
}

var MAX_STACK_SIZE = 10;
var MAX_STACK_SIZE = 10;
34 changes: 21 additions & 13 deletions smartapps/ady624/webcore-dashboard.src/webcore-dashboard.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static String version() { return "v0.3.108.20180906" }
/*** webCoRE DEFINITION ***/
/******************************************************************************/
private static String handle() { return "webCoRE" }
include 'asynchttp_v1'
if(!isHubitat())include 'asynchttp_v1'
definition(
name: "${handle()} Dashboard",
namespace: "ady624",
Expand Down Expand Up @@ -147,17 +147,21 @@ private void broadcastEvent(deviceId, eventName, eventValue, eventTime) {
def iid = state.instanceId
def region = state.region ?: 'us'
if (!iid || !iid.startsWith(':') || !iid.endsWith(':')) return
asynchttp_v1.put(null, [
uri: "https://api-${region}-${iid[32]}.webcore.co:9237",
path: '/event/sink',
headers: ['ST' : state.instanceId],
body: [
d: deviceId,
n: eventName,
v: eventValue,
t: eventTime
]
])

def params = [
uri: "https://api-${region}-${iid[32]}.webcore.co:9237",
path: '/event/sink',
requestContentType: "application/json",
headers: ['ST' : state.instanceId],
body: [d: deviceId, n: eventName, v: eventValue, t: eventTime]
]

if(asynchttp_v1){
asynchttp_v1.put(null, params)
}
//else {
// asynchttpPut((String)null, params)
//}
}

/******************************************************************************/
Expand Down Expand Up @@ -191,8 +195,12 @@ def String hashId(id) {
return result
}

private isHubitat(){
return hubUID != null
}

/******************************************************************************/
/*** ***/
/*** END OF CODE ***/
/*** ***/
/******************************************************************************/
/******************************************************************************/
111 changes: 111 additions & 0 deletions smartapps/ady624/webcore-fuel-stream.src/webcore-fuel-stream.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
private static String handle() { return "webCoRE" }
definition(
namespace:"ady624",
name:"${handle()} Fuel Stream",
description: "Local container for fuel streams",
author:"jp0550",
category:"My Apps",
iconUrl: "https://cdn.rawgit.com/ady624/${handle()}/master/resources/icons/app-CoRE.png",
iconX2Url: "https://cdn.rawgit.com/ady624/${handle()}/master/resources/icons/[email protected]",
iconX3Url: "https://cdn.rawgit.com/ady624/${handle()}/master/resources/icons/[email protected]",
parent: "ady624:webCoRE"
)

preferences {
page(name: "settingsPage")
}

def settingsPage(){
dynamicPage(name: "settingsPage", title: "Settings", uninstall: true, install: true){
section(){
input "maxSize", "number", title: "Max size of all fuelStream data in KB", defaultValue: 95

def storageSize = (int)(state.toString().size() / 1024.0)
paragraph("Current memory usage is ${storageSize}KB")
}
}
}

def installed(){
log.debug "Installed with settings $settings"
initialize()
}

def updated(){
log.debug "Updated with settings $settings"
initialize()
}

def createStream(settings){
state.fuelStream = [i: settings.id, c: (settings.canister ?: ""), n: settings.name, w: 1, t: getFormattedDate(new Date())]
}

def initialize(){
unsubscribe()
unschedule()

if(app.id){
getFuelStreamData()
cleanFuelStreams()
}
}

def getFuelStreamData(){
if(!state.fuelStreamData){
state.fuelStreamData = []
}
return state.fuelStreamData
}

def cleanFuelStreams(){
//ensure max size is obeyed
def storageSize = (int)(state.toString().size() / 1024.0)
def max = (settings.maxSize ?: 95).toInteger()

if(storageSize > max){
log.debug "Trim down fuel stream"
def points = getFuelStreamData().size()
def averageSize = points > 0 ? storageSize/(double)points : 0

def pointsToRemove = averageSize > 0 ? (int)((storageSize - max) / (double)averageSize) : 0
pointsToRemove = pointsToRemove > 0 ? pointsToRemove : 0

log.debug "Size ${storageSize}KB Points ${points} Avg $averageSize Remove $pointsToRemove"
def toBeRemoved = getFuelStreamData().sort { it.i }.take(pointsToRemove)
getFuelStreamData().removeAll(toBeRemoved)
}

getFuelStreamData().each {
it.keySet().remove('t')
}
}

def updateFuelStream(req){
def canister = req.c ?: ""
def name = req.n
def data = req.d
def instance = req.i
def source = req.s

getFuelStreamData().add([d: data, i: (new Date()).getTime()])

cleanFuelStreams()
}

def getFormattedDate(date = new Date()){
def format = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
format.format(date)
}

def getFuelStream(){
state.fuelStream
}

def listFuelStreamData(){
getFuelStreamData().collect{ it + [t: getFormattedDate(new Date(it.i))]}
}

def uninstalled(){
parent.resetFuelStreamList()
}
Loading