PHP_SMART_HOME_V3/views/Automation.php

62 lines
1.9 KiB
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
$files = scandir('class/');
$files = array_diff($files, array('.', '..'));
foreach($files as $file) {
include_once 'class/'. $file;
}
class Automation extends Template
{
function __construct()
{
global $userManager;
global $lang;
if (!$userManager->isLogin()){
header('Location: ./login');
}
$automations = [];
$automationsData = AutomationManager::getAll();
foreach ($automationsData as $automationKey => $automationData) {
2019-08-24 11:07:07 +00:00
$doSomething = [];
foreach (json_decode($automationData['do_something']) as $deviceId => $subDeviceState) {
$subDeviceMasterDeviceData = DeviceManager::getDeviceById($deviceId);
$doSomething[$deviceId] = [
2019-08-25 12:08:00 +00:00
'name' => $subDeviceMasterDeviceData['name'],
2019-08-24 11:07:07 +00:00
'state' => $subDeviceState,
];
}
2019-08-23 11:39:42 +00:00
$automations[$automationData['automation_id']] = [
'name' => '',
2019-08-24 11:07:07 +00:00
'onDays' => json_decode($automationData['on_days']),
2019-08-23 11:39:42 +00:00
'ifSomething' => $automationData['if_something'],
2019-08-24 11:07:07 +00:00
'doSomething' => $doSomething,
2019-08-23 11:39:42 +00:00
'active' => $automationData['active'],
];
}
$approvedSubDevices = [];
$allDevicesData = DeviceManager::getAllDevices();
foreach ($allDevicesData as $deviceKey => $deviceValue) {
if (!$deviceValue['approved']) continue;
$allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) {
$approvedSubDevices[$subDeviceValue['subdevice_id']] = [
'name' => $allDevicesData[$deviceKey]['name'] . $allDevicesData[$deviceKey]['device_id'],
2019-08-23 11:39:42 +00:00
'type' => $subDeviceValue['type'],
2019-08-24 11:07:07 +00:00
'masterDevice' => $subDeviceValue['device_id'],
2019-08-23 11:39:42 +00:00
];
}
}
$template = new Template('automation');
$template->prepare('title', 'Automation');
$template->prepare('lang', $lang);
$template->prepare('automations', $automations);
$template->prepare('subDevices', $approvedSubDevices);
$template->render();
}
}