PHP_SMART_HOME_V3/app/class/FallbackManager.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2020-02-11 15:01:00 +00:00
<?php
/**
*
*/
2020-02-15 13:02:18 +00:00
2020-02-11 15:01:00 +00:00
class FallbackManager
{
public $deviceDefinitions = "";
function __construct($deviceDefinition)
{
$this->deviceDefinitions = $deviceDefinition;
}
function check(){
//TODO: FIX IT
2020-02-14 16:05:56 +00:00
$allDevicesData = DeviceManager::getAllDevices();
2020-02-11 15:01:00 +00:00
foreach ($allDevicesData as $deviceKey => $deviceValue) {
$allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) {
if (!isset($this->deviceDefinitions[$subDeviceValue['type']]["fallBack"])) {
continue;
}
2020-02-15 13:02:18 +00:00
if (!isset($this->deviceDefinitions[$subDeviceValue['type']]["fallBackTime"])) {
continue;
}
2020-02-11 15:01:00 +00:00
$lastRecord = RecordManager::getLastRecord($subDeviceValue['subdevice_id']);
2020-02-14 16:05:56 +00:00
if ($lastRecord["value"] == $this->deviceDefinitions[$subDeviceValue['type']]["fallBack"]) {
2020-02-15 13:02:18 +00:00
continue;
2020-02-14 16:05:56 +00:00
}
2020-02-15 13:02:18 +00:00
$minutes = (time() - strtotime($lastRecord['time'])) / 60;
if ( $minutes > $this->deviceDefinitions[$subDeviceValue['type']]["fallBackTime"]){
2020-02-11 15:01:00 +00:00
RecordManager::create($deviceValue['device_id'], $subDeviceValue['type'], $this->deviceDefinitions[$subDeviceValue['type']]["fallBack"]);
}
}
2020-02-14 16:05:56 +00:00
}
2020-02-11 15:01:00 +00:00
}
}