Skip to content

Commit

Permalink
Added $twcweather using data from The Weather Company via SmartThings…
Browse files Browse the repository at this point in the history
… getTwc* functions
  • Loading branch information
idpaterson committed Feb 19, 2019
1 parent 569cd3e commit d2d4e94
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dashboard/js/modules/piston.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4870,7 +4870,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
var dq = false;
var dv = false;
var startIndex = i;
function isCompositeVariable() {return (str.substr(startIndex, 6) == '$args.') || (str.substr(startIndex, 6) == '$json.') || (str.substr(startIndex, 10) == '$response.') || (str.substr(startIndex, 5) == '$nfl.') || (str.substr(startIndex, 8) == '$places.') || (str.substr(startIndex, 9) == '$weather.') || (str.substr(startIndex, 11) == '$incidents.') || (str.substr(startIndex, 6) == '$args[') || (str.substr(startIndex, 6) == '$json[') || (str.substr(startIndex, 8) == '$places[') || (str.substr(startIndex, 10) == '$response[') || (str.substr(startIndex, 11) == '$incidents[');};
function isCompositeVariable() {return (str.substr(startIndex, 6) == '$args.') || (str.substr(startIndex, 6) == '$json.') || (str.substr(startIndex, 10) == '$response.') || (str.substr(startIndex, 5) == '$nfl.') || (str.substr(startIndex, 8) == '$places.') || (str.substr(startIndex, 9) == '$weather.') || (str.substr(startIndex, 12) == '$twcweather.') || (str.substr(startIndex, 11) == '$incidents.') || (str.substr(startIndex, 6) == '$args[') || (str.substr(startIndex, 6) == '$json[') || (str.substr(startIndex, 8) == '$places[') || (str.substr(startIndex, 10) == '$response[') || (str.substr(startIndex, 11) == '$incidents[');};
function addOperand() {
if (i-1 > startIndex) {
var value = str.slice(startIndex, i-1).trim();
Expand Down Expand Up @@ -5192,6 +5192,7 @@ config.controller('piston', ['$scope', '$rootScope', 'dataService', '$timeout',
if (item.x.startsWith('$response[') && (item.x.length > 10)) break;
if (item.x.startsWith('$nfl.') && (item.x.length > 5)) break;
if (item.x.startsWith('$weather.') && (item.x.length > 9)) break;
if (item.x.startsWith('$twcweather.') && (item.x.length > 12)) break;
if (item.x.startsWith('$incidents.') && (item.x.length > 11)) break;
if (item.x.startsWith('$incidents[') && (item.x.length > 11)) break;
if ($scope.systemVars && $scope.systemVars[item.x]) break;
Expand Down
29 changes: 29 additions & 0 deletions smartapps/ady624/webcore-piston.src/webcore-piston.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4980,6 +4980,31 @@ private Map getWeather(rtData, name) {
return getJsonData(rtData, rtData.weather, name)
}

private Map getTwcWeather(rtData, name) {
List parts = name.tokenize('.');
rtData.twcWeather = rtData.twcWeather ?: [:]
if (parts.size() > 0) {
def dataFeature = parts[0]
if (rtData.twcWeather[dataFeature] == null) {
switch (dataFeature) {
case 'alerts':
rtData.twcWeather[dataFeature] = app.getTwcAlerts()?.alerts
break
case 'conditions':
rtData.twcWeather[dataFeature] = app.getTwcConditions()
break
case 'forecast':
rtData.twcWeather[dataFeature] = app.getTwcForecast()
break
case 'location':
rtData.twcWeather[dataFeature] = app.getTwcLocation()?.location
break
}
}
}
return getJsonData(rtData, rtData.twcWeather, name)
}

private Map getNFLDataFeature(dataFeature) {
def requestParams = [
uri: "https://api.webcore.co/nfl/$dataFeature",
Expand Down Expand Up @@ -5052,6 +5077,8 @@ private Map getVariable(rtData, name) {
result = getNFL(rtData, name.substring(5))
} else if (name.startsWith('$weather.') && (name.size() > 9)) {
result = getWeather(rtData, name.substring(9))
} else if (name.startsWith('$twcweather.') && (name.size() > 12)) {
result = getTwcWeather(rtData, name.substring(12))
} else if (name.startsWith('$incidents.') && (name.size() > 11)) {
result = getIncidents(rtData, name.substring(11))
} else if (name.startsWith('$incidents[') && (name.size() > 11)) {
Expand Down Expand Up @@ -7843,6 +7870,7 @@ private static Map getSystemVariables() {
'$places': [t: "dynamic", d: true],
'$response': [t: "dynamic", d: true],
'$weather': [t: "dynamic", d: true],
'$twcweather': [t: "dynamic", d: true],
'$nfl': [t: "dynamic", d: true],
'$incidents': [t: "dynamic", d: true],
'$shmTripped': [t: "boolean", d: true],
Expand Down Expand Up @@ -7931,6 +7959,7 @@ private getSystemVariableValue(rtData, name) {
case '$places': return "${rtData.settings?.places}".toString()
case '$response': return "${rtData.response}".toString()
case '$weather': return "${rtData.weather}".toString()
case '$twcweather': return "${rtData.twcWeather}".toString()
case '$nfl': return "${rtData.nfl}".toString()
case '$incidents': return "${rtData.incidents}".toString()
case '$shmTripped': initIncidents(rtData); return !!((rtData.incidents instanceof List) && (rtData.incidents.size()))
Expand Down

0 comments on commit d2d4e94

Please sign in to comment.