From 1f0d6e267b6f7896dde3f8fa466b7539334f3dcd Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Tue, 23 Jun 2020 22:30:05 -0400 Subject: [PATCH] Fixed #287 - Sync fails if first chunk of data has no viable rows --- api/runtime.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/api/runtime.php b/api/runtime.php index e59d7a9..5710b90 100644 --- a/api/runtime.php +++ b/api/runtime.php @@ -92,16 +92,22 @@ class runtime extends cora\api { 1 ); - $this->api( - 'thermostat', - 'update', - [ - 'attributes' => [ - 'thermostat_id' => $thermostat_id, - 'data_begin' => $runtime_thermostats[0]['timestamp'] + // Don't attempt this update if nothing was returned. This can happen + // if data is returned from ecobee for the first time period but none + // of it was valid. + if(count($runtime_thermostats) === 1) { + $this->api( + 'thermostat', + 'update', + [ + 'attributes' => [ + 'thermostat_id' => $thermostat_id, + 'data_begin' => $runtime_thermostats[0]['timestamp'] + ] ] - ] - ); + ); + } + } else { $this->sync_backwards($thermostat_id); }