mirror of
https://github.com/beestat/app.git
synced 2025-07-09 03:04:07 -04:00
Fixed #245 - Sensor data is thrown away if any sensor in the set has missing data
This commit is contained in:
parent
aca4c69720
commit
5f2efbc7ba
@ -733,13 +733,10 @@ class runtime extends cora\api {
|
||||
foreach($sensor['capability'] as $capability) {
|
||||
if(
|
||||
$capability['id'] == $capability_identifier &&
|
||||
in_array($capability['type'], ['temperature', 'occupancy']) === true
|
||||
in_array($capability['type'], ['temperature', 'occupancy']) === true &&
|
||||
$value !== null
|
||||
) {
|
||||
if ($value === null) {
|
||||
continue 3; // If temperature or occupancy are null, ignore
|
||||
} else {
|
||||
$datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value;
|
||||
}
|
||||
$datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -747,12 +744,14 @@ class runtime extends cora\api {
|
||||
|
||||
// Create or update the database
|
||||
foreach ($datas as $data) {
|
||||
if(isset($existing_timestamps[$data['sensor_id']][$data['timestamp']]) === true) {
|
||||
$data['runtime_sensor_id'] = $existing_timestamps[$data['sensor_id']][$data['timestamp']];
|
||||
$this->database->update('runtime_sensor', $data, 'id');
|
||||
}
|
||||
else {
|
||||
$existing_timestamps[$data['sensor_id']][$data['timestamp']] = $this->database->create('runtime_sensor', $data, 'id');
|
||||
if(isset($data['temperature']) === true && isset($data['occupancy']) === true) {
|
||||
if(isset($existing_timestamps[$data['sensor_id']][$data['timestamp']]) === true) {
|
||||
$data['runtime_sensor_id'] = $existing_timestamps[$data['sensor_id']][$data['timestamp']];
|
||||
$this->database->update('runtime_sensor', $data, 'id');
|
||||
}
|
||||
else {
|
||||
$existing_timestamps[$data['sensor_id']][$data['timestamp']] = $this->database->create('runtime_sensor', $data, 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user