From ad7c192a90250c36582052155c0563dd8b13a50f Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 9 Sep 2019 21:30:50 +0200 Subject: [PATCH] At home indicator --- views/Home.php | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/views/Home.php b/views/Home.php index 536546e..e5c5a82 100644 --- a/views/Home.php +++ b/views/Home.php @@ -25,15 +25,15 @@ class Home extends Template foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { $events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5); - - - $lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']); + //TODO: skontrolovat zdali se jedná o poslední (opravdu nejaktuálnější) záznam + $lastRecord = $events[0]; $parsedValue = round($lastRecord['value']); /*Value Parsing*/ if ($subDeviceData['type'] == "on/off") { $parsedValue = ($parsedValue == 1 ? 'ON' : 'OFF'); } + if ($subDeviceData['type'] == "door") { $replacementTrue = 'Closed'; $replacementFalse = 'Opened'; @@ -64,18 +64,6 @@ class Home extends Template } } - $subDevice = SubDeviceManager::getSubDevice($subDeviceData['subdevice_id']); - $records = RecordManager::getAllRecordForGraph($subDeviceData['subdevice_id']); - - $array = array_column($records, 'value'); - foreach ($array as $key => $value) { - $array[$key] = $value . $subDevice['unit']; - } - - $data = json_encode($array); - $labels = json_encode($array); - - $date2 = new DateTime($lastRecord['time']); $niceTime = $this->ago($date2); @@ -136,29 +124,6 @@ class Home extends Template ]; } - if (isset($_POST['deviceId'])){ - $deviceData = DeviceManager::getDeviceById($_POST['deviceId']); - - $subDevices = []; - $subDevicesData = SubDeviceManager::getAllSubDevices($_POST['deviceId']); - - foreach ($subDevicesData as $subDeviceKey => $subDeviceData) { - $subDevices[$subDeviceData['subdevice_id']] = [ - 'type' => $subDeviceData['type'], - 'unit' => $subDeviceData['unit'], - ]; - } - - $device = [ - 'id' => $deviceData['device_id'], - 'name' => $deviceData['name'], - 'token' => $deviceData['token'], - 'icon' => $deviceData['icon'], - 'subDevices' => $subDevices, - ]; - $template->prepare('deviceData', $device); - } - $users = UserManager::getUsers(); $template->prepare('users', $users);