This commit is contained in:
JonatanRek 2020-05-03 19:02:27 +02:00
parent 6383034de1
commit 27d2c4fa18

View File

@ -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){ static function sync($requestId){
$devices = []; $devices = [];
@ -146,6 +96,57 @@ class GoogleHomeApi {
echo json_encode($response); 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){ static function execute($requestId, $payload){
$commands = []; $commands = [];
@ -230,25 +231,14 @@ class GoogleHomeApi {
echo json_encode($response); echo json_encode($response);
} }
function autorize(){ static function autorize(){
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
$obj = json_decode($json, true); $obj = json_decode($json, true);
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log'); $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] 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); $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 = [ $get = [
"access_token"=>"23165133", "access_token"=>"23165133",
"token_type"=>"Bearer", "token_type"=>"Bearer",