At home indicator
This commit is contained in:
parent
4c87116f06
commit
ad7c192a90
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user