/**
* Hubigraph Timeline Child App
*
* Copyright 2020, but let's behonest, you'll copy it
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* 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.
*
*/
// Hubigraph Gauge Change Log
// V 0.1 Intial release
// V 1.0 Released (not Beta) Cleanup and Preview Enabled
// V 1.5 Ordering, Color and Common API Update
// V 1.8 Smoother sliders, bug fixes
import groovy.json.JsonOutput
import java.text.DecimalFormat;
def ignoredEvents() { return [ 'lastReceive' , 'reachable' ,
'buttonReleased' , 'buttonPressed', 'lastCheckinDate', 'lastCheckin', 'buttonHeld' ] }
def version() { return "v0.22" }
definition(
name: "Hubigraph Gauge",
namespace: "tchoward",
author: "Thomas Howard",
description: "Hubigraph Gauge",
category: "",
parent: "tchoward:Hubigraphs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
)
preferences {
section ("test"){
page(name: "mainPage", install: true, uninstall: true)
page(name: "deviceSelectionPage", nextPage: "mainPage")
page(name: "attributeConfigurationPage", nextPage: "mainPage")
page(name: "graphSetupPage", nextPage: "mainPage")
page(name: "enableAPIPage")
page(name: "disableAPIPage")
}
mappings {
path("/graph/") {
action: [
GET: "getGraph"
]
}
}
path("/getData/") {
action: [
GET: "getData"
]
}
path("/getOptions/") {
action: [
GET: "getOptions"
]
}
path("/getSubscriptions/") {
action: [
GET: "getSubscriptions"
]
}
}
def call(Closure code) {
code.setResolveStrategy(Closure.DELEGATE_ONLY);
code.setDelegate(this);
code.call();
}
def extractNumber( String input ) {
val = input.findAll( /-?\d+\.\d*|-?\d*\.\d+|-?\d+/ )*.toDouble()
val[0]
}
def deviceSelectionPage() {
def supported_attrs;
dynamicPage(name: "deviceSelectionPage") {
parent.hubiForm_section(this,"Device Selection", 1){
input "sensor_", "capability.*", title: "Sensor", multiple: false, required: true, submitOnChange: true
container = [];
if (sensor_) {
attributes_ = sensor_.getSupportedAttributes();
final_attrs = [];
attributes_.each{attribute_->
final_attrs += attribute_.getName();
}
container << parent.hubiForm_sub_section(this,"""${sensor_.getDisplayName()}""")
if (final_attrs == []){
container<< parent.hubiForm_text(this, "No supported Numerical Attributes
Please select a different Sensor");
parent.hubiForm_container(this, container, 1);
} else {
input( type: "enum", name: "attribute_", title: "Attribute for Gauge", required: true, multiple: false, options: final_attrs, defaultValue: "1", submitOnChange: true)
}
}
}
if (attribute_){
state_ = sensor_.currentState(attribute_);
if (state_ != null) {
currentValue = state_.value;
parent.hubiForm_section(this, "Min Max Value", 1){
container = [];
container<< parent.hubiForm_text(this, "Current Value = $currentValue");
container << parent.hubiForm_text_input (this, "Minimum Value for Gauge", "minValue_", "0", false);
container << parent.hubiForm_text_input (this, "Maximum Value for Gauge", "maxValue_", "100", false);
parent.hubiForm_container(this, container, 1);
}
} else {
container = [];
paragraph "No recent valid events
Please select a different Attribute"
parent.hubiForm_container(this, container, 1);
}
}
}
}
def graphSetupPage(){
def fontEnum = [["1":"1"], ["2":"2"], ["3":"3"], ["4":"4"], ["5":"5"], ["6":"6"], ["7":"7"], ["8":"8"], ["9":"9"], ["10":"10"],
["11":"11"], ["12":"12"], ["13":"13"], ["14":"14"], ["15":"15"], ["16":"16"], ["17":"17"], ["18":"18"], ["19":"19"], ["20":"20"]];
def highlightEnum = [[0:"0"], [1:"1"], [2:"2"], [3:"3"]];
def num_;
dynamicPage(name: "graphSetupPage") {
parent.hubiForm_section(this,"General Options", 1){
container = [];
container << parent.hubiForm_text_input (this, "Gauge Title", "gauge_title", "Gauge Title", false);
container << parent.hubiForm_text_input (this, "Gauge Units", "gauge_units", "Units", false);
container << parent.hubiForm_text_input (this, "Gauge Number Formatting
Example", "gauge_number_format", "##.#", false);
container << parent.hubiForm_slider (this, title: "Select Number of Highlight Areas on Gauge", name: "num_highlights", default_value: 3, min: 0, max: 3, units: " highlights", submit_on_change: true);
parent.hubiForm_container(this, container, 1);
}
if (num_highlights == null){
settings["num_highlights"] = 3;
num_ = 3;
} else {
num_ = num_highlights.toInteger();
}
if (num_ > 0){
parent.hubiForm_section(this,"HighLight Regions", 1){
container = [];
for (i=0; i