Keep record of record origin
This commit is contained in:
parent
1f49391b36
commit
2410441b88
@ -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);
|
||||||
@ -46,7 +46,7 @@ class WidgetApi extends ApiController
|
|||||||
$response = null;
|
$response = null;
|
||||||
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
||||||
|
|
||||||
|
|
||||||
//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){
|
||||||
@ -114,7 +114,7 @@ class WidgetApi extends ApiController
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
//TODO: Make Cleaner
|
//TODO: Make Cleaner
|
||||||
if (isset(RANGES[$subDeviceData['type']])){
|
if (isset(RANGES[$subDeviceData['type']])){
|
||||||
$response['graph']['options']['scales']['yAxes'] = [[
|
$response['graph']['options']['scales']['yAxes'] = [[
|
||||||
'ticks' => [
|
'ticks' => [
|
||||||
@ -124,7 +124,7 @@ class WidgetApi extends ApiController
|
|||||||
]
|
]
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class GoogleHome
|
|||||||
$attributes += $deviceAttributes;
|
$attributes += $deviceAttributes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($traids < 1) {
|
if ($traids < 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class GoogleHome
|
|||||||
'online' => false,
|
'online' => false,
|
||||||
'status' => 'OFFLINE',
|
'status' => 'OFFLINE',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
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']);
|
||||||
@ -249,7 +249,7 @@ class GoogleHome
|
|||||||
|
|
||||||
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;
|
||||||
@ -288,7 +288,7 @@ class GoogleHome
|
|||||||
$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;
|
||||||
@ -332,7 +332,7 @@ class GoogleHome
|
|||||||
$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;
|
||||||
|
@ -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;
|
||||||
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user