Rooms API
This commit is contained in:
		| @@ -3,11 +3,34 @@ | |||||||
| class RoomsApi extends ApiController{ | class RoomsApi extends ApiController{ | ||||||
|  |  | ||||||
| 	public function default(){ | 	public function default(){ | ||||||
| 		$this->requireAuth(); | 		//$this->requireAuth(); | ||||||
| 		$response = []; | 		$rooms = []; | ||||||
|  | 		$roomsData = RoomManager::getAllRooms(); | ||||||
| 		// TODO: process the request | 		foreach ($roomsData as $roomKey => $roomData) { | ||||||
|  | 			$widgets = []; | ||||||
| 		$this->response($response); | 			$devicesData = DeviceManager::getAllDevicesInRoom($roomData['room_id']); | ||||||
|  | 			foreach ($devicesData as $deviceKey => $deviceData) { | ||||||
|  | 				$subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']); | ||||||
|  | 				foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { | ||||||
|  | 					$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']); | ||||||
|  | 					$widgets[] = [ | ||||||
|  | 						'subdevice_id' => $subDeviceData['subdevice_id'], | ||||||
|  | 						'device_id' =>  $deviceData['device_id'], | ||||||
|  | 						'name' => $deviceData['name'], | ||||||
|  | 						'type' => $subDeviceData['type'], | ||||||
|  | 						'icon' => $deviceData['icon'], | ||||||
|  | 						'value' => $lastRecord['value'], | ||||||
|  | 						'unit' => $subDeviceData['unit'], | ||||||
|  | 					]; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			$rooms[] = [ | ||||||
|  | 				'room_id' => $roomData['room_id'], | ||||||
|  | 				'name' => $roomData['name'], | ||||||
|  | 				'widgets' => $widgets, | ||||||
|  | 			]; | ||||||
|  | 		} | ||||||
|  | 		$this->response($rooms); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user