2 Commits

Author SHA1 Message Date
GamerClassN7
0045bdeb84 Google API change Fix 2021-04-11 10:40:32 +02:00
GamerClassN7
9c565d90fa Minor Bug Fixes 2021-04-05 20:02:11 +02:00
9 changed files with 54 additions and 35 deletions

View File

@@ -17,7 +17,7 @@ RewriteCond %{REQUEST_FILENAME} \.
RewriteRule (.*) ./public/$1 [L] RewriteRule (.*) ./public/$1 [L]
# serve all other request as query parameters # serve all other request as query parameters
# RewriteRule (.*) ./public/index.php?url=$1 [L,QSA] RewriteRule (.*) ./public/index.php?url=$1 [L,QSA]
RewriteRule ^(.*?\.php)/([^/]*)/([^/]*)(/.+)? ./public/index.php?url=$1&$2&$3 [NC,N,QSA] #RewriteRule ^(.*?\.php)/([^/]*)/([^/]*)(/.+)? ./public/index.php?url=$1&$2&$3 [NC,N,QSA]
AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php .php .phtml

View File

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

View File

@@ -2,18 +2,18 @@
class RoomsApi extends ApiController class RoomsApi extends ApiController
{ {
public function default() public function default()
{ {
//$this->requireAuth(); //$this->requireAuth();
$response = []; $response = [];
$roomIds = []; $roomIds = [];
$roomsData = RoomManager::getRoomsDefault(); $roomsData = RoomManager::getRoomsDefault();
foreach ($roomsData as $roomKey => $room) { foreach ($roomsData as $roomKey => $room) {
$roomIds[] = $room['room_id']; $roomIds[] = $room['room_id'];
} }
//Translation Of Numeric Walues //Translation Of Numeric Walues
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds); $subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
foreach ($subDevicesData as $subDeviceKey => $subDevice) { foreach ($subDevicesData as $subDeviceKey => $subDevice) {
@@ -25,14 +25,21 @@ class RoomsApi extends ApiController
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) { } else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type']; $type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
} }
//Connection Error Creation //Connection Error Creation
$connectionError = true; $connectionError = true;
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['time']); $LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['heartbeat']);
$interval = $LastRecordTime->diff(new DateTime()); $interval = $LastRecordTime->diff(new DateTime());
$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
if ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == NULL || $subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 || $lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time']) { $lastSeen = $interval->days * 24 * 60;
$lastSeen += $interval->h * 60;
$lastSeen += $interval->i;
//$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
if ($lastSeen < ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 ? 15 : $subDevicesData[$subDeviceKey][$key]['sleep_time'])) {
$connectionError = false; $connectionError = false;
} }
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError; $subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError;
@@ -50,7 +57,7 @@ class RoomsApi extends ApiController
} }
} }
} }
foreach ($roomsData as $roomKey => $roomData) { foreach ($roomsData as $roomKey => $roomData) {
if ($roomData['device_count'] == 0) continue; if ($roomData['device_count'] == 0) continue;
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : []; $subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
@@ -64,11 +71,11 @@ class RoomsApi extends ApiController
$this->response($response); $this->response($response);
} }
public function update($roomId) public function update($roomId)
{ {
//$this->requireAuth(); //$this->requireAuth();
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]); $subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]);
$this->response($subDevicesData); $this->response($subDevicesData);
} }

View File

@@ -149,7 +149,8 @@ class WidgetApi extends ApiController
} }
} }
$subDeviceData = SubDeviceManager::edit($subDeviceId, $obj); echo $subDeviceId;
echo SubDeviceManager::edit($subDeviceId, $obj);
$response = [ $response = [
"value" => "OK" "value" => "OK"

View File

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

View File

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

View File

@@ -92,7 +92,7 @@ class SubDeviceManager
//TODO: @Patrik Check line 89 //TODO: @Patrik Check line 89
$rows = Db::loadAll(" $rows = Db::loadAll("
SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.device_id, COALESCE(sd.icon, d.icon) AS icon, COALESCE(sd.name, d.name) AS name, sd.type, sd.unit, r.value, r.time FROM subdevices sd SELECT d.room_id, d.sleep_time, d.heartbeat, sd.subdevice_id, sd.device_id, COALESCE(sd.icon, d.icon) AS icon, COALESCE(sd.name, d.name) AS name, sd.type, sd.unit, r.value, r.time FROM subdevices sd
JOIN devices d ON sd.device_id = d.device_id JOIN devices d ON sd.device_id = d.device_id
JOIN records r ON r.subdevice_id = sd.subdevice_id JOIN records r ON r.subdevice_id = sd.subdevice_id
WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?) WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?)

View File

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

View File

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