Need To be Fixed

This commit is contained in:
JonatanRek 2020-05-03 19:29:15 +02:00
parent 27d2c4fa18
commit 13678630f2
2 changed files with 106 additions and 105 deletions

View File

@ -1,13 +1,11 @@
<?php <?php
class GoogleHomeApi { class GoogleHomeApi {
public static function response() static function response(){
{
set_time_limit (20); set_time_limit (20);
$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');
header('Content-Type: application/json'); header('Content-Type: application/json');
switch ($obj['inputs'][0]['intent']) { switch ($obj['inputs'][0]['intent']) {
@ -42,7 +40,7 @@ class GoogleHomeApi {
$tempDevice = [ $tempDevice = [
'id' => (string) $subDeviceData['subdevice_id'], 'id' => (string) $subDeviceData['subdevice_id'],
'type' => GoogleHomeDeviceTypes::getEquivalent($subDeviceData['type']), 'type' => GoogleHomeDeviceTypes::getAction($subDeviceData['type']),
'name' => [ 'name' => [
'name' => $deviceData['name'], 'name' => $deviceData['name'],
], ],
@ -50,37 +48,11 @@ class GoogleHomeApi {
'roomHint' => $roomData['name'] 'roomHint' => $roomData['name']
]; ];
//traids //traids & Attributes
switch ($subDeviceData['type']) { $tempDevice = GoogleHomeDeviceTypes::getSyncObj($tempDevice, GoogleHomeDeviceTypes::getAction($subDeviceData['type']));
case 'on/off':
$tempDevice['traits'] = [ 'action.devices.traits.OnOff' ];
break;
case 'temp_cont':
$tempDevice['attributes'] = [
"availableThermostatModes" => "off,heat,on",
"thermostatTemperatureRange" => [
'minThresholdCelsius' => 5,
'maxThresholdCelsius' => 15,
],
"thermostatTemperatureUnit" => "C",
"commandOnlyTemperatureSetting" => false,
"queryOnlyTemperatureSetting" => false,
"bufferRangeCelsius" => 0,
];
$tempDevice['traits'] = [
'action.devices.traits.TemperatureSetting',
];
break;
}
$devices[] = $tempDevice; $devices[] = $tempDevice;
} }
} }
} }

View File

@ -1,9 +1,5 @@
<?php <?php
class GoogleHomeDeviceTypes { class GoogleHomeDeviceTypes {
private static $wordBook = [
'on/off' => 'action.devices.types.OUTLET',
'temp_cont' => 'action.devices.types.THERMOSTAT',
/*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';
@ -74,9 +70,42 @@ class GoogleHomeDeviceTypes {
const WaterSoftener = 'action.devices.types.WATERSOFTENER'; const WaterSoftener = 'action.devices.types.WATERSOFTENER';
const Window = 'action.devices.types.WINDOW'; const Window = 'action.devices.types.WINDOW';
const YogurtMaker = 'action.devices.types.YOGURTMAKER';*/ const YogurtMaker = 'action.devices.types.YOGURTMAKER';*/
private static $actionWordBook = [
'on/off' => 'action.devices.types.OUTLET',
'temp_cont' => 'action.devices.types.THERMOSTAT',
]; ];
static function getEquivalent($type){ static function getAction($deviceType){
return self::$actionWordBook[$deviceType];
}
static function getSyncObj($deviceBaseObj, $deviceType){
switch ($deviceType) {
case 'action.devices.types.OUTLET':
$deviceBaseObj['traits'] = 'action.devices.traits.OnOff';
break;
case 'action.devices.types.THERMOSTAT':
$deviceBaseObj['traits'] = [
'action.devices.traits.TemperatureSetting',
];
$deviceBaseObj['attributes'] = [
"availableThermostatModes" => "off,heat,on",
"thermostatTemperatureRange" => [
'minThresholdCelsius' => 5,
'maxThresholdCelsius' => 30,
],
"thermostatTemperatureUnit" => "C",
"commandOnlyTemperatureSetting" => false,
"queryOnlyTemperatureSetting" => false,
"bufferRangeCelsius" => 0,
];
break;
}
return $deviceBaseObj;
}
static function getQueryJson($deviceType, $type){
return self::$wordBook[$type]; return self::$wordBook[$type];
} }
} }