diff --git a/js/component/card/comparison_settings.js b/js/component/card/comparison_settings.js index 67d58a3..d630eac 100644 --- a/js/component/card/comparison_settings.js +++ b/js/component/card/comparison_settings.js @@ -4,10 +4,11 @@ * @param {number} thermostat_id The thermostat_id this card is displaying * data for. */ -beestat.component.card.comparison_settings = function(thermostat_id) { - var self = this; - - this.thermostat_id_ = thermostat_id; +beestat.component.card.comparison_settings = function(thermostat_id) { + var self = this; + + this.thermostat_id_ = thermostat_id; + this.get_data_in_flight_ = false; /* * If the thermostat changes that means the property_type could change and @@ -89,31 +90,36 @@ beestat.component.card.comparison_settings.prototype.decorate_contents_ = functi api.send(); }, 10000); } else { - if (thermostat.profile === null) { - this.show_loading_('Fetching'); - new beestat.api() - .add_call( - 'thermostat', - 'generate_profile', - { - 'thermostat_id': this.thermostat_id_ - } - ) - .add_call( - 'thermostat', - 'read_id', - { - 'attributes': { - 'inactive': 0 - } - }, - 'thermostat' - ) - .set_callback(function(response) { - beestat.cache.set('thermostat', response.thermostat); - }) - .send(); - } else if (beestat.cache.data.metrics === undefined) { + if (thermostat.profile === null) { + this.show_loading_('Fetching'); + if (this.get_data_in_flight_ === false) { + this.get_data_in_flight_ = true; + + new beestat.api() + .add_call( + 'thermostat', + 'generate_profile', + { + 'thermostat_id': this.thermostat_id_ + } + ) + .add_call( + 'thermostat', + 'read_id', + { + 'attributes': { + 'inactive': 0 + } + }, + 'thermostat' + ) + .set_callback(function(response) { + this.get_data_in_flight_ = false; + beestat.cache.set('thermostat', response.thermostat); + }.bind(this)) + .send(); + } + } else if (beestat.cache.data.metrics === undefined) { this.show_loading_('Fetching'); new beestat.api() .add_call( diff --git a/js/component/card/temperature_profiles.js b/js/component/card/temperature_profiles.js index 9488c51..3fc2846 100644 --- a/js/component/card/temperature_profiles.js +++ b/js/component/card/temperature_profiles.js @@ -4,8 +4,9 @@ * @param {number} thermostat_id The thermostat_id this card is displaying * data for. */ -beestat.component.card.temperature_profiles = function(thermostat_id) { - this.thermostat_id_ = thermostat_id; +beestat.component.card.temperature_profiles = function(thermostat_id) { + this.thermostat_id_ = thermostat_id; + this.get_data_in_flight_ = false; var self = this; @@ -47,7 +48,7 @@ beestat.component.card.temperature_profiles.prototype.decorate_subtitle_ = funct * * @param {rocket.Elements} parent */ -beestat.component.card.temperature_profiles.prototype.decorate_contents_ = function(parent) { +beestat.component.card.temperature_profiles.prototype.decorate_contents_ = function(parent) { var container = $.createElement('div').style({ 'position': 'relative' }); @@ -58,7 +59,7 @@ beestat.component.card.temperature_profiles.prototype.decorate_contents_ = funct var chart_container = $.createElement('div'); container.appendChild(chart_container); - if (this.has_data_() === false) { + if (this.has_data_() === false) { chart_container.style('filter', 'blur(3px)'); var no_data = $.createElement('div'); no_data.style({ @@ -182,37 +183,43 @@ beestat.component.card.temperature_profiles.prototype.get_data_ = function() { var profiles = this.get_profiles_(); var is_current = (this.profile_index_ === undefined || this.profile_index_ === profiles.length - 1); - if ( - is_current && - ( - selected_profile === null || - moment().diff(moment(selected_profile.metadata.generated_at), 'days') >= 7 - ) - ) { - this.show_loading_('Fetching'); - new beestat.api() - .add_call( - 'thermostat', - 'generate_profile', - { - 'thermostat_id': this.thermostat_id_ - } - ) - .add_call( - 'thermostat', - 'read_id', - { - 'attributes': { - 'inactive': 0 - } - }, - 'thermostat' - ) - .set_callback(function(response) { - beestat.cache.set('thermostat', response.thermostat); - }) - .send(); - } else if (selected_profile !== null) { + if ( + is_current && + ( + selected_profile === null || + moment().diff(moment(selected_profile.metadata.generated_at), 'days') >= 7 + ) + ) { + this.show_loading_('Fetching'); + + if (this.get_data_in_flight_ === false) { + this.get_data_in_flight_ = true; + + new beestat.api() + .add_call( + 'thermostat', + 'generate_profile', + { + 'thermostat_id': this.thermostat_id_ + } + ) + .add_call( + 'thermostat', + 'read_id', + { + 'attributes': { + 'inactive': 0 + } + }, + 'thermostat' + ) + .set_callback(function(response) { + this.get_data_in_flight_ = false; + beestat.cache.set('thermostat', response.thermostat); + }.bind(this)) + .send(); + } + } else if (selected_profile !== null) { const profile_extremes = this.get_profile_extremes_(5); var y_min = Infinity; @@ -552,7 +559,7 @@ beestat.component.card.temperature_profiles.prototype.get_selected_profile_ = fu * * @return {boolean} */ -beestat.component.card.temperature_profiles.prototype.has_data_ = function() { - const data = this.get_data_(); - return Object.keys(data.series).length > 0; -}; +beestat.component.card.temperature_profiles.prototype.has_data_ = function() { + const data = this.get_data_(); + return Object.keys(data.series).length > 0; +};