Google Home Execution Fix

This commit is contained in:
JonatanRek 2020-06-26 21:35:40 +02:00
parent 4c3aaa40bc
commit 2ddb2750ab
1 changed files with 31 additions and 16 deletions

View File

@ -193,7 +193,9 @@ static function execute($requestId, $payload){
static function executeSwitch($subDeviceId, $executionCommand){ static function executeSwitch($subDeviceId, $executionCommand){
$value = 0; $value = 0;
$status = 'SUCCESS'; $status = 'OFFLINE';
$online = false;
if ($executionCommand['params']['on']) $value = 1; if ($executionCommand['params']['on']) $value = 1;
RecordManager::createWithSubId($subDeviceId, $value); RecordManager::createWithSubId($subDeviceId, $value);
@ -207,17 +209,19 @@ static function executeSwitch($subDeviceId, $executionCommand){
$waiting++; $waiting++;
} }
} }
if ($waiting < $executed){ if ($waiting < $executed){
$status = "PENDING"; $status = "PENDING";
} else { $online = true;
$status = "OFFLINE";
} }
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
$commandTemp = [ $commandTemp = [
'ids' => [$subDeviceId], 'ids' => [(string) $deviceId],
'status' => $status, 'status' => $status,
'states' => [ 'states' => [
'on' => $executionCommand['params']['on'], 'on' => $executionCommand['params']['on'],
'online' => $online,
], ],
]; ];
return $commandTemp; return $commandTemp;
@ -225,7 +229,8 @@ static function executeSwitch($subDeviceId, $executionCommand){
static function executeTermostatValue($subDeviceId, $executionCommand){ static function executeTermostatValue($subDeviceId, $executionCommand){
$value = 0; $value = 0;
$status = 'SUCCESS'; $status = 'OFFLINE';
$online = false;
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) { if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) {
$value = $executionCommand['params']['thermostatTemperatureSetpoint']; $value = $executionCommand['params']['thermostatTemperatureSetpoint'];
@ -242,20 +247,21 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
$waiting++; $waiting++;
} }
} }
if ($waiting < $executed){ if ($waiting < $executed){
$status = "PENDING"; $status = "PENDING";
$status = "SUCCESS"; $online = true;;
} else {
$status = "OFFLINE";
} }
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
$commandTemp = [ $commandTemp = [
'ids' => [$subDeviceId], 'ids' => [(string) $deviceId],
'status' => $status, 'status' => $status,
'states' => [ 'states' => [
'thermostatMode' => 'heat', 'thermostatMode' => 'heat',
'thermostatTemperatureSetpoint' => $value, 'thermostatTemperatureSetpoint' => $value,
'thermostatTemperatureAmbient' => $value, 'thermostatTemperatureAmbient' => $value,
'online' => $online,
//ambient z dalšího zenzoru v roomu //ambient z dalšího zenzoru v roomu
], ],
]; ];
@ -265,7 +271,8 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
static function executeTermostatMode($subDeviceId, $executionCommand){ static function executeTermostatMode($subDeviceId, $executionCommand){
$mode = "off"; $mode = "off";
$value = 0; $value = 0;
$status = "SUCCESS"; $status = 'OFFLINE';
$online = false;
if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') { if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') {
$mode = $executionCommand['params']['thermostatMode']; $mode = $executionCommand['params']['thermostatMode'];
@ -283,15 +290,19 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
$waiting++; $waiting++;
} }
} }
if ($waiting < $executed){ if ($waiting < $executed){
$status = "PENDING"; $status = "PENDING";
$online = true;
} }
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
$commandTemp = [ $commandTemp = [
'ids' => [$subDeviceId], 'ids' => [(string) $deviceId],
'status' => $status, 'status' => $status,
'states' => [ 'states' => [
'thermostatMode' => $mode 'thermostatMode' => $mode,
'online' => $online,
], ],
]; ];
@ -299,7 +310,9 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
} }
static function executeVolume($subDeviceId, $executionCommand){ static function executeVolume($subDeviceId, $executionCommand){
$status = "SUCCESS"; $status = 'OFFLINE';
$online = false;
$currentVolume = RecordManager::getLastRecord($subDeviceId)['value']; $currentVolume = RecordManager::getLastRecord($subDeviceId)['value'];
if (isset($executionCommand['params']['volumeLevel'])) { if (isset($executionCommand['params']['volumeLevel'])) {
@ -313,18 +326,20 @@ static function executeVolume($subDeviceId, $executionCommand){
$waiting++; $waiting++;
} }
} }
if ($waiting < $executed){ if ($waiting > $executed){
$status = "PENDING"; $status = "PENDING";
} else { $online = true;
$currentVolume = $executionCommand['params']['volumeLevel']; $currentVolume = $executionCommand['params']['volumeLevel'];
} }
} }
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
$commandTemp = [ $commandTemp = [
'ids' => [$subDeviceId], 'ids' => [(string) $deviceId],
'status' => $status, 'status' => $status,
'states' => [ 'states' => [
'currentVolume' => $currentVolume, 'currentVolume' => $currentVolume,
'online' => $online,
], ],
]; ];