Fix
This commit is contained in:
parent
6383034de1
commit
27d2c4fa18
@ -29,56 +29,6 @@ class GoogleHomeApi {
|
||||
}
|
||||
}
|
||||
|
||||
static function query($requestId, $payload){
|
||||
$devices = [];
|
||||
foreach ($payload['devices'] as $deviceId) {
|
||||
$subDeviceData = SubDeviceManager::getSubDevice($deviceId['id']);
|
||||
if ($subDeviceData['type'] != "on/off" && $subDeviceData['type'] != "temp_cont") continue;
|
||||
|
||||
$state = false;
|
||||
if (RecordManager::getLastRecord($deviceId['id'])['value'] == 1){
|
||||
$state = true;
|
||||
}
|
||||
|
||||
$online = false;
|
||||
$status = 'OFFLINE';
|
||||
if (RecordManager::getLastRecord($deviceId['id'])['execuded'] == 1){
|
||||
$online = true;
|
||||
$status = 'SUCCESS';
|
||||
}
|
||||
|
||||
$tempDevice = [
|
||||
$deviceId['id'] => [
|
||||
'online' => $online,
|
||||
'status'=> $status,
|
||||
]
|
||||
];
|
||||
|
||||
if ($subDeviceData['type'] == "temp_cont"){
|
||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
||||
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = RecordManager::getLastRecord($deviceId['id'])['value'];
|
||||
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = RecordManager::getLastRecord($deviceId['id'])['value'];
|
||||
} else {
|
||||
$tempDevice[$deviceId['id']]['on'] = $state;
|
||||
}
|
||||
$devices = $tempDevice;
|
||||
if (count($devices)> 1){
|
||||
$devices[] = $tempDevice;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$response = [
|
||||
'requestId' => $requestId,
|
||||
'payload' => [
|
||||
'devices' => $devices,
|
||||
],
|
||||
];
|
||||
|
||||
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
||||
$apiLogManager->write("[API] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
||||
echo json_encode($response);
|
||||
}
|
||||
static function sync($requestId){
|
||||
$devices = [];
|
||||
|
||||
@ -146,6 +96,57 @@ class GoogleHomeApi {
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
static function query($requestId, $payload){
|
||||
$devices = [];
|
||||
foreach ($payload['devices'] as $deviceId) {
|
||||
$subDeviceData = SubDeviceManager::getSubDevice($deviceId['id']);
|
||||
if ($subDeviceData['type'] != "on/off" && $subDeviceData['type'] != "temp_cont") continue;
|
||||
|
||||
$state = false;
|
||||
if (RecordManager::getLastRecord($deviceId['id'])['value'] == 1){
|
||||
$state = true;
|
||||
}
|
||||
|
||||
$online = false;
|
||||
$status = 'OFFLINE';
|
||||
if (RecordManager::getLastRecord($deviceId['id'])['execuded'] == 1){
|
||||
$online = true;
|
||||
$status = 'SUCCESS';
|
||||
}
|
||||
|
||||
$tempDevice = [
|
||||
$deviceId['id'] => [
|
||||
'online' => $online,
|
||||
'status'=> $status,
|
||||
]
|
||||
];
|
||||
|
||||
if ($subDeviceData['type'] == "temp_cont"){
|
||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
||||
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = RecordManager::getLastRecord($deviceId['id'])['value'];
|
||||
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = RecordManager::getLastRecord($deviceId['id'])['value'];
|
||||
} else {
|
||||
$tempDevice[$deviceId['id']]['on'] = $state;
|
||||
}
|
||||
$devices = $tempDevice;
|
||||
if (count($devices)> 1){
|
||||
$devices[] = $tempDevice;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$response = [
|
||||
'requestId' => $requestId,
|
||||
'payload' => [
|
||||
'devices' => $devices,
|
||||
],
|
||||
];
|
||||
|
||||
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
||||
$apiLogManager->write("[API] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
static function execute($requestId, $payload){
|
||||
$commands = [];
|
||||
|
||||
@ -230,25 +231,14 @@ class GoogleHomeApi {
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
function autorize(){
|
||||
static function autorize(){
|
||||
$json = file_get_contents('php://input');
|
||||
$obj = json_decode($json, true);
|
||||
|
||||
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
||||
$apiLogManager->write("[API] request body\n" . json_encode($obj, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
||||
|
||||
$apiLogManager->write("[API] GET body\n" . json_encode($_GET, JSON_PRETTY_PRINT), LogRecordType::INFO);
|
||||
|
||||
//tel: zemanová 607979429
|
||||
|
||||
/*echo json_encode(array (
|
||||
'access_token' => '',
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => 3600,
|
||||
'refresh_token' => '',
|
||||
'scope' => 'create',
|
||||
));*/
|
||||
|
||||
$get = [
|
||||
"access_token"=>"23165133",
|
||||
"token_type"=>"Bearer",
|
||||
@ -257,5 +247,5 @@ class GoogleHomeApi {
|
||||
|
||||
echo $_GET["redirect_uri"] . '#' . http_build_query($get) ;
|
||||
echo '<a href="'.$_GET["redirect_uri"] . '#' . http_build_query($get) . '">FINISH</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user