mirror of
https://github.com/beestat/app.git
synced 2025-06-03 21:57:32 -04:00
Fixed sensor runtime doing way too many queries
This commit is contained in:
parent
a05b2aac60
commit
a7b4c1a55e
@ -580,7 +580,8 @@ class runtime extends cora\api {
|
|||||||
$row,
|
$row,
|
||||||
$ecobee_columns
|
$ecobee_columns
|
||||||
);
|
);
|
||||||
$datas = [];
|
|
||||||
|
$datas = [];
|
||||||
|
|
||||||
foreach ($columns as $key => $value) {
|
foreach ($columns as $key => $value) {
|
||||||
if ($key === 'date' || $key === 'time') {
|
if ($key === 'date' || $key === 'time') {
|
||||||
@ -623,20 +624,24 @@ class runtime extends cora\api {
|
|||||||
$capability['id'] == $capability_identifier &&
|
$capability['id'] == $capability_identifier &&
|
||||||
in_array($capability['type'], ['temperature', 'occupancy']) === true
|
in_array($capability['type'], ['temperature', 'occupancy']) === true
|
||||||
) {
|
) {
|
||||||
$datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value;
|
if ($value === null) {
|
||||||
|
$datas[$sensor['sensor_id']][$capability['type']] = null;
|
||||||
|
} else {
|
||||||
|
$datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create or update the database
|
// Create or update the database
|
||||||
foreach ($datas as $data) {
|
foreach ($datas as $data) {
|
||||||
if(isset($existing_timestamps[$data['sensor_id']][$data['timestamp']]) === true) {
|
if(isset($existing_timestamps[$data['sensor_id']][$data['timestamp']]) === true) {
|
||||||
$data['runtime_sensor_id'] = $existing_timestamps[$data['sensor_id']][$data['timestamp']];
|
$data['runtime_sensor_id'] = $existing_timestamps[$data['sensor_id']][$data['timestamp']];
|
||||||
$this->database->update('runtime_sensor', $data, 'id');
|
$this->database->update('runtime_sensor', $data, 'id');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$existing_timestamps[$data['sensor_id']][$data['timestamp']] = $this->database->create('runtime_sensor', $data, 'id');
|
$existing_timestamps[$data['sensor_id']][$data['timestamp']] = $this->database->create('runtime_sensor', $data, 'id');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user