PHP_SMART_HOME_V3/app/models/managers/VirtualDeviceManager.php

20 lines
528 B
PHP
Raw Permalink Normal View History

2020-08-25 13:12:25 +00:00
<?php
class VirtualDeviceManager
{
2020-10-14 13:53:26 +00:00
public function fetchEnabled($deviceId = null, $subDeviceId = null){
$sleepTime = DeviceManager::getDeviceById($deviceId)['sleep_time'];
2020-08-25 13:12:25 +00:00
2020-10-14 13:53:26 +00:00
$LastRecordTime = new DateTime(RecordManager::getLastRecord($subDeviceId, 1)['time']);
$interval = $LastRecordTime->diff(new DateTime());
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
$lastSeen = ($hours * 60 + $minutes);
2020-08-25 13:12:25 +00:00
2020-10-14 13:53:26 +00:00
if ($lastSeen > $sleepTime || $sleepTime == 0) {
return true;
}
2020-08-25 13:12:25 +00:00
2020-10-14 13:53:26 +00:00
return false;
}
2020-08-25 13:12:25 +00:00
}