|
|
@ -24,53 +24,43 @@ class RoomsApi extends ApiController |
|
|
|
$type = $subDevicesData[$subDeviceKey][$key]['type']; |
|
|
|
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) { |
|
|
|
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type']; |
|
|
|
} else { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
//Connection Error Creation
|
|
|
|
$connectionError = true; |
|
|
|
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['time']); |
|
|
|
$interval = $LastRecordTime->diff(new DateTime()); |
|
|
|
$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i')); |
|
|
|
|
|
|
|
if ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == NULL || $subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 || $lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time']) { |
|
|
|
$connectionError = false; |
|
|
|
} |
|
|
|
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError; |
|
|
|
|
|
|
|
//Record Translation
|
|
|
|
$cammelCaseClass = ""; |
|
|
|
foreach (explode('-', $type) as $word) { |
|
|
|
$cammelCaseClass .= ucfirst($word); |
|
|
|
} |
|
|
|
if (!class_exists($cammelCaseClass)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
$deviceClass = new $cammelCaseClass; |
|
|
|
if (!method_exists($deviceClass, 'translate')) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']); |
|
|
|
|
|
|
|
//Connection Error Creation
|
|
|
|
$niceTime = Utilities::ago($LastRecordTime); |
|
|
|
|
|
|
|
$interval = $LastRecordTime->diff(new DateTime()); |
|
|
|
$hours = $interval->format('%h'); |
|
|
|
$minutes = $interval->format('%i'); |
|
|
|
$lastSeen = ($hours * 60 + $minutes); |
|
|
|
|
|
|
|
if ( |
|
|
|
$lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time'] || |
|
|
|
$subDevicesData[$subDeviceKey][$key]['type'] == "on/off" || |
|
|
|
$subDevicesData[$subDeviceKey][$key]['type'] == "door" || |
|
|
|
$subDevicesData[$subDeviceKey][$key]['type'] == "wather" |
|
|
|
) { |
|
|
|
$connectionError = false; |
|
|
|
if (class_exists($cammelCaseClass)) { |
|
|
|
$deviceClass = new $cammelCaseClass; |
|
|
|
if (method_exists($deviceClass, 'translate')) { |
|
|
|
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']); |
|
|
|
} |
|
|
|
} |
|
|
|
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($roomsData as $roomKey => $roomData) { |
|
|
|
if ($roomData['device_count'] == 0) continue; |
|
|
|
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : []; |
|
|
|
$response[] = [ |
|
|
|
'room_id' => $roomData['room_id'], |
|
|
|
'name' => $roomData['name'], |
|
|
|
'widgets' => isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [], |
|
|
|
'widgets' => $subDevicesSorted, |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
$this->response($response); |
|
|
|
} |
|
|
|
|
|
|
|