Commit da6e374d authored by Langston Ball's avatar Langston Ball

refs #2806 - Add stub for color changing, update discovery

parent 0e9ecb7d
......@@ -145,7 +145,7 @@ class AlexaController extends AppController
'error'=>$error
);
$device = $DeviceList->get($deviceTarget, ['contain'=>['DeviceTemplate', 'Device_DeviceData'] ] );
$device = $DeviceList->get($deviceTarget, ['contain'=>['DevdiscovericeTemplate', 'Device_DeviceData'] ] );
if($device->device_template->FK_DeviceCategory==73){
......@@ -157,32 +157,32 @@ class AlexaController extends AppController
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
public function colorCommand(){
$requestData = $this->request->getData('body');
$rep = $this->DceCommandExecutor->sendColorCommand(json_decode($requestData));
$now = Time::now();
$now->format('e');
$reply = array(
'status' => $rep,
'timeSent'=>$now,
'error'=>"none"
);
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
public function report(){
$deviceTarget = $this->request->params['?']['device'];
$error = "none";
$deviceTarget = $this->request->params['?']['device'];
$DeviceList = TableRegistry::get('Devices');
$reply = $DeviceList->handleDeviceReport($deviceTarget);
$now = Time::now();
$now->format('e');
$now->format('e');
$reply= array(
'status' => "OK",
'timeSent'=>$now,
'error'=>$error
);
if(isset($deviceTarget)){
$DeviceList = TableRegistry::get('Devices');
$device = $DeviceList->get($deviceTarget, ['contain'=>['DeviceTemplate', 'Device_DeviceData'] ] );
if($device->device_template->FK_DeviceCategory==73){
$lightState = explode("/", $device->State);
$reply['bri'] = $lightState[1];
$reply['lightState'] = $lightState[0];
}
} else {
$error = "invalid device";
}
$reply['timeSent'] = $now;
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
......@@ -215,10 +215,7 @@ class AlexaController extends AppController
}
public function findMovieByName(){
$error = "none";
$now = Time::now();
$now->format('e');
$status ="";
$movieName = $this->request->getQuery('name');
$roomRequest = $this->request->getQuery('room');
......@@ -227,11 +224,7 @@ class AlexaController extends AppController
$Linuxmcefile = TableRegistry::get('Linuxmcefile');
$movieReply = $Linuxmcefile->getVideoByName($movieName);
$reply= array(
'status' => $status,
'timeSent'=>$now,
'error'=>$error
);
$reply= $this->buildResponseTemplate();
$reply['movie']=$movieReply;
$reply['room'] = array(
......@@ -242,8 +235,8 @@ class AlexaController extends AppController
if($reply['movie']['count']==0){
$reply['status'] = 'error';
$reply["error"] = 'movie not found';
}
else if ($roomRequest==-1)
}
else if ($room==-1)
{
$reply['status'] = 'error';
$reply['error'] = 'Incorrect room';
......@@ -252,23 +245,13 @@ class AlexaController extends AppController
$reply['status'] = 'OK';
}
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
public function findRoomByName($roomName){
$error = "none";
$now = Time::now();
$now->format('e');
$status ="";
public function findRoomByName($roomName){
$EA = TableRegistry::get('Entertainarea');
$targetEa = $EA->getEntertainAreaFromName($roomName);
$targetEa = $EA->getEntertainAreaFromName($roomName);
return $targetEa;
}
......@@ -278,4 +261,51 @@ class AlexaController extends AppController
return $status;
}
public function stopMediaInRoom(){
$reply = $this->buildResponseTemplate();
$room = $this->request->getQuery('room');
$targetEa = $this->findRoomByName($room);
if($targetEa==-1){
$reply['status'] = 'error';
$reply['error'] = 'Incorrect room';
} else {
$reply['status'] = $this->DceCommandExecutor->stopMediaInRoom($targetEa);
}
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
public function pauseMediaInRoom(){
$room = $this->request->getQuery('room');
$targetEa = $EA->getEntertainAreaFromName($room);
if($targetEa==-1){
$reply['status'] = 'error';
$reply['error'] = 'Incorrect room';
} else {
//$status = $this->DceCommandExecutor->pauseMediaInRoom($targetEa);
}
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
function buildResponseTemplate(){
$now = Time::now();
$now->format('e');
$replyTemplate = array(
'error' => 'none',
'status' => 'OK',
'timeSent' => $now
);
return $replyTemplate;
}
}
......@@ -87,6 +87,21 @@ class DceCommandExecutorComponent extends Component
$response = $this->executeFormedCommand($device, $params);
return $response;
}
function sendColorCommand($data){
$params=array(
'msgid' => 1115,
'params' => array(
array('76', $data['brightness']*100),
array('266', $data['hue']),
array('287', $data['saturation']*100)
)
);
$response = $this->executeFormedCommand($data['device'], $params);
return $response;
}
function sendLightOffCommand($device){
$params = array(
......
......@@ -11,6 +11,10 @@ class DevicesTable extends Table{
public function initialize(array $config){
$this->setTable('Device');
$this->primaryKey('PK_Device');
$this->colorDeviceTemplates= array(2319,2257);
$this->tunableDeviceTemplates = array(2362,2257);
$this->dimmableDeviceTemplates = array(2318);
$this->excludedDevices = array(2358, 2359, 2361);
$this->hasOne( 'Room',
......@@ -62,6 +66,8 @@ public function initialize(array $config){
function findByDeviceCategory(Query $query, array $options){
$cat = $options['category'];
return $query
->contain(['DeviceTemplate','Room', 'DeviceData', 'Device_DeviceData'] )
->matching('DeviceTemplate', function ($q) use ($cat) {
......@@ -75,10 +81,16 @@ function findByDeviceCategory(Query $query, array $options){
$devices = TableRegistry::get('Devices');
$lightList = $this->find('byDeviceCategory', ['category'=> "73"]);
$alexaObject = array();
foreach($lightList as $light){
if(in_array($light->device_template->PK_DeviceTemplate, $this->excludedDevices)){
break;
}
$appendArry = array(
'endpointId' => (string) $light->PK_Device,
'friendlyName' =>$light['Description'],
......@@ -111,9 +123,40 @@ function findByDeviceCategory(Query $query, array $options){
'retrievable' => true
)
]
)
)
);
if( in_array($light->device_template->PK_DeviceTemplate, $this->colorDeviceTemplates ) ){
$appendArry['capabilities'][]= [
'type'=>'AlexaInterface',
'interface' => 'Alexa.ColorController',
'version' => '3',
'properties' => array(
'supported'=> [array(
'name' => 'color'
)],
'retrievable' => true
)
];
}
if ( in_array($light->device_template->PK_DeviceTemplate, $this->tunableDeviceTemplates ) ){
$appendArry['capabilities'][]= [
'type'=>'AlexaInterface',
'interface' => 'Alexa.ColorTemperatureController',
'version' => '3',
'properties' => array(
'supported'=> [array(
'name' => 'colorTemperatureInKelvin'
)],
'retrievable' => true
)
];
}
$alexaObject[] = $appendArry;
}
......@@ -241,11 +284,41 @@ function findByDeviceCategory(Query $query, array $options){
}
function deviceDataForDevice($deviceId){
}
function handleDeviceReport($deviceTarget){
$DeviceList = TableRegistry::get('Devices');
$device = $DeviceList->get($deviceTarget, ['contain'=>['DeviceTemplate', 'Device_DeviceData'] ] );
$reply = array();
$reply['error']="none";
if($device->device_template->FK_DeviceCategory==73){
$lightState = explode("/", $device->State);
$reply['bri'] = $lightState[1];
$reply['lightState'] = $lightState[0];
if( in_array($device->device_template->PK_DeviceTemplate, $this->colorDeviceTemplates) ){
$hueCurrentColor = json_decode($device->device__device_data[5]->IK_DeviceData, true);
$hsl = $hueCurrentColor["color"]["currentColor"]["hsl"];
$reply['color'] = array(
"hsb"=>[
"h"=>$hsl["h"],
"s"=>$hsl["s"],
"b"=>$hsl["l"]
]
);
} 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;
}
}
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