PHP_SMART_HOME_V3/app/api/RoomsApi.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2020-05-15 20:45:31 +00:00
<?php
class RoomsApi extends ApiController{
public function default(){
//$this->requireAuth();
2020-05-15 20:49:35 +00:00
$rooms = [];
$roomsData = RoomManager::getAllRooms();
foreach ($roomsData as $roomKey => $roomData) {
2020-05-15 20:45:31 +00:00
2020-05-15 20:49:35 +00:00
$widgets = [];
$devicesData = DeviceManager::getAllDevicesInRoom($roomData['room_id']);
foreach ($devicesData as $deviceKey => $deviceData) {
2020-05-15 20:45:31 +00:00
2020-05-15 20:49:35 +00:00
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']);
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
2020-05-15 20:45:31 +00:00
2020-05-15 20:49:35 +00:00
$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[] = [
2020-05-15 20:45:31 +00:00
'room_id' => $roomData['room_id'],
'name' => $roomData['name'],
2020-05-15 20:49:35 +00:00
'widgets' => $widgets,
2020-05-15 20:45:31 +00:00
];
}
2020-05-15 20:49:35 +00:00
$this->response($rooms);
2020-05-15 20:45:31 +00:00
}
}