Compare commits
3 Commits
3.0
...
2410441b88
| Author | SHA1 | Date | |
|---|---|---|---|
| 2410441b88 | |||
|
|
1f49391b36 | ||
|
|
c17e3090a8 |
@@ -113,7 +113,7 @@ class EndpointsApi extends ApiController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subDeviceLastReordValue[$key] = $value['value'];
|
$subDeviceLastReordValue[$key] = $value['value'];
|
||||||
RecordManager::create($device['device_id'], $key, round($value['value'],3));
|
RecordManager::create($device['device_id'], $key, round($value['value'],3), 'device');
|
||||||
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
||||||
|
|
||||||
//notification
|
//notification
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class WidgetApi extends ApiController
|
|||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||||
if ($subDeviceData['type'] == 'on/off') {
|
if ($subDeviceData['type'] == 'on/off') {
|
||||||
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
||||||
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue);
|
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue, "vue-app");
|
||||||
$response = !$lastValue;
|
$response = !$lastValue;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Bad Request", 403);
|
throw new Exception("Bad Request", 403);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class GoogleHome {
|
class GoogleHome
|
||||||
static function sync($requestId){
|
{
|
||||||
|
static function sync($requestId)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$roomsData = RoomManager::getAllRooms();
|
$roomsData = RoomManager::getAllRooms();
|
||||||
foreach ($roomsData as $roomKey => $roomData) {
|
foreach ($roomsData as $roomKey => $roomData) {
|
||||||
@@ -26,7 +28,7 @@ class GoogleHome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($traids < 1){
|
if ($traids < 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,43 +55,45 @@ class GoogleHome {
|
|||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
'payload' => [
|
'payload' => [
|
||||||
'agentUserId'=>'651351531531',
|
'agentUserId' => '651351531531',
|
||||||
'devices' => array_values( $devices ),
|
'devices' => array_values($devices),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function query($requestId, $payload){
|
static function query($requestId, $payload)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$num = 0;
|
$num = 0;
|
||||||
foreach ($payload['devices'] as $deviceId) {
|
foreach ($payload['devices'] as $deviceId) {
|
||||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id']);
|
|
||||||
|
|
||||||
$tempDevice[$deviceId['id']] = [
|
$tempDevice[$deviceId['id']] = [
|
||||||
'online' => false,
|
'online' => false,
|
||||||
'status' => 'OFFLINE',
|
'status' => 'OFFLINE',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
||||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||||
if ($lastRecord['execuded'] == 1){
|
if ($lastRecord != false && $lastRecord['execuded'] == 1) {
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
||||||
} else {
|
} else {
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,29 +125,33 @@ class GoogleHome {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($lastRecord['execuded'] == 1){
|
// $lastRecord = RecordManager::getLastRecord($deviceId['id']);
|
||||||
$online = true;
|
// //var_dump($lastRecord);
|
||||||
$status = 'SUCCESS';
|
// if ($lastRecord['execuded'] == 1) {
|
||||||
} else {
|
// $online = true;
|
||||||
|
// $status = 'SUCCESS';
|
||||||
|
// } else {
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
|
||||||
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
$devices = $tempDevice;
|
$devices = $tempDevice;
|
||||||
/*if (count($devices)> 1){
|
if (count($devices)> 1){
|
||||||
$devices[] = $tempDevice;
|
$devices[] = $tempDevice;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
@@ -151,13 +159,14 @@ class GoogleHome {
|
|||||||
'devices' => $devices,
|
'devices' => $devices,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function execute($requestId, $payload){
|
static function execute($requestId, $payload)
|
||||||
|
{
|
||||||
$commands = [];
|
$commands = [];
|
||||||
foreach ($payload['commands'] as $key => $command) {
|
foreach ($payload['commands'] as $key => $command) {
|
||||||
foreach ($command['devices'] as $key2 => $device) {
|
foreach ($command['devices'] as $key2 => $device) {
|
||||||
@@ -167,7 +176,8 @@ static function execute($requestId, $payload){
|
|||||||
}
|
}
|
||||||
|
|
||||||
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
||||||
$subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)['subdevice_id'];
|
if ($subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)) {
|
||||||
|
$subDeviceId = $subDeviceId['subdevice_id'];
|
||||||
switch ($executionCommand['command']) {
|
switch ($executionCommand['command']) {
|
||||||
case 'action.devices.commands.OnOff':
|
case 'action.devices.commands.OnOff':
|
||||||
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
||||||
@@ -212,9 +222,10 @@ static function execute($requestId, $payload){
|
|||||||
case 'action.devices.commands.mediaStop':
|
case 'action.devices.commands.mediaStop':
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
@@ -223,33 +234,34 @@ static function execute($requestId, $payload){
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
|
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeSwitch($subDeviceId, $executionCommand){
|
static function executeSwitch($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
|
|
||||||
if ($executionCommand['params']['on']) $value = 1;
|
if ($executionCommand['params']['on']) $value = 1;
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
}
|
||||||
@@ -264,9 +276,10 @@ static function executeSwitch($subDeviceId, $executionCommand){
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeTermostatValue($subDeviceId, $executionCommand){
|
static function executeTermostatValue($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -275,19 +288,19 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
|||||||
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
||||||
if ($lastValue['execuded'] == 1){
|
if ($lastValue['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;;
|
$online = true;;
|
||||||
}
|
}
|
||||||
@@ -305,9 +318,10 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeTermostatMode($subDeviceId, $executionCommand){
|
static function executeTermostatMode($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$mode = "off";
|
$mode = "off";
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
@@ -318,19 +332,19 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
|||||||
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
}
|
||||||
@@ -346,9 +360,10 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeVolume($subDeviceId, $executionCommand){
|
static function executeVolume($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['volumeLevel'];
|
//echo $executionCommand['params']['volumeLevel'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -360,13 +375,13 @@ static function executeVolume($subDeviceId, $executionCommand){
|
|||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
$currentVolume = $executionCommand['params']['volumeLevel'];
|
$currentVolume = $executionCommand['params']['volumeLevel'];
|
||||||
@@ -384,9 +399,10 @@ static function executeVolume($subDeviceId, $executionCommand){
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeApp($subDeviceId, $executionCommand){
|
static function executeApp($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['newApplication'];
|
//echo $executionCommand['params']['newApplication'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -398,13 +414,13 @@ static function executeApp($subDeviceId, $executionCommand){
|
|||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
$currentApplication = $executionCommand['params']['newApplication'];
|
$currentApplication = $executionCommand['params']['newApplication'];
|
||||||
@@ -422,9 +438,10 @@ static function executeApp($subDeviceId, $executionCommand){
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeInput($subDeviceId, $executionCommand){
|
static function executeInput($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['newInput'];
|
//echo $executionCommand['params']['newInput'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -436,13 +453,13 @@ static function executeInput($subDeviceId, $executionCommand){
|
|||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
if ($value['execuded'] == 1){
|
if ($value['execuded'] == 1) {
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed){
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
$currentInput = $executionCommand['params']['newInput'];
|
$currentInput = $executionCommand['params']['newInput'];
|
||||||
@@ -460,9 +477,10 @@ static function executeInput($subDeviceId, $executionCommand){
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeMediaCont($subDeviceId, $executionCommand){
|
static function executeMediaCont($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$status = 'SUCCESS';
|
$status = 'SUCCESS';
|
||||||
$online = true;
|
$online = true;
|
||||||
|
|
||||||
@@ -476,5 +494,5 @@ static function executeMediaCont($subDeviceId, $executionCommand){
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,21 @@
|
|||||||
class RecordManager{
|
class RecordManager{
|
||||||
public static $records;
|
public static $records;
|
||||||
|
|
||||||
public static function createWithSubId ($subDeviceId, $value) {
|
public static function createWithSubId ($subDeviceId, $value, $origin = false) {
|
||||||
try {
|
try {
|
||||||
$record = [
|
$record = [
|
||||||
'execuded' => 1,
|
'execuded' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
||||||
$record = array (
|
$record = array (
|
||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
@@ -19,7 +24,7 @@ class RecordManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($deviceId, $type, $value) {
|
public static function create ($deviceId, $type, $value, $origin = false) {
|
||||||
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
||||||
if ($subDeviceId == '') {
|
if ($subDeviceId == '') {
|
||||||
return false;
|
return false;
|
||||||
@@ -28,7 +33,7 @@ class RecordManager{
|
|||||||
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
||||||
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
||||||
|
|
||||||
if ($lastRecord['value'] == $value){
|
if (isset($lastRecord['value']) && $lastRecord['value'] == $value){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +47,10 @@ class RecordManager{
|
|||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user