diff --git a/js/beestat/temperature.js b/js/beestat/temperature.js index 588a255..0f9aa90 100644 --- a/js/beestat/temperature.js +++ b/js/beestat/temperature.js @@ -5,6 +5,8 @@ * * @param {object} args Instructions on how to format: * temperature (required) - Temperature to work with + * input_temperature_unit (optional, default °F) - Input temperature unit + * output_temperature_unit (optional, default °F|°C) - Input temperature unit; default matches setting. * convert (optional, default true) - Whether or not to convert to Celcius if necessary * delta (optional, default false) - Whether or not the convert action is for a delta instead of a normal value * round (optional, default 1) - Number of decimal points to round to @@ -21,7 +23,14 @@ beestat.temperature = function(args) { }; } - var convert = beestat.default_value(args.convert, true); + var input_temperature_unit = beestat.default_value( + args.input_temperature_unit, + '°F' + ); + var output_temperature_unit = beestat.default_value( + args.output_temperature_unit, + beestat.setting('temperature_unit') + ); var delta = beestat.default_value(args.delta, false); var round = beestat.default_value(args.round, 1); var units = beestat.default_value(args.units, false); @@ -35,11 +44,19 @@ beestat.temperature = function(args) { } // Convert to Celcius if necessary and asked for. - if (convert === true && beestat.setting('temperature_unit') === '°C') { - if (delta === true) { - temperature *= (5 / 9); - } else { - temperature = (temperature - 32) * (5 / 9); + if (input_temperature_unit !== output_temperature_unit) { + if (input_temperature_unit === '°F') { + if (delta === true) { + temperature *= (5 / 9); + } else { + temperature = (temperature - 32) * (5 / 9); + } + } else if (input_temperature_unit === '°C') { + if (delta === true) { + temperature *= (9 / 5); + } else { + temperature = (temperature * (9 / 5)) + 32; + } } } @@ -62,7 +79,7 @@ beestat.temperature = function(args) { // Append units if asked for. if (units === true) { - temperature += beestat.setting('temperature_unit'); + temperature += output_temperature_unit; } return temperature; diff --git a/js/component/card/three_d.js b/js/component/card/three_d.js index ba199d8..46c09fb 100644 --- a/js/component/card/three_d.js +++ b/js/component/card/three_d.js @@ -103,7 +103,6 @@ beestat.component.card.three_d.prototype.decorate_contents_ = function(parent) { parent.appendChild(controls_container); this.decorate_controls_(controls_container); - // var thermostat = beestat.cache.thermostat[this.thermostat_id_]; let required_begin; diff --git a/js/component/card/visualize_settings.js b/js/component/card/visualize_settings.js index e840438..00490a5 100644 --- a/js/component/card/visualize_settings.js +++ b/js/component/card/visualize_settings.js @@ -150,21 +150,65 @@ beestat.component.card.visualize_settings.prototype.decorate_heat_map_type_ = fu parent.appendChild(min_max_container); const min = new beestat.component.input.text() - .set_value(beestat.setting( - 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.min') + .set_maxlength('5') + .set_requirements({ + 'type': 'decimal', + 'required': true + }) + .set_value( + beestat.temperature(beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.min' + )) ) .set_width(50); min.addEventListener('change', function() { - beestat.setting('visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.min', min.get_value()); + if (min.meets_requirements() === true) { + beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.min', + beestat.temperature({ + 'temperature': min.get_value(), + 'input_temperature_unit': beestat.setting('temperature_unit'), + 'output_temperature_unit': '°F' + }) + ); + } else { + min.set_value( + beestat.temperature(beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.min' + )) + ); + } }); const max = new beestat.component.input.text() - .set_value(beestat.setting( - 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.max') + .set_maxlength('5') + .set_requirements({ + 'type': 'decimal', + 'required': true + }) + .set_value( + beestat.temperature(beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.max' + )) ) .set_width(50); max.addEventListener('change', function() { - beestat.setting('visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.max', max.get_value()); + if (max.meets_requirements() === true) { + beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.max', + beestat.temperature({ + 'temperature': max.get_value(), + 'input_temperature_unit': beestat.setting('temperature_unit'), + 'output_temperature_unit': '°F' + }) + ); + } else { + max.set_value( + beestat.temperature(beestat.setting( + 'visualize.heat_map_absolute.' + beestat.setting('visualize.data_type') + '.max' + )) + ); + } }); let span; diff --git a/js/component/chart/runtime_sensor_detail_temperature.js b/js/component/chart/runtime_sensor_detail_temperature.js index 7eaedf5..2a0a1d4 100644 --- a/js/component/chart/runtime_sensor_detail_temperature.js +++ b/js/component/chart/runtime_sensor_detail_temperature.js @@ -230,7 +230,7 @@ beestat.component.chart.runtime_sensor_detail_temperature.prototype.get_options_ } else { value = beestat.temperature({ 'temperature': point.value, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true }); point_value = point.value; diff --git a/js/component/chart/runtime_thermostat_detail_temperature.js b/js/component/chart/runtime_thermostat_detail_temperature.js index 19cef54..b66602b 100644 --- a/js/component/chart/runtime_thermostat_detail_temperature.js +++ b/js/component/chart/runtime_thermostat_detail_temperature.js @@ -288,7 +288,7 @@ beestat.component.chart.runtime_thermostat_detail_temperature.prototype.get_opti value = beestat.temperature({ 'temperature': value, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true }); } else if (point.series_code.includes('humidity') === true) { diff --git a/js/component/chart/runtime_thermostat_summary.js b/js/component/chart/runtime_thermostat_summary.js index decbde5..c3d7ec5 100755 --- a/js/component/chart/runtime_thermostat_summary.js +++ b/js/component/chart/runtime_thermostat_summary.js @@ -234,14 +234,14 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_tooltip ) { value = beestat.temperature({ 'temperature': values.min_outdoor_temperature, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true, 'round': 0 }); value += ' to '; value += beestat.temperature({ 'temperature': values.max_outdoor_temperature, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true, 'round': 0 }); @@ -252,7 +252,7 @@ beestat.component.chart.runtime_thermostat_summary.prototype.get_options_tooltip color = point.series.color; value = beestat.temperature({ 'temperature': values.avg_outdoor_temperature, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true, 'round': 0 }); diff --git a/js/component/chart/temperature_profiles.js b/js/component/chart/temperature_profiles.js index 6b6963d..d71d806 100644 --- a/js/component/chart/temperature_profiles.js +++ b/js/component/chart/temperature_profiles.js @@ -296,7 +296,7 @@ beestat.component.chart.temperature_profiles.prototype.get_options_tooltip_forma var value = beestat.temperature({ 'temperature': point.y, 'units': true, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'delta': true, 'type': 'string' }) + ' / h'; @@ -321,7 +321,7 @@ beestat.component.chart.temperature_profiles.prototype.get_options_tooltip_forma 'temperature': this.x, 'round': 0, 'units': true, - 'convert': false + 'input_temperature_unit': beestat.setting('temperature_unit') }), sections ); @@ -380,7 +380,7 @@ beestat.component.chart.temperature_profiles.prototype.get_options_xAxis_ = func 'useHTML': true, 'text': 'Now: ' + beestat.temperature({ 'temperature': this.data_.metadata.chart.outdoor_temperature, - 'convert': false, + 'input_temperature_unit': beestat.setting('temperature_unit'), 'units': true, 'round': 0 }) diff --git a/js/component/input.js b/js/component/input.js index 119e6a2..3329802 100644 --- a/js/component/input.js +++ b/js/component/input.js @@ -79,6 +79,9 @@ beestat.component.input.prototype.meets_requirements = function() { case 'integer': this.requirements_.regexp = /^-?\d+$/; break; + case 'decimal': + this.requirements_.regexp = /^-?\d+(?:\.\d+)?$/; + break; } if (