some fix and new firmware for shelly1
This commit is contained in:
@@ -145,6 +145,77 @@ class Ajax extends Template
|
||||
echo 'no action detected';
|
||||
break;
|
||||
}
|
||||
} else if (
|
||||
isset($_POST['action']) &&
|
||||
$_POST['action'] != ''
|
||||
) {
|
||||
$updateData = [];
|
||||
$allDevicesData = DeviceManager::getAllDevices();
|
||||
foreach ($allDevicesData as $deviceKey => $deviceValue) {
|
||||
$allSubDevices = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
|
||||
foreach ($allSubDevices as $key => $subDevicesData) {
|
||||
|
||||
$lastRecord = RecordManager::getLastRecord($subDevicesData['subdevice_id']);
|
||||
$parsedValue = $lastRecord['value'] . $subDevicesData['unit'];
|
||||
|
||||
//TODO: udělat parser a ten použít jak v houmu tak zde
|
||||
switch ($subDevicesData['type']) {
|
||||
case 'on/off':
|
||||
$replacementTrue = 'On';
|
||||
$replacementFalse = 'Off';
|
||||
$operator = '==';
|
||||
$breakValue = 1;
|
||||
break;
|
||||
|
||||
case 'door':
|
||||
$replacementTrue = 'Closed';
|
||||
$replacementFalse = 'Open';
|
||||
$operator = '==';
|
||||
$breakValue = 1;
|
||||
break;
|
||||
|
||||
case 'light':
|
||||
$replacementTrue = 'Light';
|
||||
$replacementFalse = 'Dark';
|
||||
$operator = '==';
|
||||
$breakValue = 1;
|
||||
if ($lastRecord['value'] != 1 && $lastRecord['value'] != 0) { //Digital Light Senzor
|
||||
$operator = '<';
|
||||
$breakValue = 810;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'water':
|
||||
$replacementTrue = 'Wet';
|
||||
$replacementFalse = 'Dry';
|
||||
$operator = '==';
|
||||
$breakValue = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
$replacementTrue = '';
|
||||
$replacementFalse = '';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($replacementTrue != '' && $replacementFalse != '') {
|
||||
//parsing last values
|
||||
$parsedValue = $replacementFalse;
|
||||
|
||||
if (Utilities::checkOperator($lastRecord['value'], $operator, $breakValue)) {
|
||||
$parsedValue = $replacementTrue;
|
||||
}
|
||||
}
|
||||
|
||||
$updateData[$subDevicesData['subdevice_id']] = [
|
||||
'time' => $lastRecord['time'],
|
||||
'value' => $parsedValue,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: PRO JS VRACET DATA
|
||||
echo json_encode($updateData, JSON_PRETTY_PRINT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,6 @@ class Home extends Template
|
||||
{
|
||||
global $userManager;
|
||||
global $langMng;
|
||||
$roomManager = new RoomManager();
|
||||
$deviceManager = new DeviceManager();
|
||||
$subDeviceManager = new SubDeviceManager();
|
||||
$recordManager = new RecordManager();
|
||||
$utilities = new Utilities();
|
||||
|
||||
if (!$userManager->isLogin()){
|
||||
header('Location: ' . BASEDIR . 'login');
|
||||
@@ -20,7 +15,7 @@ class Home extends Template
|
||||
$template = new Template('home');
|
||||
|
||||
//users instantialize
|
||||
$users = $userManager->getUsers();
|
||||
$users = UserManager::getUsers();
|
||||
$template->prepare('users', $users);
|
||||
|
||||
//Users at home Info
|
||||
@@ -39,16 +34,16 @@ class Home extends Template
|
||||
|
||||
|
||||
$roomsItems = [];
|
||||
$roomsData = $roomManager->getAllRooms();
|
||||
$roomsData = RoomManager::getAllRooms();
|
||||
foreach ($roomsData as $roomKey => $roomsData) {
|
||||
$devices = [];
|
||||
$devicesData = $deviceManager->getAllDevicesInRoom($roomsData['room_id']);
|
||||
$devicesData = DeviceManager::getAllDevicesInRoom($roomsData['room_id']);
|
||||
foreach ($devicesData as $deviceKey => $deviceData) {
|
||||
$subDevices = [];
|
||||
$subDevicesData = $subDeviceManager->getAllSubDevices($deviceData['device_id']);
|
||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceData['device_id']);
|
||||
foreach ($subDevicesData as $subDeviceKey => $subDeviceData) {
|
||||
|
||||
$events = $recordManager->getLastRecord($subDeviceData['subdevice_id'], 5);
|
||||
$events = RecordManager::getLastRecord($subDeviceData['subdevice_id'], 5);
|
||||
$eventsRaw = $events;
|
||||
|
||||
$connectionError = true;
|
||||
@@ -105,7 +100,7 @@ class Home extends Template
|
||||
//parsing last values
|
||||
$parsedValue = $replacementFalse;
|
||||
|
||||
if ($utilities->checkOperator($lastValue, $operator, $breakValue)) {
|
||||
if (Utilities::checkOperator($lastValue, $operator, $breakValue)) {
|
||||
$parsedValue = $replacementTrue;
|
||||
}
|
||||
|
||||
@@ -113,14 +108,14 @@ class Home extends Template
|
||||
//parsing last events values
|
||||
foreach ($events as $key => $value) {
|
||||
$events[$key]['value'] = $replacementFalse;
|
||||
if ($utilities->checkOperator($value['value'], $operator, $breakValue)) {
|
||||
if (Utilities::checkOperator($value['value'], $operator, $breakValue)) {
|
||||
$events[$key]['value'] = $replacementTrue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$LastRecordTime = new DateTime($lastRecord['time']);
|
||||
$niceTime = $utilities->ago($LastRecordTime);
|
||||
$niceTime = Utilities::ago($LastRecordTime);
|
||||
|
||||
$interval = $LastRecordTime->diff(new DateTime());
|
||||
$hours = $interval->format('%h');
|
||||
@@ -180,7 +175,7 @@ class Home extends Template
|
||||
];
|
||||
}
|
||||
|
||||
$rooms = $roomManager->getAllRooms();
|
||||
$rooms = RoomManager::getAllRooms();
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('title', 'Home');
|
||||
|
@@ -26,6 +26,8 @@ class Log extends Template
|
||||
}
|
||||
|
||||
$template->prepare('baseDir', BASEDIR);
|
||||
$template->prepare('debugMod', DEBUGMOD);
|
||||
$template->prepare('logToLiveTime', LOGTIMOUT);
|
||||
$template->prepare('title', 'Logy');
|
||||
$template->prepare('logsFiles', $result);
|
||||
$template->prepare('langMng', $langMng);
|
||||
|
Reference in New Issue
Block a user