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

Removing firstConnected as a requirement for unique thermostats.

Turns out ecobee is sometimes changing firstConnected (on four thermostats so far, see #203). Since this field is no longer reliable, switching to serial number (identifier) only.
This commit is contained in:
Jon Ziebell 2019-12-19 21:15:58 -05:00
parent 23cefc3834
commit 08403cedc6
3 changed files with 6 additions and 11 deletions

View File

@ -62,12 +62,11 @@ class ecobee extends external_api {
$ecobee_token
);
$guids = [];
$identifiers = [];
$email_addresses = [];
foreach($response['thermostatList'] as $thermostat) {
$runtime = $thermostat['runtime'];
$guid = sha1($thermostat['identifier'] . $runtime['firstConnected']);
$guids[] = $guid;
$identifiers[] = $thermostat['identifier'];
$notification_settings = $thermostat['notificationSettings'];
$email_addresses = array_merge($email_addresses, $notification_settings['emailAddresses']);
@ -79,7 +78,7 @@ class ecobee extends external_api {
$existing_ecobee_thermostats = $this->database->read(
'ecobee_thermostat',
[
'guid' => $guids
'identifier' => $identifiers
]
);

View File

@ -100,14 +100,12 @@ class ecobee_sensor extends cora\crud {
// Loop over the returned sensors and create/update them as necessary.
$sensor_ids_to_keep = [];
foreach($response['thermostatList'] as $thermostat_api) {
$guid = sha1($thermostat_api['identifier'] . $thermostat_api['runtime']['firstConnected']);
$ecobee_thermostat = $this->api(
'ecobee_thermostat',
'get',
[
'attributes' => [
'guid' => $guid
'identifier' => $thermostat_api['identifier']
]
]
);

View File

@ -100,11 +100,9 @@ class ecobee_thermostat extends cora\crud {
// Loop over the returned thermostats and create/update them as necessary.
$thermostat_ids_to_keep = [];
foreach($response['thermostatList'] as $api_thermostat) {
$guid = sha1($api_thermostat['identifier'] . $api_thermostat['runtime']['firstConnected']);
$ecobee_thermostat = $this->get(
[
'guid' => $guid
'identifier' => $api_thermostat['identifier']
]
);
@ -123,7 +121,7 @@ class ecobee_thermostat extends cora\crud {
else {
// Thermostat does not exist.
$ecobee_thermostat = $this->create([
'guid' => $guid
'identifier' => $api_thermostat['identifier']
]);
$thermostat = $this->api(
'thermostat',