Minor Tweeks
This commit is contained in:
		@@ -18,6 +18,7 @@ class RoomsApi extends ApiController
 | 
			
		||||
		$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
 | 
			
		||||
		foreach ($subDevicesData as $subDeviceKey => $subDevice) {
 | 
			
		||||
			foreach ($subDevice as $key => $value) {
 | 
			
		||||
				//Type Handling
 | 
			
		||||
				$type = null;
 | 
			
		||||
				if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
 | 
			
		||||
					$type = $subDevicesData[$subDeviceKey][$key]['type'];
 | 
			
		||||
@@ -27,6 +28,7 @@ class RoomsApi extends ApiController
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				//Record Translation
 | 
			
		||||
				$cammelCaseClass = "";
 | 
			
		||||
				foreach (explode('-', $type) as $word) {
 | 
			
		||||
					$cammelCaseClass .= ucfirst($word);
 | 
			
		||||
@@ -39,6 +41,25 @@ class RoomsApi extends ApiController
 | 
			
		||||
					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;
 | 
			
		||||
				}
 | 
			
		||||
				$subDevicesData[$subDeviceKey][$key]['connection_error'] =  $connectionError
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -46,9 +46,9 @@ class WidgetApi extends ApiController
 | 
			
		||||
		$response = null;
 | 
			
		||||
		$connectionError = true;
 | 
			
		||||
 | 
			
		||||
		$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
 | 
			
		||||
		$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
 | 
			
		||||
		$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
 | 
			
		||||
		$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
 | 
			
		||||
		if ( count($events) == 0){
 | 
			
		||||
@@ -65,20 +65,6 @@ class WidgetApi extends ApiController
 | 
			
		||||
		$LastRecordTime = new DateTime(reset($events)['time']);
 | 
			
		||||
		$niceTime = Utilities::ago($LastRecordTime);
 | 
			
		||||
 | 
			
		||||
		$interval = $LastRecordTime->diff(new DateTime());
 | 
			
		||||
		$hours   = $interval->format('%h');
 | 
			
		||||
		$minutes = $interval->format('%i');
 | 
			
		||||
		$lastSeen = ($hours * 60 + $minutes);
 | 
			
		||||
 | 
			
		||||
		if (
 | 
			
		||||
			$lastSeen < $deviceData['sleep_time'] ||
 | 
			
		||||
			$subDeviceData['type'] == "on/off" ||
 | 
			
		||||
			$subDeviceData['type'] == "door" ||
 | 
			
		||||
			$subDeviceData['type'] == "wather"
 | 
			
		||||
		) {
 | 
			
		||||
			$connectionError = false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$labels = [];
 | 
			
		||||
		$values = [];
 | 
			
		||||
		foreach ($events as $key => $event) {
 | 
			
		||||
@@ -95,6 +81,9 @@ class WidgetApi extends ApiController
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$response = [
 | 
			
		||||
			'room_id' => $subDeviceData['room_id'],
 | 
			
		||||
			'device_id' => $subDeviceData['device_id'],
 | 
			
		||||
			'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
 | 
			
		||||
			'records' => $events,
 | 
			
		||||
			'graph' => [
 | 
			
		||||
				'type' => $this->getDeviceConfig($subDeviceData['type'])['graph'],
 | 
			
		||||
@@ -124,8 +113,7 @@ class WidgetApi extends ApiController
 | 
			
		||||
					],
 | 
			
		||||
				],
 | 
			
		||||
			],
 | 
			
		||||
			'comError' => $connectionError,
 | 
			
		||||
			'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
 | 
			
		||||
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
		//TODO: Make Cleaner 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user