1
0
mirror of https://github.com/beestat/app.git synced 2025-07-09 03:04:07 -04:00

Updated compare tab to support area unit setting

This commit is contained in:
Jon Ziebell 2022-09-20 08:21:49 -04:00
parent 88ad7fc177
commit ad7fe5d9b7
7 changed files with 43 additions and 12 deletions

View File

@ -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
}
};

View File

@ -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) {

View File

@ -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

View File

@ -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_();
};

View File

@ -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;
};

View File

@ -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

View File

@ -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