Google API change Fix

This commit is contained in:
GamerClassN7 2021-04-11 10:40:32 +02:00
parent 9c565d90fa
commit 0045bdeb84
5 changed files with 31 additions and 20 deletions

View File

@ -66,6 +66,7 @@ $router->post('/cron/automations', 'CronApi@automations');
$router->any('/api/HA/auth', 'Oauth@default');
$router->any('/api/HA/token', 'Oauth@token');
$router->any('/api/HA', 'GoogleHomeApi@response');
$router->any('/api/HA/', 'GoogleHomeApi@response');
//Endpoints API

View File

@ -26,7 +26,6 @@ if (
$get = [
"state"=>$state,
"code"=>$token,
"access_token"=>$token,
"state"=>$state,
];
} else {

View File

@ -1,4 +1,5 @@
<?php
https://console.cloud.google.com/logs/query;cursorTimestamp=2021-04-11T07:51:16.567357750Z?project=simple-home-79188
class GoogleHome
{
static function sync($requestId)
@ -42,7 +43,10 @@ class GoogleHome
],
'willReportState' => false,
'roomHint' => $roomData['name']
'roomHint' => $roomData['name'],
"otherDeviceIds" => [
["deviceId" => "SH#".(string) $deviceData['device_id']]
]
];
if ($tempDevice['attributes'] == null) unset($tempDevice['attributes']);

View File

@ -1,5 +1,6 @@
<?php
class GoogleHomeDeviceTypes {
class GoogleHomeDeviceTypes
{
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
const AirFreshener = 'action.devices.types.AIRFRESHENER';
const AirPurifier = 'action.devices.types.AIRPURIFIER';
@ -107,7 +108,7 @@ class GoogleHomeDeviceTypes {
'commandOnlyOnOff' => false,
],
'temp_cont' => [
'availableThermostatModes' => 'off,heat',
'availableThermostatModes' => ['off', 'heat'],
'thermostatTemperatureUnit' => 'C',
],
'vol_cont' => [
@ -159,27 +160,32 @@ class GoogleHomeDeviceTypes {
],
];
static function getAction($deviceType){
static function getAction($deviceType)
{
if (!isset(self::$actionWordBook[$deviceType])) return;
return self::$actionWordBook[$deviceType];
}
static function getTraid($subDeviceType){
static function getTraid($subDeviceType)
{
if (!isset(self::$traidWordBook[$subDeviceType])) return;
return self::$traidWordBook[$subDeviceType];
}
static function getType($subDeviceCommand){
static function getType($subDeviceCommand)
{
if (!isset(self::$commandWordBook[$subDeviceCommand])) return;
return self::$commandWordBook[$subDeviceCommand];
}
static function getAttribute($subDeviceType){
static function getAttribute($subDeviceType)
{
if (!isset(self::$attributeWordBook[$subDeviceType])) return;
return self::$attributeWordBook[$subDeviceType];
}
static function getQueryJson($deviceType, $type){
static function getQueryJson($deviceType, $type)
{
return self::$wordBook[$type];
}
}

View File

@ -9,9 +9,9 @@ class Oauth
//Log
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::INFO);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::INFO);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::INFO);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
$userManager = new UserManager();
$langMng = new LanguageManager('en');
@ -49,10 +49,10 @@ class Oauth
//Log
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::INFO);
$logManager->write("[OAUTH] POST " . json_encode($_POST), LogRecordTypes::INFO);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::INFO);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::INFO);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] POST " . json_encode($_POST), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
// $template = new Template('oauth');
// $template->prepare('baseDir', BASEDIR);
@ -63,12 +63,13 @@ class Oauth
$token = $_POST["code"];
$get = [
"access_token" => $token,
"token_type" => "bearer",
"token_type" => "Bearer",
"refresh_token" => $token,
"scope" => 'user',
//"expires_in" => 63113851,
];
$logManager->write("[OAUTH] Response " . json_encode($get), LogRecordTypes::INFO);
$logManager->write("[OAUTH] Response " . json_encode($get), LogRecordTypes::WARNING);
echo json_encode($get);
die();
}