mirror of
				https://github.com/beestat/app.git
				synced 2025-10-31 10:07:01 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| /**
 | |
|  * Sensor for any thermostat type.
 | |
|  *
 | |
|  * @author Jon Ziebell
 | |
|  */
 | |
| class sensor extends cora\crud {
 | |
| 
 | |
|   public static $exposed = [
 | |
|     'private' => [
 | |
|       'read_id',
 | |
|       'sync'
 | |
|     ],
 | |
|     'public' => []
 | |
|   ];
 | |
| 
 | |
|   public static $cache = [
 | |
|     'sync' => 300 // 5 Minutes
 | |
|   ];
 | |
| 
 | |
|   /**
 | |
|    * Normal read_id, but filter out unsupported sensor types.
 | |
|    *
 | |
|    * @param array $attributes
 | |
|    * @param array $columns
 | |
|    *
 | |
|    * @return array
 | |
|    */
 | |
|   public function read_id($attributes = [], $columns = []) {
 | |
|     $sensors = parent::read_id($attributes, $columns);
 | |
| 
 | |
|     $return = [];
 | |
|     foreach($sensors as $sensor) {
 | |
|       if (
 | |
|         in_array(
 | |
|           $sensor['type'],
 | |
|           ['ecobee3_remote_sensor', 'thermostat']
 | |
|         ) === true
 | |
|       ) {
 | |
|         $return[$sensor['sensor_id']] = $sensor;
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     return $return;
 | |
|   }
 | |
| 
 | |
|   /**
 | |
|    * 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.
 | |
|    */
 | |
|   public function sync() {
 | |
|     // Skip this for the demo
 | |
|     if($this->setting->is_demo() === true) {
 | |
|       return;
 | |
|     }
 | |
| 
 | |
|     $lock_name = 'sensor->sync(' . $this->session->get_user_id() . ')';
 | |
|     $this->database->get_lock($lock_name);
 | |
| 
 | |
|     $this->api('ecobee_sensor', 'sync');
 | |
| 
 | |
|     $this->api(
 | |
|       'user',
 | |
|       'update_sync_status',
 | |
|       [
 | |
|         'key' => 'sensor'
 | |
|       ]
 | |
|     );
 | |
| 
 | |
|     $this->database->release_lock($lock_name);
 | |
|   }
 | |
| 
 | |
| }
 |