mirror of
https://github.com/beestat/app.git
synced 2025-05-24 02:14:03 -04:00
Added ability to manually manage thermostats
This commit is contained in:
parent
41fe96502e
commit
6ffafeeec6
@ -235,8 +235,7 @@ class ecobee extends external_api {
|
||||
if($this::$log_mysql !== 'all') {
|
||||
$this->log_mysql($curl_response, true);
|
||||
}
|
||||
$this->api('ecobee_token', 'delete', $ecobee_token['ecobee_token_id']);
|
||||
throw new cora\exception('Ecobee access was revoked by user.', 10508, false, null, false);
|
||||
throw new cora\exception('Ecobee access was revoked by user.', 10508, false, $response['status']['message'], false);
|
||||
}
|
||||
else if (isset($response['status']) === true && $response['status']['code'] === 9) {
|
||||
// Invalid selection. No thermostats in selection. Ensure permissions and selection.
|
||||
|
@ -214,6 +214,7 @@ class ecobee_thermostat extends cora\crud {
|
||||
$identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers));
|
||||
|
||||
// Get all of the thermostats from ecobee.
|
||||
try {
|
||||
$response = $this->api(
|
||||
'ecobee',
|
||||
'ecobee_api',
|
||||
@ -233,6 +234,40 @@ class ecobee_thermostat extends cora\crud {
|
||||
]
|
||||
]
|
||||
);
|
||||
} catch(cora\exception $e) {
|
||||
if($e->getCode() === 10508) {
|
||||
// If there was an authorization failure, remove those identifiers.
|
||||
// These are likely thermostats that have been removed from the account
|
||||
// and are no longer accessible.
|
||||
|
||||
// Use regex to extract numbers
|
||||
preg_match_all('/\d+/', $e->getExtraInfo(), $matches);
|
||||
|
||||
$exclude_identifiers = $matches[0];
|
||||
|
||||
$identifiers = array_diff($identifiers, $exclude_identifiers);
|
||||
|
||||
$response = $this->api(
|
||||
'ecobee',
|
||||
'ecobee_api',
|
||||
[
|
||||
'method' => 'GET',
|
||||
'endpoint' => 'thermostat',
|
||||
'arguments' => [
|
||||
'body' => json_encode([
|
||||
'selection' => array_merge(
|
||||
[
|
||||
'selectionType' => 'thermostats',
|
||||
'selectionMatch' => implode(',', $identifiers)
|
||||
],
|
||||
$include
|
||||
)
|
||||
])
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop over the returned thermostats and create/update them as necessary.
|
||||
$thermostat_ids_to_keep = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user