Keep record of record origin

This commit is contained in:
Václav Španinger 2021-02-02 12:47:41 +01:00
parent 1f49391b36
commit 2410441b88
4 changed files with 21 additions and 12 deletions

View File

@ -113,7 +113,7 @@ class EndpointsApi extends ApiController{
}
$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);
//notification

View File

@ -14,7 +14,7 @@ class WidgetApi extends ApiController
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
if ($subDeviceData['type'] == 'on/off') {
$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;
} else {
throw new Exception("Bad Request", 403);

View File

@ -249,7 +249,7 @@ class GoogleHome
if ($executionCommand['params']['on']) $value = 1;
RecordManager::createWithSubId($subDeviceId, $value);
RecordManager::createWithSubId($subDeviceId, $value, 'google');
$executed = 0;
$waiting = 0;
@ -288,7 +288,7 @@ class GoogleHome
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
}
RecordManager::createWithSubId($subDeviceId, $value);
RecordManager::createWithSubId($subDeviceId, $value, 'google');
$executed = 0;
$waiting = 0;
@ -332,7 +332,7 @@ class GoogleHome
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
}
RecordManager::createWithSubId($subDeviceId, $value);
RecordManager::createWithSubId($subDeviceId, $value, 'google');
$executed = 0;
$waiting = 0;

View File

@ -2,16 +2,21 @@
class RecordManager{
public static $records;
public static function createWithSubId ($subDeviceId, $value) {
public static function createWithSubId ($subDeviceId, $value, $origin = false) {
try {
$record = [
'execuded' => 1,
];
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
$record = array (
'subdevice_id' => $subDeviceId,
'value' => $value,
);
if ($origin != false)
$record['Origin'] = $origin;
return Db::add ('records', $record);
} catch(PDOException $error) {
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'];
if ($subDeviceId == '') {
return false;
@ -42,6 +47,10 @@ class RecordManager{
'subdevice_id' => $subDeviceId,
'value' => $value,
);
if ($origin != false)
$record['Origin'] = $origin;
return Db::add ('records', $record);
} catch(PDOException $error) {
echo $error->getMessage();