1
0
mirror of https://github.com/beestat/app.git synced 2025-05-23 18:04:14 -04:00

Added ability to manually manage thermostats

This commit is contained in:
Jon Ziebell 2025-02-03 22:01:41 -05:00
parent 41fe96502e
commit 6ffafeeec6
2 changed files with 54 additions and 20 deletions

View File

@ -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.

View File

@ -214,25 +214,60 @@ class ecobee_thermostat extends cora\crud {
$identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers));
// Get all of the thermostats from ecobee.
$response = $this->api(
'ecobee',
'ecobee_api',
[
'method' => 'GET',
'endpoint' => 'thermostat',
'arguments' => [
'body' => json_encode([
'selection' => array_merge(
[
'selectionType' => 'thermostats',
'selectionMatch' => implode(',', $identifiers)
],
$include
)
])
try {
$response = $this->api(
'ecobee',
'ecobee_api',
[
'method' => 'GET',
'endpoint' => 'thermostat',
'arguments' => [
'body' => json_encode([
'selection' => array_merge(
[
'selectionType' => 'thermostats',
'selectionMatch' => implode(',', $identifiers)
],
$include
)
])
]
]
]
);
);
} 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 = [];