2020-05-12 17:41:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class RoomsApi extends ApiController{
|
|
|
|
|
|
|
|
public function default(){
|
2020-05-13 08:05:54 +00:00
|
|
|
//$this->requireAuth();
|
|
|
|
$rooms = [];
|
|
|
|
$roomsData = RoomManager::getAllRooms();
|
|
|
|
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'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 17:41:46 +00:00
|
|
|
|
2020-05-13 08:05:54 +00:00
|
|
|
$rooms[] = [
|
|
|
|
'room_id' => $roomData['room_id'],
|
|
|
|
'name' => $roomData['name'],
|
|
|
|
'widgets' => $widgets,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$this->response($rooms);
|
2020-05-12 17:41:46 +00:00
|
|
|
}
|
|
|
|
}
|