API Changes/Optimalizaton/Improvement
This commit is contained in:
parent
6060d3362e
commit
97e2eaf6ec
48
api.php
48
api.php
@ -140,19 +140,59 @@ if ($values != null || $values != "") {
|
||||
}
|
||||
RecordManager::create($deviceId, $key, round($value['value'],2));
|
||||
$logManager->write("[API] Device_ID " . $deviceId . " writed value " . $key . ' ' . $value['value'], LogRecordType::INFO);
|
||||
|
||||
|
||||
//notification
|
||||
if ($key == 'door' || $key == 'water') {
|
||||
|
||||
$notificationMng = new NotificationManager;
|
||||
|
||||
$notificationData = [];
|
||||
|
||||
switch ($key) {
|
||||
case 'door':
|
||||
$notificationData = [
|
||||
'title' => 'Info',
|
||||
'body' => 'Someone just open up '.$device['name'],
|
||||
'icon' => '',
|
||||
];
|
||||
break;
|
||||
case 'water':
|
||||
$notificationData = [
|
||||
'title' => 'Alert',
|
||||
'body' => 'Wather leak detected by '.$device['name'],
|
||||
'icon' => '',
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
if ($notificationData != []) {
|
||||
$subscribers = $notificationMng::getSubscription();
|
||||
foreach ($subscribers as $key => $subscriber) {
|
||||
$logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ");
|
||||
$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hostname = strtolower($device['name']);
|
||||
$hostname = str_replace(' ', '_', $hostname);
|
||||
echo json_encode(array(
|
||||
$jsonAnswer = [
|
||||
'device' => [
|
||||
'hostname' => $hostname,
|
||||
'sleepTime' => $device['sleep_time'],
|
||||
],
|
||||
'state' => 'succes',
|
||||
));
|
||||
];
|
||||
|
||||
$subDevicesTypeList = SubDeviceManager::getSubDeviceSTypeForMater($deviceId);
|
||||
if (!in_array($subDevicesTypeList, ['on/off', 'door', 'water'])) {
|
||||
$jsonAnswer['sleepTime'] = $device['sleep_time'];
|
||||
}
|
||||
echo json_encode($jsonAnswer);
|
||||
|
||||
header("HTTP/1.1 200 OK");
|
||||
} else {
|
||||
} else {
|
||||
//Vypis
|
||||
//TODO: doděla uložení výpisu jinými slovy zda li byl comman vykonán
|
||||
$device = DeviceManager::getDeviceByToken($token);
|
||||
|
Loading…
Reference in New Issue
Block a user