Commit 4d9e777f authored by Langston Ball's avatar Langston Ball

ref #2806 update external api commands for web interface

parent f1b98f43
......@@ -105,8 +105,7 @@ class AlexaController extends AppController
function brightnessCommand(){
//$this->request->allowMethod(['POST', 'post']);
$DeviceList = TableRegistry::get('Devices');
$DeviceList = TableRegistry::get('Devices');
$deviceTarget = $this->request->params['?']['device'];
$mode = $this->request->params['?']['mode'];
......@@ -159,16 +158,22 @@ class AlexaController extends AppController
}
public function colorCommand(){
$requestData = $this->request->getData('body');
$rep = $this->DceCommandExecutor->sendColorCommand(json_decode($requestData));
$this->request->allowMethod('POST');
$requestData = $this->request->data("body");
$rep = "error";
if(isset($requestData["colorTemp"]) ){
$rep = $this->DceCommandExecutor->sendColorTempCommand($requestData);
} else if(isset($requestData["color"]) ){
$rep = $this->DceCommandExecutor->sendColorCommand($requestData);
}
$now = Time::now();
$now->format('e');
$reply = array(
'status' => $rep,
'status' => "OK",
'timeSent'=>$now,
'error'=>"none"
'error'=>"none",
'colordata'=>$rep
);
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
......
......@@ -89,18 +89,47 @@ class DceCommandExecutorComponent extends Component
}
function sendColorCommand($data){
$params=array(
'msgid' => 1115,
'params' => array(
array('76', $data['brightness']*100),
array('266', $data['hue']),
array('287', $data['saturation']*100)
array('76', $data['color']['color']['brightness']*255),
array('286', $data['color']['color']['hue']),
array('287', $data['color']['color']['saturation']*255)
)
);
$response = $this->executeFormedCommand($data['device'], $params);
return $response;
if($response=="OK"){
return array(
"h"=>$data['color']['color']['hue'],
"s"=>$data['color']['color']['saturation'],
"b"=>$data['color']['color']['brightness']
);
} else {
return array(
"h"=>0,
"s"=>0,
"b"=>0
);
}
}
function sendColorTempCommand($data){
$colorTempValue = $data['colorTemp']['colorTemperatureInKelvin'];
$finalColorTempVal = ( ($colorTempValue - 1000) / (10000 - 1000) ) * (6500 - 2000) + 2000 ;
$params=array(
'msgid' => 1160,
'params' => array(
array('48', $finalColorTempVal)
)
);
$this->executeFormedCommand($data['device'], $params);
return $data['colorTemp']['colorTemperatureInKelvin'];
}
function sendLightOffCommand($device){
......
......@@ -307,14 +307,14 @@ function findByDeviceCategory(Query $query, array $options){
$reply['color'] = array(
"hsb"=>[
"h"=>$hsl["h"],
"s"=>$hsl["s"],
"b"=>$hsl["l"]
"s"=>$hsl["s"]*.001,
"b"=>$hsl["l"]*.001
]
);
} else if( in_array($device->device_template->PK_DeviceTemplate, $this->tunableDeviceTemplates) ){
$hueCurrentColor = json_decode($device->device__device_data[5]->IK_DeviceData, true);
$colorTemp = $hueCurrentColor["color"]["currentColorTemp"];
$reply['colorTemperatureInKelvin'] = $colorTemp;
$reply['colorTemperatureInKelvin'] = $colorTemp*10;
}
}
return $reply;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment