mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-29 07:23:00 +00:00
[client] Handle devices with no data gracefully
This commit is contained in:
parent
8ebb6539bc
commit
122d44f3b2
1 changed files with 7 additions and 4 deletions
|
@ -101,10 +101,9 @@ class DeviceReadingDisplay {
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
|
|
||||||
this.reading_types = await this.fetch_reading_types();
|
this.reading_types = await this.fetch_reading_types();
|
||||||
this.reading_type = this.reading_types.find((type) => type.short_descr == default_reading_type);
|
this.reading_type = this.reading_types.find((type) => type.short_descr == default_reading_type)
|
||||||
// Default to the 1st reading type if we can't find the default
|
|| this.reading_types[0] // Default to the 1st reading type if we can't find the default
|
||||||
if(typeof this.reading_type == "undefined")
|
|| { short_descr: "NONE_PRESENT", friendly_text: "(none yet!)", id: -1, count: -1 }; // ...or a default object if there aren't any readings yet
|
||||||
this.reading_type = this.reading_types[0];
|
|
||||||
|
|
||||||
// Create the reading type buttons
|
// Create the reading type buttons
|
||||||
let reading_type_list = this.display.querySelector(".reading-types");
|
let reading_type_list = this.display.querySelector(".reading-types");
|
||||||
|
@ -261,6 +260,10 @@ class DeviceReadingDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
async get_data() {
|
async get_data() {
|
||||||
|
// If there aren't any readings yet, then there's no point in requesting them
|
||||||
|
if(this.reading_type.id == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
let new_data = null;
|
let new_data = null;
|
||||||
// Dividing by 1000: ms -> s
|
// Dividing by 1000: ms -> s
|
||||||
let average_seconds = (this.end_time.diff(this.start_time) / 1000) / this.points_resolution;
|
let average_seconds = (this.end_time.diff(this.start_time) / 1000) / this.points_resolution;
|
||||||
|
|
Loading…
Reference in a new issue