Cherry pick Rooms API
This commit is contained in:
		@@ -4,36 +4,23 @@ class RoomsApi extends ApiController{
 | 
			
		||||
 | 
			
		||||
	public function default(){
 | 
			
		||||
		//$this->requireAuth();
 | 
			
		||||
		$rooms = [];
 | 
			
		||||
		$roomsData = RoomManager::getAllRooms();
 | 
			
		||||
		$response = [];
 | 
			
		||||
		$roomIds = [];
 | 
			
		||||
		$roomsData = RoomManager::getRoomsDefault();
 | 
			
		||||
 | 
			
		||||
		foreach ($roomsData as $roomKey => $room) {
 | 
			
		||||
			$roomIds[] = $room['room_id'];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
 | 
			
		||||
 | 
			
		||||
		foreach ($roomsData as $roomKey => $roomData) {
 | 
			
		||||
 | 
			
		||||
			$widgets = [];
 | 
			
		||||
			$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[] = [
 | 
			
		||||
			$response[] = [
 | 
			
		||||
				'room_id' => $roomData['room_id'],
 | 
			
		||||
				'name' => $roomData['name'],
 | 
			
		||||
				'widgets' => $widgets,
 | 
			
		||||
				'widgets' => isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [],
 | 
			
		||||
			];
 | 
			
		||||
		}
 | 
			
		||||
		$this->response($rooms);
 | 
			
		||||
		$this->response($response);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user