Rooms And Widget API Endpoints
This commit is contained in:
		@@ -18,8 +18,12 @@ $router->any('/oauth', 'Oauth');
 | 
			
		||||
$router->post('/api/login', 'AuthApi@login');
 | 
			
		||||
$router->post('/api/logout', 'AuthApi@logout');
 | 
			
		||||
 | 
			
		||||
$router->get('/api/devices', 'DevicesApi@default');
 | 
			
		||||
$router->get('/api/rooms', 'RoomsApi@default');
 | 
			
		||||
$router->get('/api/rooms/:id/update', 'RoomsApi@update');
 | 
			
		||||
 | 
			
		||||
$router->get('/api/devices', 'DevicesApi@default');
 | 
			
		||||
 | 
			
		||||
$router->get('/api/widget/:id/run', 'WidgetApi@default');
 | 
			
		||||
 | 
			
		||||
$router->any('/api/HA/auth', 'Oauth');
 | 
			
		||||
$router->any('/api/HA', 'GoogleHomeApi@response');
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
class RoomsApi extends ApiController{
 | 
			
		||||
 | 
			
		||||
	public function default(){
 | 
			
		||||
		//$this->requireAuth();
 | 
			
		||||
		$this->requireAuth();
 | 
			
		||||
		$response = [];
 | 
			
		||||
		$roomIds = [];
 | 
			
		||||
		$roomsData = RoomManager::getRoomsDefault();
 | 
			
		||||
@@ -23,4 +23,15 @@ class RoomsApi extends ApiController{
 | 
			
		||||
		}
 | 
			
		||||
		$this->response($response);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function update($roomId){
 | 
			
		||||
		//$this->requireAuth();
 | 
			
		||||
 | 
			
		||||
		$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
 | 
			
		||||
 | 
			
		||||
		foreach ($roomsData as $roomKey => $roomData) {
 | 
			
		||||
			$response[] = isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [];
 | 
			
		||||
		}
 | 
			
		||||
		$this->response($response);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								app/api/WidgetApi.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								app/api/WidgetApi.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
<?php
 | 
			
		||||
class WidgetApi extends ApiController{
 | 
			
		||||
 | 
			
		||||
	public function default($subDeviceId){
 | 
			
		||||
		//$this->requireAuth();
 | 
			
		||||
		$response = null;
 | 
			
		||||
 | 
			
		||||
		$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
 | 
			
		||||
		if ($subDeviceData['type'] == 'on/off'){
 | 
			
		||||
			$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
 | 
			
		||||
			RecordManager::create($subDeviceData['device_id'], 'on/off', !$lastValue);
 | 
			
		||||
			$response = !$lastValue;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$this->response($response);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user