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'];
|
||||
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
|
||||
|
@@ -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);
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
class GoogleHome {
|
||||
static function sync($requestId){
|
||||
class GoogleHome
|
||||
{
|
||||
static function sync($requestId)
|
||||
{
|
||||
$devices = [];
|
||||
$roomsData = RoomManager::getAllRooms();
|
||||
foreach ($roomsData as $roomKey => $roomData) {
|
||||
@@ -64,19 +66,21 @@ class GoogleHome {
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
static function query($requestId, $payload){
|
||||
static function query($requestId, $payload)
|
||||
{
|
||||
$devices = [];
|
||||
$num = 0;
|
||||
foreach ($payload['devices'] as $deviceId) {
|
||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id']);
|
||||
|
||||
$tempDevice[$deviceId['id']] = [
|
||||
'online' => false,
|
||||
'status' => 'OFFLINE',
|
||||
];
|
||||
|
||||
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||
if ($lastRecord['execuded'] == 1){
|
||||
if ($lastRecord != false && $lastRecord['execuded'] == 1) {
|
||||
$tempDevice[$deviceId['id']]['online'] = true;
|
||||
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
||||
} else {
|
||||
@@ -121,11 +125,14 @@ class GoogleHome {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($lastRecord['execuded'] == 1){
|
||||
$online = true;
|
||||
$status = 'SUCCESS';
|
||||
} else {
|
||||
// $lastRecord = RecordManager::getLastRecord($deviceId['id']);
|
||||
// //var_dump($lastRecord);
|
||||
// if ($lastRecord['execuded'] == 1) {
|
||||
// $online = true;
|
||||
// $status = 'SUCCESS';
|
||||
// } else {
|
||||
$executed = 0;
|
||||
$waiting = 0;
|
||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||
@@ -135,15 +142,16 @@ class GoogleHome {
|
||||
$waiting++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($waiting < $executed) {
|
||||
$status = "PENDING";
|
||||
$online = true;
|
||||
}
|
||||
}
|
||||
// }
|
||||
$devices = $tempDevice;
|
||||
/*if (count($devices)> 1){
|
||||
if (count($devices)> 1){
|
||||
$devices[] = $tempDevice;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
$response = [
|
||||
'requestId' => $requestId,
|
||||
@@ -157,7 +165,8 @@ class GoogleHome {
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
static function execute($requestId, $payload){
|
||||
static function execute($requestId, $payload)
|
||||
{
|
||||
$commands = [];
|
||||
foreach ($payload['commands'] as $key => $command) {
|
||||
foreach ($command['devices'] as $key2 => $device) {
|
||||
@@ -167,7 +176,8 @@ static function execute($requestId, $payload){
|
||||
}
|
||||
|
||||
$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']) {
|
||||
case 'action.devices.commands.OnOff':
|
||||
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
||||
@@ -212,9 +222,10 @@ static function execute($requestId, $payload){
|
||||
case 'action.devices.commands.mediaStop':
|
||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$response = [
|
||||
'requestId' => $requestId,
|
||||
@@ -230,14 +241,15 @@ static function execute($requestId, $payload){
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
static function executeSwitch($subDeviceId, $executionCommand){
|
||||
static function executeSwitch($subDeviceId, $executionCommand)
|
||||
{
|
||||
$value = 0;
|
||||
$status = 'OFFLINE';
|
||||
$online = false;
|
||||
|
||||
if ($executionCommand['params']['on']) $value = 1;
|
||||
|
||||
RecordManager::createWithSubId($subDeviceId, $value);
|
||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||
|
||||
$executed = 0;
|
||||
$waiting = 0;
|
||||
@@ -266,7 +278,8 @@ static function executeSwitch($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeTermostatValue($subDeviceId, $executionCommand){
|
||||
static function executeTermostatValue($subDeviceId, $executionCommand)
|
||||
{
|
||||
$value = 0;
|
||||
$status = 'OFFLINE';
|
||||
$online = false;
|
||||
@@ -275,7 +288,7 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
||||
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
||||
}
|
||||
|
||||
RecordManager::createWithSubId($subDeviceId, $value);
|
||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||
|
||||
$executed = 0;
|
||||
$waiting = 0;
|
||||
@@ -307,7 +320,8 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeTermostatMode($subDeviceId, $executionCommand){
|
||||
static function executeTermostatMode($subDeviceId, $executionCommand)
|
||||
{
|
||||
$mode = "off";
|
||||
$value = 0;
|
||||
$status = 'OFFLINE';
|
||||
@@ -318,7 +332,7 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
||||
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
||||
}
|
||||
|
||||
RecordManager::createWithSubId($subDeviceId, $value);
|
||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||
|
||||
$executed = 0;
|
||||
$waiting = 0;
|
||||
@@ -348,7 +362,8 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeVolume($subDeviceId, $executionCommand){
|
||||
static function executeVolume($subDeviceId, $executionCommand)
|
||||
{
|
||||
//echo $executionCommand['params']['volumeLevel'];
|
||||
$status = 'OFFLINE';
|
||||
$online = false;
|
||||
@@ -386,7 +401,8 @@ static function executeVolume($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeApp($subDeviceId, $executionCommand){
|
||||
static function executeApp($subDeviceId, $executionCommand)
|
||||
{
|
||||
//echo $executionCommand['params']['newApplication'];
|
||||
$status = 'OFFLINE';
|
||||
$online = false;
|
||||
@@ -424,7 +440,8 @@ static function executeApp($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeInput($subDeviceId, $executionCommand){
|
||||
static function executeInput($subDeviceId, $executionCommand)
|
||||
{
|
||||
//echo $executionCommand['params']['newInput'];
|
||||
$status = 'OFFLINE';
|
||||
$online = false;
|
||||
@@ -462,7 +479,8 @@ static function executeInput($subDeviceId, $executionCommand){
|
||||
return $commandTemp;
|
||||
}
|
||||
|
||||
static function executeMediaCont($subDeviceId, $executionCommand){
|
||||
static function executeMediaCont($subDeviceId, $executionCommand)
|
||||
{
|
||||
$status = 'SUCCESS';
|
||||
$online = true;
|
||||
|
||||
|
@@ -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;
|
||||
@@ -28,7 +33,7 @@ class RecordManager{
|
||||
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
||||
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
||||
|
||||
if ($lastRecord['value'] == $value){
|
||||
if (isset($lastRecord['value']) && $lastRecord['value'] == $value){
|
||||
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();
|
||||
|
Reference in New Issue
Block a user