mirror of
https://github.com/beestat/app.git
synced 2025-05-31 20:26:32 -04:00
Fixed #320 - Profiles don't always generate and sometimes break GUI
This commit is contained in:
parent
2ae9a05963
commit
ae3a72c791
@ -243,7 +243,7 @@ class thermostat extends cora\crud {
|
|||||||
* @param int $thermostat_id
|
* @param int $thermostat_id
|
||||||
*/
|
*/
|
||||||
public function generate_profile($thermostat_id) {
|
public function generate_profile($thermostat_id) {
|
||||||
return $this->update([
|
$this->update([
|
||||||
'thermostat_id' => $thermostat_id,
|
'thermostat_id' => $thermostat_id,
|
||||||
'profile' => $this->api('profile', 'generate', $thermostat_id)
|
'profile' => $this->api('profile', 'generate', $thermostat_id)
|
||||||
]);
|
]);
|
||||||
|
@ -88,16 +88,24 @@ beestat.component.card.comparison_settings.prototype.decorate_contents_ = functi
|
|||||||
|
|
||||||
api.send();
|
api.send();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
} else if (beestat.cache.data.metrics === undefined) {
|
|
||||||
this.show_loading_('Fetching');
|
|
||||||
} else {
|
} else {
|
||||||
if (thermostat.profile === null) {
|
if (thermostat.profile === null) {
|
||||||
|
this.show_loading_('Fetching');
|
||||||
new beestat.api()
|
new beestat.api()
|
||||||
.add_call(
|
.add_call(
|
||||||
'thermostat',
|
'thermostat',
|
||||||
'generate_profile',
|
'generate_profile',
|
||||||
{
|
{
|
||||||
'thermostat_id': this.thermostat_id_
|
'thermostat_id': this.thermostat_id_
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.add_call(
|
||||||
|
'thermostat',
|
||||||
|
'read_id',
|
||||||
|
{
|
||||||
|
'attributes': {
|
||||||
|
'inactive': 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'thermostat'
|
'thermostat'
|
||||||
)
|
)
|
||||||
@ -105,6 +113,21 @@ beestat.component.card.comparison_settings.prototype.decorate_contents_ = functi
|
|||||||
beestat.cache.set('thermostat', response.thermostat);
|
beestat.cache.set('thermostat', response.thermostat);
|
||||||
})
|
})
|
||||||
.send();
|
.send();
|
||||||
|
} else if (beestat.cache.data.metrics === undefined) {
|
||||||
|
this.show_loading_('Fetching');
|
||||||
|
new beestat.api()
|
||||||
|
.add_call(
|
||||||
|
'thermostat',
|
||||||
|
'get_metrics',
|
||||||
|
{
|
||||||
|
'thermostat_id': this.thermostat_id_,
|
||||||
|
'attributes': beestat.comparisons.get_attributes()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.set_callback(function(response) {
|
||||||
|
beestat.cache.set('data.metrics', response);
|
||||||
|
})
|
||||||
|
.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -27,20 +27,6 @@ beestat.component.card.metrics = function(thermostat_id) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
beestat.component.card.apply(this, arguments);
|
beestat.component.card.apply(this, arguments);
|
||||||
|
|
||||||
new beestat.api()
|
|
||||||
.add_call(
|
|
||||||
'thermostat',
|
|
||||||
'get_metrics',
|
|
||||||
{
|
|
||||||
'thermostat_id': this.thermostat_id_,
|
|
||||||
'attributes': beestat.comparisons.get_attributes()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.set_callback(function(response) {
|
|
||||||
beestat.cache.set('data.metrics', response);
|
|
||||||
})
|
|
||||||
.send();
|
|
||||||
};
|
};
|
||||||
beestat.extend(beestat.component.card.metrics, beestat.component.card);
|
beestat.extend(beestat.component.card.metrics, beestat.component.card);
|
||||||
|
|
||||||
@ -196,6 +182,11 @@ beestat.component.card.metrics.prototype.decorate_top_right_ = function(parent)
|
|||||||
beestat.component.card.metrics.prototype.get_subtitle_ = function() {
|
beestat.component.card.metrics.prototype.get_subtitle_ = function() {
|
||||||
const thermostat = beestat.cache.thermostat[this.thermostat_id_];
|
const thermostat = beestat.cache.thermostat[this.thermostat_id_];
|
||||||
|
|
||||||
|
// If the profile has not yet been generated.
|
||||||
|
if (thermostat.profile === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const generated_at_m = moment(
|
const generated_at_m = moment(
|
||||||
thermostat.profile.metadata.generated_at
|
thermostat.profile.metadata.generated_at
|
||||||
);
|
);
|
||||||
@ -214,7 +205,7 @@ beestat.component.card.metrics.prototype.get_subtitle_ = function() {
|
|||||||
} else {
|
} else {
|
||||||
duration_text += duration_weeks + ' weeks';
|
duration_text += duration_weeks + ' weeks';
|
||||||
}
|
}
|
||||||
duration_text += ' of data.';
|
duration_text += ' of data';
|
||||||
|
|
||||||
return 'Generated ' + generated_at_m.format('MMM Do @ h a') + ' (updated weekly) ' + duration_text;
|
return 'Generated ' + generated_at_m.format('MMM Do @ h a') + duration_text + ' (updated weekly).';
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Temperature profiles.
|
* Temperature Profiles.
|
||||||
*
|
*
|
||||||
* @param {number} thermostat_id The thermostat_id this card is displaying
|
* @param {number} thermostat_id The thermostat_id this card is displaying
|
||||||
* data for.
|
* data for.
|
||||||
@ -7,6 +7,22 @@
|
|||||||
beestat.component.card.temperature_profiles = function(thermostat_id) {
|
beestat.component.card.temperature_profiles = function(thermostat_id) {
|
||||||
this.thermostat_id_ = thermostat_id;
|
this.thermostat_id_ = thermostat_id;
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Debounce so that multiple setting changes don't re-trigger the same
|
||||||
|
* event. This fires on the trailing edge so that all changes are accounted
|
||||||
|
* for when rerendering.
|
||||||
|
*/
|
||||||
|
var change_function = beestat.debounce(function() {
|
||||||
|
self.rerender();
|
||||||
|
}, 10);
|
||||||
|
|
||||||
|
beestat.dispatcher.addEventListener(
|
||||||
|
['cache.thermostat'],
|
||||||
|
change_function
|
||||||
|
);
|
||||||
|
|
||||||
beestat.component.card.apply(this, arguments);
|
beestat.component.card.apply(this, arguments);
|
||||||
};
|
};
|
||||||
beestat.extend(beestat.component.card.temperature_profiles, beestat.component.card);
|
beestat.extend(beestat.component.card.temperature_profiles, beestat.component.card);
|
||||||
@ -49,8 +65,29 @@ beestat.component.card.temperature_profiles.prototype.get_data_ = function() {
|
|||||||
if (
|
if (
|
||||||
thermostat.profile === null
|
thermostat.profile === null
|
||||||
) {
|
) {
|
||||||
this.chart_.render(parent);
|
|
||||||
this.show_loading_('Fetching');
|
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 {
|
} else {
|
||||||
// Global x range.
|
// Global x range.
|
||||||
var x_min = Infinity;
|
var x_min = Infinity;
|
||||||
@ -202,6 +239,11 @@ beestat.component.card.temperature_profiles.prototype.get_title_ = function() {
|
|||||||
beestat.component.card.temperature_profiles.prototype.get_subtitle_ = function() {
|
beestat.component.card.temperature_profiles.prototype.get_subtitle_ = function() {
|
||||||
const thermostat = beestat.cache.thermostat[this.thermostat_id_];
|
const thermostat = beestat.cache.thermostat[this.thermostat_id_];
|
||||||
|
|
||||||
|
// If the profile has not yet been generated.
|
||||||
|
if (thermostat.profile === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const generated_at_m = moment(
|
const generated_at_m = moment(
|
||||||
thermostat.profile.metadata.generated_at
|
thermostat.profile.metadata.generated_at
|
||||||
);
|
);
|
||||||
@ -220,9 +262,9 @@ beestat.component.card.temperature_profiles.prototype.get_subtitle_ = function()
|
|||||||
} else {
|
} else {
|
||||||
duration_text += duration_weeks + ' weeks';
|
duration_text += duration_weeks + ' weeks';
|
||||||
}
|
}
|
||||||
duration_text += ' of data.';
|
duration_text += ' of data';
|
||||||
|
|
||||||
return 'Generated ' + generated_at_m.format('MMM Do @ h a') + ' (updated weekly) ' + duration_text;
|
return 'Generated ' + generated_at_m.format('MMM Do @ h a') + duration_text + ' (updated weekly).';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user