Skip to content

Commit

Permalink
Updates for HE webCoRE
Browse files Browse the repository at this point in the history
Support for local fuel streams (app.js)
Support for HE endpoint access token format
Ability to execute rules on HE
  • Loading branch information
imnotbob committed Jun 1, 2019
1 parent 3573bec commit e8dbced
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 29 deletions.
109 changes: 85 additions & 24 deletions dashboard/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,21 +1375,50 @@ 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
}
}
}
return $http(req).then(function(response) {
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;
});
}
}
}

Expand Down Expand Up @@ -1438,21 +1467,53 @@ 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
}
}
}
return $http(req).then(function(response) {
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;
});
}
}
}

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
28 changes: 24 additions & 4 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 @@ -759,6 +759,9 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
case 'routine':
item.i = $scope.instance.virtualDevices['routine'].o;
break;
case 'rule':
item.i = $scope.instance.virtualDevices['rule'].o;
break;
}
}

Expand Down Expand Up @@ -853,7 +856,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 @@ -2500,6 +2503,13 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
return null;
}

$scope.getRuleById = function(ruleId) {
if ($scope.instance.virtualDevices.rule && $scope.instance.virtualDevices.rule.o) {
return $scope.instance.virtualDevices.rule.o[ruleId];
}
return null;
}

$scope.getLocationModeById = function(locationModeId) {
if ($scope.instance.virtualDevices.mode && $scope.instance.virtualDevices.mode.o) {
return $scope.instance.virtualDevices.mode.o[locationModeId];
Expand Down Expand Up @@ -3129,6 +3139,10 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
operand.multiple = true;
dataType = 'routine';
}
if (dataType == 'rules') {
operand.multiple = true;
dataType = 'rule';
}
if (dataType == 'attributes') {
operand.multiple = true;
dataType = 'attribute';
Expand Down Expand Up @@ -3192,7 +3206,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
break;
}

var disableExpressions = (!!operand.disableExpressions) || (dataType == 'piston') || (dataType == 'routine') || (dataType == 'askAlexaMacro') || (dataType == 'attribute')
var disableExpressions = (!!operand.disableExpressions) || (dataType == 'piston') || (dataType == 'routine') || (dataType == 'rule') || (dataType == 'askAlexaMacro') || (dataType == 'attribute')
operand.onlyAllowConstants = operand.onlyAllowConstants || disableExpressions

var strict = !!operand.strict;
Expand Down Expand Up @@ -3276,6 +3290,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
case 'mode':
case 'powerSource':
case 'alarmSystemStatus':
case 'rule':
case 'routine':
operand.options = $scope.objectToArray($scope.instance.virtualDevices[dataType].o);
break;
Expand Down Expand Up @@ -4464,6 +4479,11 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
object = anonymizeValue(object, {t: 'routine'});
return object;
}
var rule = $scope.getRuleById(object);
if (rule) {
object = anonymizeValue(object, {t: 'rule'});
return object;
}
var contact = $scope.getContactById(object);
if (contact) {
object = anonymizeValue(object, {t: 'contact'});
Expand Down Expand Up @@ -5378,4 +5398,4 @@ function test(value, parseAsString, dataType) {
scope.evaluateExpression(scope.parseExpression(value, parseAsString, dataType));
}

var MAX_STACK_SIZE = 10;
var MAX_STACK_SIZE = 10;

0 comments on commit e8dbced

Please sign in to comment.