diff --git a/js/beestat/thermostat.js b/js/beestat/thermostat.js index 8e36674..37f1a33 100644 --- a/js/beestat/thermostat.js +++ b/js/beestat/thermostat.js @@ -57,3 +57,43 @@ beestat.thermostat.data_synced = function(thermostat_id, required_sync_begin, re current_sync_end.isSameOrAfter(required_sync_end) === true ); }; + +/** + * Helper function to get any system type. + * + * @param {number} thermostat_id + * @param {string} mode heat|auxiliary_heat|cool + * + * @return {string} The system type. + */ +beestat.thermostat.get_system_type = function(thermostat_id, mode) { + const thermostat = beestat.cache.thermostat[thermostat_id]; + + if (thermostat.system_type2.reported[mode].equipment !== null) { + return thermostat.system_type2.reported[mode].equipment; + } else if (thermostat.system_type2.detected[mode].equipment !== null) { + return thermostat.system_type2.detected[mode].equipment; + } + + return 'unknown'; +}; + +/** + * Helper function to get any stages. + * + * @param {number} thermostat_id + * @param {string} mode heat|auxiliary_heat|cool + * + * @return {string} The system type. + */ +beestat.thermostat.get_stages = function(thermostat_id, mode) { + const thermostat = beestat.cache.thermostat[thermostat_id]; + + if (thermostat.system_type2.reported[mode].stages !== null) { + return thermostat.system_type2.reported[mode].stages; + } else if (thermostat.system_type2.detected[mode].stages !== null) { + return thermostat.system_type2.detected[mode].stages; + } + + return 'unknown'; +}; diff --git a/js/component/card/my_home.js b/js/component/card/my_home.js index e3b5bca..c73e573 100644 --- a/js/component/card/my_home.js +++ b/js/component/card/my_home.js @@ -30,17 +30,18 @@ beestat.component.card.my_home.prototype.decorate_system_type_ = function(parent (new beestat.component.title('System')).render(parent); - var heat = thermostat_group.system_type_heat !== null - ? thermostat_group.system_type_heat - : 'unknown'; - - var heat_auxiliary = thermostat_group.system_type_heat_auxiliary !== null - ? thermostat_group.system_type_heat_auxiliary - : 'unknown'; - - var cool = thermostat_group.system_type_cool !== null - ? thermostat_group.system_type_cool - : 'unknown'; + const heat = beestat.thermostat.get_system_type( + thermostat.thermostat_id, + 'heat' + ); + const heat_auxiliary = beestat.thermostat.get_system_type( + thermostat.thermostat_id, + 'heat_auxiliary' + ); + const cool = beestat.thermostat.get_system_type( + thermostat.thermostat_id, + 'cool' + ); var button_group = new beestat.component.button_group(); button_group.add_button(new beestat.component.button() diff --git a/js/component/modal/change_system_type.js b/js/component/modal/change_system_type.js index 3a6567d..7fd3c9a 100644 --- a/js/component/modal/change_system_type.js +++ b/js/component/modal/change_system_type.js @@ -56,7 +56,10 @@ beestat.component.modal.change_system_type.prototype.decorate_contents_ = functi for (let key in options) { (new beestat.component.title(titles[key])).render(parent); - let current_type = thermostat_group['system_type_' + key]; + let current_type = beestat.thermostat.get_system_type( + thermostat.thermostat_id, + key + ); let button_group = new beestat.component.button_group(); options[key].forEach(function(system_type) { diff --git a/js/layer/load.js b/js/layer/load.js index 2986ba5..d258f8d 100644 --- a/js/layer/load.js +++ b/js/layer/load.js @@ -170,10 +170,10 @@ beestat.layer.load.prototype.decorate_ = function(parent) { beestat.setting('temperature_unit', thermostat.temperature_unit); // Rename series if only one stage is available. - if (ecobee_thermostat.settings.coolStages === 1) { + if (beestat.thermostat.get_stages(thermostat.thermostat_id, 'cool') === 1) { beestat.series.sum_compressor_cool_1.name = 'Cool'; } - if (ecobee_thermostat.settings.heatStages === 1) { + if (beestat.thermostat.get_stages(thermostat.thermostat_id, 'heat') === 1) { beestat.series.sum_compressor_heat_1.name = 'Heat'; }