diff --git a/api/ecobee.php b/api/ecobee.php index 7d2a2ec..a9cdc46 100644 --- a/api/ecobee.php +++ b/api/ecobee.php @@ -266,6 +266,22 @@ class ecobee extends external_api { $this->log_mysql($curl_response, true); } throw new cora\exception('User cannot access thermostat.', 10510, false, null, false); + } else if ( + isset($response['status']['message']) === true && + stripos($response['status']['message'], 'Processing error. Error populating API thermostats.') !== false + ) { + // Processing error. Error populating API thermostats. ... + + // Appears to happen when specifying "includeNotificationSettings" in + // the /thermostat API call when using a thermostat serial number from + // the /homes endpoint. I believe the /homes endpoint is out of date + // and errornously returning the thermostat, then asking for the + // thermostat, specifically the notification settings, breaks the + // ecobee API. + if($this::$log_mysql !== 'all') { + $this->log_mysql($curl_response, true); + } + throw new cora\exception('No thermostats found.', 10511, false, null, false); } } else if (isset($response['status']) === true && $response['status']['code'] !== 0) { diff --git a/api/ecobee_sensor.php b/api/ecobee_sensor.php index e1db261..bc0bf5f 100644 --- a/api/ecobee_sensor.php +++ b/api/ecobee_sensor.php @@ -199,25 +199,44 @@ class ecobee_sensor extends cora\crud { } if(count($serial_numbers) > 0) { - $response = $this->api( - 'ecobee', - 'ecobee_api', - [ - 'method' => 'GET', - 'endpoint' => 'thermostat', - 'arguments' => [ - 'body' => json_encode([ - 'selection' => array_merge( - [ - 'selectionType' => 'thermostats', - 'selectionMatch' => implode(',', $serial_numbers), - ], - $include - ) - ]) + try { + $response = $this->api( + 'ecobee', + 'ecobee_api', + [ + 'method' => 'GET', + 'endpoint' => 'thermostat', + 'arguments' => [ + 'body' => json_encode([ + 'selection' => array_merge( + [ + 'selectionType' => 'thermostats', + 'selectionMatch' => implode(',', $serial_numbers), + ], + $include + ) + ]) + ] ] - ] - ); + ); + } catch(cora\exception $e) { + /** + * For some reason, I can get a serial number in the /homes data + * and still get no results from the /thermostat endpoint. Likely + * due to two data sources not being in sync. Catch that exception + * and let the code continue so any existing thermostats still get + * inactivated. + * + * Also have to fabricate the $response a bit. + */ + if($e->getCode() === 10511) { + $response = [ + 'thermostatList' => [] + ]; + } 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, diff --git a/api/ecobee_thermostat.php b/api/ecobee_thermostat.php index d3ba89c..04fb0dd 100644 --- a/api/ecobee_thermostat.php +++ b/api/ecobee_thermostat.php @@ -162,25 +162,44 @@ class ecobee_thermostat extends cora\crud { } if(count($serial_numbers) > 0) { - $response = $this->api( - 'ecobee', - 'ecobee_api', - [ - 'method' => 'GET', - 'endpoint' => 'thermostat', - 'arguments' => [ - 'body' => json_encode([ - 'selection' => array_merge( - [ - 'selectionType' => 'thermostats', - 'selectionMatch' => implode(',', $serial_numbers), - ], - $include - ) - ]) + try { + $response = $this->api( + 'ecobee', + 'ecobee_api', + [ + 'method' => 'GET', + 'endpoint' => 'thermostat', + 'arguments' => [ + 'body' => json_encode([ + 'selection' => array_merge( + [ + 'selectionType' => 'thermostats', + 'selectionMatch' => implode(',', $serial_numbers), + ], + $include + ) + ]) + ] ] - ] - ); + ); + } catch(cora\exception $e) { + /** + * For some reason, I can get a serial number in the /homes data + * and still get no results from the /thermostat endpoint. Likely + * due to two data sources not being in sync. Catch that exception + * and let the code continue so any existing thermostats still get + * inactivated. + * + * Also have to fabricate the $response a bit. + */ + if($e->getCode() === 10511) { + $response = [ + 'thermostatList' => [] + ]; + } 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,