1
0
mirror of https://github.com/beestat/app.git synced 2026-05-13 10:52:29 -04:00
Loading now doesn't break if the sync fails, and as a bonus that made it trivial to display whether or not ecobee is down.
This commit is contained in:
Jon Ziebell
2020-01-29 22:39:05 -05:00
parent deaf81e214
commit a6564305b0
15 changed files with 191 additions and 113 deletions
+19 -14
View File
@@ -46,9 +46,10 @@ class sensor extends cora\crud {
}
/**
* Sync all sensors connected to this account. Once Nest support is
* added this will need to check for all connected accounts and run the
* appropriate ones.
* Sync all sensors for the current user. If we fail to get a lock, fail
* silently (catch the exception) and just return false.
*
* @return boolean true if the sync ran, false if not.
*/
public function sync() {
// Skip this for the demo
@@ -56,20 +57,24 @@ class sensor extends cora\crud {
return;
}
$lock_name = 'sensor->sync(' . $this->session->get_user_id() . ')';
$this->database->get_lock($lock_name);
try {
$lock_name = 'sensor->sync(' . $this->session->get_user_id() . ')';
$this->database->get_lock($lock_name);
$this->api('ecobee_sensor', 'sync');
$this->api('ecobee_sensor', 'sync');
$this->api(
'user',
'update_sync_status',
[
'key' => 'sensor'
]
);
$this->api(
'user',
'update_sync_status',
[
'key' => 'sensor'
]
);
$this->database->release_lock($lock_name);
$this->database->release_lock($lock_name);
} catch(cora\exception $e) {
return false;
}
}
}