1
0
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:
Jon Ziebell 2025-01-30 19:44:31 -05:00
parent 425c73c7eb
commit 71694b5a1d

View File

@ -156,9 +156,8 @@ class ecobee_sensor extends cora\crud {
); );
// For each of the manually added ones, check and see if ecobee gives a // For each of the manually added ones, check and see if ecobee gives a
// result. If so, store that identifier as good. If not, inactivate the // result. If so, do nothing. If not, inactivate the manually added
// manually added ecobee_thermostat row. // ecobee_thermostat row.
$manual_identifiers = [];
foreach($manual_ecobee_thermostats as $manual_ecobee_thermostat) { foreach($manual_ecobee_thermostats as $manual_ecobee_thermostat) {
try { try {
$response = $this->api( $response = $this->api(
@ -180,10 +179,6 @@ class ecobee_sensor extends cora\crud {
] ]
] ]
); );
foreach($response['thermostatList'] as $api_thermostat) {
$manual_identifiers[] = $api_thermostat['identifier'];
}
} catch(\Exception $e) { } catch(\Exception $e) {
$this->api( $this->api(
'ecobee_thermostat', 'ecobee_thermostat',
@ -198,6 +193,24 @@ class ecobee_sensor extends cora\crud {
} }
} }
// Now get everything from the database. This will get already registered
// thermostats if they have been synced before, newly manually added
// thermostats, and existing manually added thermostats.
$ecobee_thermostats = $this->api(
'ecobee_thermostat',
'read',
[
'attributes' => [
'inactive' => 0
]
]
);
$manual_identifiers = [];
foreach($ecobee_thermostats as $ecobee_thermostat) {
$manual_identifiers[] = $ecobee_thermostat['identifier'];
}
// Get a unique list of identifiers. // Get a unique list of identifiers.
$identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers)); $identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers));
@ -225,13 +238,13 @@ class ecobee_sensor extends cora\crud {
// Loop over the returned sensors and create/update them as necessary. // Loop over the returned sensors and create/update them as necessary.
$sensor_ids_to_keep = []; $sensor_ids_to_keep = [];
foreach($response['thermostatList'] as $thermostat_api) { foreach($response['thermostatList'] as $api_thermostat) {
$ecobee_thermostat = $this->api( $ecobee_thermostat = $this->api(
'ecobee_thermostat', 'ecobee_thermostat',
'get', 'get',
[ [
'attributes' => [ 'attributes' => [
'identifier' => $thermostat_api['identifier'] 'identifier' => $api_thermostat['identifier']
] ]
] ]
); );
@ -246,7 +259,7 @@ class ecobee_sensor extends cora\crud {
] ]
); );
foreach($thermostat_api['remoteSensors'] as $api_sensor) { foreach($api_thermostat['remoteSensors'] as $api_sensor) {
$ecobee_sensor = $this->get( $ecobee_sensor = $this->get(
[ [
'ecobee_thermostat_id' => $ecobee_thermostat['ecobee_thermostat_id'], 'ecobee_thermostat_id' => $ecobee_thermostat['ecobee_thermostat_id'],