mirror of
				https://github.com/beestat/app.git
				synced 2025-10-30 17:52:25 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			108 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| /**
 | |
|  * Any type of thermostat.
 | |
|  *
 | |
|  * @author Jon Ziebell
 | |
|  */
 | |
| class thermostat extends cora\crud {
 | |
| 
 | |
|   public static $exposed = [
 | |
|     'private' => [
 | |
|       'read_id',
 | |
|       'sync',
 | |
|       'dismiss_alert',
 | |
|       'restore_alert'
 | |
|     ],
 | |
|     'public' => []
 | |
|   ];
 | |
| 
 | |
|   public static $cache = [
 | |
|     'sync' => 300 // 5 Minutes
 | |
|   ];
 | |
| 
 | |
|   public static $converged = [
 | |
|     'filters' => [
 | |
|       'type' => 'json'
 | |
|     ],
 | |
|     'temperature_profile' => [
 | |
|       'type' => 'json'
 | |
|     ],
 | |
|     'property' => [
 | |
|       'type' => 'json'
 | |
|     ],
 | |
|     'system_type' => [
 | |
|       'type' => 'json'
 | |
|     ]
 | |
|   ];
 | |
| 
 | |
|   public static $user_locked = true;
 | |
| 
 | |
|   /**
 | |
|    * Sync all thermostats for the current user with their associated service.
 | |
|    */
 | |
|   public function sync() {
 | |
|     // Skip this for the demo
 | |
|     if($this->setting->is_demo() === true) {
 | |
|       return;
 | |
|     }
 | |
| 
 | |
|     $lock_name = 'thermostat->sync(' . $this->session->get_user_id() . ')';
 | |
|     $this->database->get_lock($lock_name);
 | |
| 
 | |
|     $this->api('ecobee_thermostat', 'sync');
 | |
| 
 | |
|     $this->api(
 | |
|       'user',
 | |
|       'update_sync_status',
 | |
|       ['key' => 'thermostat']
 | |
|     );
 | |
| 
 | |
|     $this->database->release_lock($lock_name);
 | |
|   }
 | |
| 
 | |
|   /**
 | |
|    * Dismiss an alert.
 | |
|    *
 | |
|    * @param int $thermostat_id
 | |
|    * @param string $guid
 | |
|    */
 | |
|   public function dismiss_alert($thermostat_id, $guid) {
 | |
|     $thermostat = $this->get($thermostat_id);
 | |
|     foreach($thermostat['json_alerts'] as &$alert) {
 | |
|       if($alert['guid'] === $guid) {
 | |
|         $alert['dismissed'] = true;
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|     $this->update(
 | |
|       [
 | |
|         'thermostat_id' => $thermostat_id,
 | |
|         'json_alerts' => $thermostat['json_alerts']
 | |
|       ]
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   /**
 | |
|    * Restore a dismissed alert.
 | |
|    *
 | |
|    * @param int $thermostat_id
 | |
|    * @param string $guid
 | |
|    */
 | |
|   public function restore_alert($thermostat_id, $guid) {
 | |
|     $thermostat = $this->get($thermostat_id);
 | |
|     foreach($thermostat['json_alerts'] as &$alert) {
 | |
|       if($alert['guid'] === $guid) {
 | |
|         $alert['dismissed'] = false;
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|     $this->update(
 | |
|       [
 | |
|         'thermostat_id' => $thermostat_id,
 | |
|         'json_alerts' => $thermostat['json_alerts']
 | |
|       ]
 | |
|     );
 | |
|   }
 | |
| }
 |