From 8d513331dca59b9aa98b460182b84d6366b90f2c Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Wed, 23 Aug 2023 22:18:19 -0400 Subject: [PATCH] Fixed an issue where thermostats were not inactivating if none were found. --- api/ecobee_thermostat.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/api/ecobee_thermostat.php b/api/ecobee_thermostat.php index a211ae6..d3ba89c 100644 --- a/api/ecobee_thermostat.php +++ b/api/ecobee_thermostat.php @@ -181,8 +181,12 @@ class ecobee_thermostat extends cora\crud { ] ] ); - } else { - throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback()); + + /** + * At this point, $response will either be populated with results, + * or have an empty thermostatList attribute. The code can continue + * on as it will inactivate any thermostats that were not found. + */ } } else { throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback()); @@ -392,14 +396,14 @@ class ecobee_thermostat extends cora\crud { } // Inactivate any ecobee_thermostats that were no longer returned. - $thermostats = $this->api('thermostat', 'read'); + $thermostats = $this->api('thermostat', 'read', ['attributes' => ['inactive' => false]]); $ecobee_thermostat_ids_to_return = []; foreach($thermostats as $thermostat) { if(in_array($thermostat['thermostat_id'], $thermostat_ids_to_keep) === false) { $this->update( [ 'ecobee_thermostat_id' => $thermostat['ecobee_thermostat_id'], - 'inactive' => 1 + 'inactive' => true ] ); @@ -409,7 +413,7 @@ class ecobee_thermostat extends cora\crud { [ 'attributes' => [ 'thermostat_id' => $thermostat['thermostat_id'], - 'inactive' => 1 + 'inactive' => true ], ] ); @@ -418,7 +422,11 @@ class ecobee_thermostat extends cora\crud { } } - return $this->read_id(['ecobee_thermostat_id' => $ecobee_thermostat_ids_to_return]); + if (count($ecobee_thermostat_ids_to_return) === 0) { + return []; + } else { + return $this->read_id(['ecobee_thermostat_id' => $ecobee_thermostat_ids_to_return]); + } } /**