Need To be Fixed
This commit is contained in:
parent
27d2c4fa18
commit
13678630f2
@ -1,13 +1,11 @@
|
||||
<?php
|
||||
class GoogleHomeApi {
|
||||
public static function response()
|
||||
{
|
||||
static function response(){
|
||||
set_time_limit (20);
|
||||
$json = file_get_contents('php://input');
|
||||
$obj = json_decode($json, true);
|
||||
|
||||
$apiLogManager = new LogManager('../logs/api/HA/'. date("Y-m-d").'.log');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
switch ($obj['inputs'][0]['intent']) {
|
||||
@ -42,7 +40,7 @@ class GoogleHomeApi {
|
||||
|
||||
$tempDevice = [
|
||||
'id' => (string) $subDeviceData['subdevice_id'],
|
||||
'type' => GoogleHomeDeviceTypes::getEquivalent($subDeviceData['type']),
|
||||
'type' => GoogleHomeDeviceTypes::getAction($subDeviceData['type']),
|
||||
'name' => [
|
||||
'name' => $deviceData['name'],
|
||||
],
|
||||
@ -50,37 +48,11 @@ class GoogleHomeApi {
|
||||
'roomHint' => $roomData['name']
|
||||
];
|
||||
|
||||
//traids
|
||||
switch ($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;
|
||||
}
|
||||
|
||||
|
||||
//traids & Attributes
|
||||
$tempDevice = GoogleHomeDeviceTypes::getSyncObj($tempDevice, GoogleHomeDeviceTypes::getAction($subDeviceData['type']));
|
||||
$devices[] = $tempDevice;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
<?php
|
||||
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 AirFreshener = 'action.devices.types.AIRFRESHENER';
|
||||
const AirPurifier = 'action.devices.types.AIRPURIFIER';
|
||||
@ -74,9 +70,42 @@ class GoogleHomeDeviceTypes {
|
||||
const WaterSoftener = 'action.devices.types.WATERSOFTENER';
|
||||
const Window = 'action.devices.types.WINDOW';
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user