From ad7fe5d9b7fd54683afd44900921509465d32da9 Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Tue, 20 Sep 2022 08:21:49 -0400 Subject: [PATCH] Updated compare tab to support area unit setting --- js/beestat/area.js | 13 ++++++++++--- js/component/card/my_home.js | 7 ++++++- js/component/floor_plan.js | 2 ++ js/component/metric.js | 12 ++++++++++++ js/component/metric/property/square_feet.js | 19 +++++++++++-------- js/component/tile/floor_plan.js | 1 + js/component/tile/floor_plan_group.js | 1 + 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/js/beestat/area.js b/js/beestat/area.js index cf581e0..a929578 100644 --- a/js/beestat/area.js +++ b/js/beestat/area.js @@ -5,7 +5,7 @@ * area (required) - area to work with * output_area_unit (optional, default ft) - Output area unit; default matches setting. * convert (optional, default true) - Whether or not to convert to Celcius if necessary - * round (optional, default 1) - Number of decimal points to round to + * round (optional, default 0) - Number of decimal points to round to * units (optional, default false) - Whether or not to include units in the result * type (optional, default number) - Type of value to return (string|number) * @@ -19,12 +19,15 @@ beestat.area = function(args) { }; } - const input_area_unit = 'in²'; + var input_area_unit = beestat.default_value( + args.input_area_unit, + 'ft²' + ); var output_area_unit = beestat.default_value( args.output_area_unit, beestat.setting('units.area') ); - var round = beestat.default_value(args.round, 1); + var round = beestat.default_value(args.round, 0); var units = beestat.default_value(args.units, false); var type = beestat.default_value(args.type, 'number'); @@ -39,6 +42,10 @@ beestat.area = function(args) { 'in²': { 'ft²': 0.00694444, 'm²': 0.00064516 + }, + 'ft²': { + 'in²': 144, + 'm²': 0.092903 } }; diff --git a/js/component/card/my_home.js b/js/component/card/my_home.js index 117ad66..51f0ef8 100644 --- a/js/component/card/my_home.js +++ b/js/component/card/my_home.js @@ -186,7 +186,12 @@ beestat.component.card.my_home.prototype.decorate_property_ = function(parent) { .set_background_color(beestat.style.color.purple.base) .set_text_color('#fff') .set_icon('view_quilt') - .set_text(Number(thermostat.property.square_feet).toLocaleString() + ' ft²')); + .set_text(beestat.area({ + 'area': thermostat.property.square_feet, + 'units': true, + 'round': 0 + })) + ); } if (thermostat.property.age !== null) { diff --git a/js/component/floor_plan.js b/js/component/floor_plan.js index 1c0d652..c6ef5cb 100644 --- a/js/component/floor_plan.js +++ b/js/component/floor_plan.js @@ -658,6 +658,7 @@ beestat.component.floor_plan.prototype.update_infobox = function() { parts.push(this.state_.active_room_entity.get_room().name || 'Unnamed Room'); parts.push( beestat.area({ + 'input_area_unit': 'in²', 'area': beestat.floor_plan.get_area_room(this.state_.active_room_entity.get_room()), 'round': 0, 'units': true @@ -667,6 +668,7 @@ beestat.component.floor_plan.prototype.update_infobox = function() { parts.push(this.state_.active_group.name || 'Unnamed Floor'); parts.push( beestat.area({ + 'input_area_unit': 'in²', 'area': beestat.floor_plan.get_area_group(this.state_.active_group), 'round': 0, 'units': true diff --git a/js/component/metric.js b/js/component/metric.js index 94ef988..e8e4103 100644 --- a/js/component/metric.js +++ b/js/component/metric.js @@ -6,6 +6,14 @@ beestat.component.metric = function() { }; beestat.extend(beestat.component.metric, beestat.component); +/** + * Whether or not this is an area value. If so, do the appropriate conversion + * on display. + * + * @type {boolean} + */ +beestat.component.metric.prototype.is_area_ = false; + /** * Whether or not this is a temperature value. If so, do the appropriate * conversion on display. @@ -249,6 +257,10 @@ beestat.component.metric.prototype.get_formatter_ = function() { 'temperature': value, 'delta': self.is_temperature_delta_ }); + } else if (self.is_area_ === true) { + return_value = beestat.area({ + 'area': value + }); } return return_value.toFixed(self.get_precision_()) + self.get_units_(); }; diff --git a/js/component/metric/property/square_feet.js b/js/component/metric/property/square_feet.js index 73a40dd..39eeca3 100644 --- a/js/component/metric/property/square_feet.js +++ b/js/component/metric/property/square_feet.js @@ -12,13 +12,15 @@ beestat.extend(beestat.component.metric.property.square_feet, beestat.component. beestat.component.metric.property.square_feet.prototype.child_metric_name_ = 'square_feet'; +beestat.component.metric.property.square_feet.prototype.is_area_ = true; + /** * Get the units for this metric. * * @return {string} The units for this metric. */ beestat.component.metric.property.square_feet.prototype.get_units_ = function() { - return 'ft²'; + return beestat.setting('units.area'); }; /** @@ -27,10 +29,11 @@ beestat.component.metric.property.square_feet.prototype.get_units_ = function() * @return {mixed} A function that formats the string. */ beestat.component.metric.property.square_feet.prototype.get_formatter_ = function() { - var self = this; - - return function(value, precision) { - return value.toLocaleString() + self.get_units_(); + return function(value) { + return beestat.area({ + 'area': value, + 'units': true + }); }; }; @@ -40,7 +43,7 @@ beestat.component.metric.property.square_feet.prototype.get_formatter_ = functio * @return {string} The title of this metric. */ beestat.component.metric.property.square_feet.prototype.get_title_ = function() { - return 'Square Feet'; + return 'Area'; }; /** @@ -59,7 +62,7 @@ beestat.component.metric.property.square_feet.prototype.get_icon_ = function() { * @return {object} The cutoff value. */ beestat.component.metric.property.square_feet.prototype.get_cutoff_min_ = function() { - return 500; + return beestat.setting('units.area') === 'ft²' ? 500 : 50; }; /** @@ -68,5 +71,5 @@ beestat.component.metric.property.square_feet.prototype.get_cutoff_min_ = functi * @return {number} The interval. */ beestat.component.metric.property.square_feet.prototype.get_interval_ = function() { - return 500; + return beestat.setting('units.area') === 'ft²' ? 500 : 50; }; diff --git a/js/component/tile/floor_plan.js b/js/component/tile/floor_plan.js index 030bbf7..5290c01 100644 --- a/js/component/tile/floor_plan.js +++ b/js/component/tile/floor_plan.js @@ -33,6 +33,7 @@ beestat.component.tile.floor_plan.prototype.get_text_ = function() { line_2_parts.push(floor_count + (floor_count === 1 ? ' Floor' : ' Floors')); line_2_parts.push( beestat.area({ + 'input_area_unit': 'in²', 'area': beestat.floor_plan.get_area(this.floor_plan_id_), 'round': 0, 'units': true diff --git a/js/component/tile/floor_plan_group.js b/js/component/tile/floor_plan_group.js index 9563e87..7499d27 100644 --- a/js/component/tile/floor_plan_group.js +++ b/js/component/tile/floor_plan_group.js @@ -30,6 +30,7 @@ beestat.component.tile.floor_plan_group.prototype.get_text_ = function() { line_2_parts.push(room_count + (room_count === 1 ? ' Room' : ' Rooms')); line_2_parts.push( beestat.area({ + 'input_area_unit': 'in²', 'area': beestat.floor_plan.get_area_group(this.floor_plan_group_), 'round': 0, 'units': true