Minor Tweeks
This commit is contained in:
parent
879a63948f
commit
ff2c51d505
@ -18,6 +18,7 @@ class RoomsApi extends ApiController
|
|||||||
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
||||||
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
||||||
foreach ($subDevice as $key => $value) {
|
foreach ($subDevice as $key => $value) {
|
||||||
|
//Type Handling
|
||||||
$type = null;
|
$type = null;
|
||||||
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
||||||
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
||||||
@ -27,6 +28,7 @@ class RoomsApi extends ApiController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Record Translation
|
||||||
$cammelCaseClass = "";
|
$cammelCaseClass = "";
|
||||||
foreach (explode('-', $type) as $word) {
|
foreach (explode('-', $type) as $word) {
|
||||||
$cammelCaseClass .= ucfirst($word);
|
$cammelCaseClass .= ucfirst($word);
|
||||||
@ -39,6 +41,25 @@ class RoomsApi extends ApiController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
||||||
|
|
||||||
|
//Connection Error Creation
|
||||||
|
$niceTime = Utilities::ago($LastRecordTime);
|
||||||
|
|
||||||
|
$interval = $LastRecordTime->diff(new DateTime());
|
||||||
|
$hours = $interval->format('%h');
|
||||||
|
$minutes = $interval->format('%i');
|
||||||
|
$lastSeen = ($hours * 60 + $minutes);
|
||||||
|
|
||||||
|
if (
|
||||||
|
$lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time'] ||
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['type'] == "on/off" ||
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['type'] == "door" ||
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['type'] == "wather"
|
||||||
|
) {
|
||||||
|
$connectionError = false;
|
||||||
|
}
|
||||||
|
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ class WidgetApi extends ApiController
|
|||||||
$response = null;
|
$response = null;
|
||||||
$connectionError = true;
|
$connectionError = true;
|
||||||
|
|
||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
||||||
$deviceData = DeviceManager::getDeviceById($subDeviceData['device_id']);
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
||||||
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
||||||
if ( count($events) == 0){
|
if ( count($events) == 0){
|
||||||
@ -65,20 +65,6 @@ class WidgetApi extends ApiController
|
|||||||
$LastRecordTime = new DateTime(reset($events)['time']);
|
$LastRecordTime = new DateTime(reset($events)['time']);
|
||||||
$niceTime = Utilities::ago($LastRecordTime);
|
$niceTime = Utilities::ago($LastRecordTime);
|
||||||
|
|
||||||
$interval = $LastRecordTime->diff(new DateTime());
|
|
||||||
$hours = $interval->format('%h');
|
|
||||||
$minutes = $interval->format('%i');
|
|
||||||
$lastSeen = ($hours * 60 + $minutes);
|
|
||||||
|
|
||||||
if (
|
|
||||||
$lastSeen < $deviceData['sleep_time'] ||
|
|
||||||
$subDeviceData['type'] == "on/off" ||
|
|
||||||
$subDeviceData['type'] == "door" ||
|
|
||||||
$subDeviceData['type'] == "wather"
|
|
||||||
) {
|
|
||||||
$connectionError = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$labels = [];
|
$labels = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
foreach ($events as $key => $event) {
|
foreach ($events as $key => $event) {
|
||||||
@ -95,6 +81,9 @@ class WidgetApi extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = [
|
$response = [
|
||||||
|
'room_id' => $subDeviceData['room_id'],
|
||||||
|
'device_id' => $subDeviceData['device_id'],
|
||||||
|
'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
||||||
'records' => $events,
|
'records' => $events,
|
||||||
'graph' => [
|
'graph' => [
|
||||||
'type' => $this->getDeviceConfig($subDeviceData['type'])['graph'],
|
'type' => $this->getDeviceConfig($subDeviceData['type'])['graph'],
|
||||||
@ -124,8 +113,7 @@ class WidgetApi extends ApiController
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'comError' => $connectionError,
|
|
||||||
'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
//TODO: Make Cleaner
|
//TODO: Make Cleaner
|
||||||
|
@ -26,6 +26,10 @@ class GoogleHome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($traids < 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$tempDevice = [
|
$tempDevice = [
|
||||||
'id' => (string) $deviceData['device_id'],
|
'id' => (string) $deviceData['device_id'],
|
||||||
'type' => $actionType,
|
'type' => $actionType,
|
||||||
|
@ -5,7 +5,7 @@ class SubDeviceManager
|
|||||||
|
|
||||||
public static function getAllSubDevices($deviceId = null)
|
public static function getAllSubDevices($deviceId = null)
|
||||||
{
|
{
|
||||||
if ($deviceId == null){
|
if ($deviceId == null) {
|
||||||
return Db::loadAll("SELECT * FROM subdevices");
|
return Db::loadAll("SELECT * FROM subdevices");
|
||||||
}
|
}
|
||||||
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
|
return Db::loadAll("SELECT * FROM subdevices WHERE device_id = ?", array($deviceId));
|
||||||
@ -72,15 +72,16 @@ class SubDeviceManager
|
|||||||
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
|
return Db::loadAll("DELETE FROM subdevices WHERE subdevice_id = ?", array($subDeviceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubdevicesByRoomIds($roomIds = NULL) {
|
public static function getSubdevicesByRoomIds($roomIds = NULL)
|
||||||
if(empty($roomIds)) return NULL;
|
{
|
||||||
|
if (empty($roomIds)) return NULL;
|
||||||
|
|
||||||
//TODO: @Patrik Check line 89
|
//TODO: @Patrik Check line 89
|
||||||
$rows = Db::loadAll("
|
$rows = Db::loadAll("
|
||||||
SELECT d.room_id, sd.subdevice_id, sd.device_id, d.icon, d.name, sd.type, sd.unit, r.value FROM subdevices sd
|
SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.device_id, d.icon, d.name, sd.type, sd.unit, r.value FROM subdevices sd
|
||||||
JOIN devices d ON sd.device_id = d.device_id
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
JOIN records r ON r.subdevice_id = sd.subdevice_id
|
||||||
WHERE d.room_id IN (".str_repeat("?,", count($roomIds)-1)."?)
|
WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?)
|
||||||
/*AND value != '999'*/
|
/*AND value != '999'*/
|
||||||
AND r.record_id IN (
|
AND r.record_id IN (
|
||||||
SELECT MAX(record_id)
|
SELECT MAX(record_id)
|
||||||
@ -92,10 +93,21 @@ class SubDeviceManager
|
|||||||
", $roomIds);
|
", $roomIds);
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach($rows as $row){
|
foreach ($rows as $row) {
|
||||||
$ret[$row['room_id']][] = $row;
|
$ret[$row['room_id']][] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getSubdeviceDetailById($subDeviceId){
|
||||||
|
if (empty($subDeviceId)) return NULL;
|
||||||
|
|
||||||
|
$rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
|
||||||
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
|
WHERE sd.subdevice_id = ? ", [$subDeviceId]);
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class GoogleHomeDeviceTypes {
|
|||||||
'control-light' => 'action.devices.types.LIGHT',
|
'control-light' => 'action.devices.types.LIGHT',
|
||||||
'control-socket' => 'action.devices.types.OUTLET',
|
'control-socket' => 'action.devices.types.OUTLET',
|
||||||
'control-temp' => 'action.devices.types.THERMOSTAT',
|
'control-temp' => 'action.devices.types.THERMOSTAT',
|
||||||
'control-media' => 'action.devices.types.REMOTECONTROL',
|
'control-media' => 'action.devices.types.REMOTECONTROL',
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $traidWordBook = [
|
private static $traidWordBook = [
|
||||||
|
Loading…
Reference in New Issue
Block a user