Commit cc901cb5 authored by Langston Ball's avatar Langston Ball

Merge branch 'master' of git.linuxmce.org:linuxmce/linuxmce

parents 9730a330 74edd5ce
This diff is collapsed.
......@@ -255,6 +255,11 @@ private:
static const char renameLight[]; /*!< Rename the light \note put */
static const char setLightState[]; /*!< Set properties on the light */
QStringList m_extendedColorLightModels;
QStringList m_colorLightModels;
QStringList m_colorTemperatureModels;
QStringList m_dimmableModels;
};
//<-dceag-end-b->
......
......@@ -19,7 +19,7 @@ AbstractWirelessBulb::AbstractWirelessBulb(HueControllerHardware *p_controller,
m_implementsColor(false),
m_implementsColorTemp(false)
{
conversionVar = ceil(65280 / 360);
conversionVar = ceil(65280 / 360);
m_rgbColor.setRgb(0,0,0);
m_hslColor = m_rgbColor.toHsl();
......@@ -87,7 +87,7 @@ double AbstractWirelessBulb::CurrentLevel() const
void AbstractWirelessBulb::setCurrentLevel(double CurrentLevel)
{
if(m_CurrentLevel == CurrentLevel) return;
if(m_CurrentLevel == CurrentLevel) return;
m_CurrentLevel = CurrentLevel;
emit currentLevelChanged();
......@@ -107,9 +107,9 @@ void AbstractWirelessBulb::setPowerOn(bool powerOn)
emit powerOnChanged();
if(linuxmceId()==0)
return;
return;
emit dceMessage(EVENT_Device_OnOff_CONST);
emit dceMessage(EVENT_Device_OnOff_CONST);
}
int AbstractWirelessBulb::bulbType() const
{
......@@ -188,24 +188,15 @@ void AbstractWirelessBulb::proccessStateInformation(QVariantMap d)
setEffect(stateInfo["effect"].toString());
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
switch (m_deviceTemplate) {
case DEVICETEMPLATE_Hue_Lightbulb_CONST :
setCurrentColor(stateInfo);
setCurrentColorTemp(stateInfo["ct"].toInt());
break;
case DEVICETEMPLATE_Hue_Light_Strips_CONST :
if( this->getImplementsColor() ){
setCurrentColor(stateInfo);
setCurrentColorTemp(stateInfo["ct"].toInt());
break;
case DEVICETEMPLATE_Hue_Lux_Bulb_CONST :
setBrightness(stateInfo["bri"].toDouble());
break;
case DEVICETEMPLATE_Connected_A19_60w_Equivalent_CONST :
}
if(this->getImplementsColorTemp()){
setBrightness(stateInfo["bri"].toDouble());
break;
default:
break;
setCurrentColorTemp(stateInfo["ct"].toInt());
}
}
int AbstractWirelessBulb::getCurrentColorTemp() const
......@@ -216,8 +207,31 @@ int AbstractWirelessBulb::getCurrentColorTemp() const
void AbstractWirelessBulb::setCurrentColorTemp(int value)
{
if(currentColorTemp == value) return;
currentColorTemp = value;
if(getDeviceTemplate() == DEVICETEMPLATE_Hue_White_Ambiance_CONST ){
QVariantMap colorTempBlock;
colorTempBlock["defaultColorTemp"]= defaultColor;
colorTempBlock["alarmColorTemp"] = alertColor;
colorTempBlock["currentColorTemp"] = currentColorTemp;
QJsonObject out;
out.insert("color", QJsonValue::fromVariant(colorTempBlock));
QJsonDocument doc;
doc.setObject(out);
DCE::CMD_Set_Device_Data cmd(
this->linuxmceId(),
4,
this->linuxmceId(),
QString::fromUtf8(doc.toJson()).toStdString().c_str(),
DEVICEDATA_Mapping_CONST );
emit dataEvent(cmd);
}
}
bool AbstractWirelessBulb::getImplementsColorTemp() const
......@@ -278,8 +292,6 @@ void AbstractWirelessBulb::setCurrentColor(const QVariantMap &value)
QJsonDocument doc;
doc.setObject(out);
DCE::CMD_Set_Device_Data cmd(
this->linuxmceId(),
4,
......@@ -299,15 +311,23 @@ void AbstractWirelessBulb::setDeviceTemplate(long deviceTemplate)
{
m_deviceTemplate = deviceTemplate;
switch (m_deviceTemplate) {
case DEVICETEMPLATE_Hue_Lightbulb_CONST :
case DEVICETEMPLATE_Hue_Light_Strips_CONST :
case DEVICETEMPLATE_Hue_Extended_Color_Bulb_CONST :
setImplementsColor(true);
setImplementsColorTemp(true);
case DEVICETEMPLATE_Hue_Color_Light_Bulb_CONST:
setImplementsColor(true);
case DEVICETEMPLATE_Hue_Light_Strips_CONST :
setImplementsColor(true);
if(lightModel()=="LST002"){
setImplementsColorTemp(true);
}
break;
case DEVICETEMPLATE_Hue_Lux_Bulb_CONST :
setImplementsColorTemp(true);
case DEVICETEMPLATE_Hue_White_Ambiance_CONST:
setImplementsColorTemp(true);
break;
default:
setImplementsColor(false);
setImplementsColorTemp(false);
break;
}
}
......@@ -387,7 +407,7 @@ void AbstractWirelessBulb::setUniqueId(const QString &uniqueId)
void AbstractWirelessBulb::setRgb(int r, int g, int b)
{
m_rgbColor = QColor::fromRgb(r,g,b);
emit rgbColorChanged();
emit rgbColorChanged();
}
......
......@@ -185,7 +185,6 @@ private:
QVariantMap alertColor;
QVariantMap defaultColor;
HueControllerHardware *mp_controller;
QMap<QString, int> deviceMap;
......
......@@ -207,7 +207,53 @@ void ZWave::ReceivedCommandForChild(DeviceData_Impl *pDeviceData_Impl,string &sC
break;
;;
}
case COMMAND_Set_Temperature_CONST:
case COMMAND_Set_Color_RGB_CONST:
{
LoggerWrapper::GetInstance()->Write(LV_ZWAVE,"Assuming node has a Color value");
OpenZWave::ValueID* valueID = m_pZWInterface->GetValueIdByNodeInstanceLabel(node_id, instance_id, "Color");
if (valueID != NULL)
{
int red = atoi(pMessage->m_mapParameters[COMMANDPARAMETER_Red_Level_CONST].c_str());
int green = atoi(pMessage->m_mapParameters[COMMANDPARAMETER_Green_Level_CONST].c_str());
int blue = atoi(pMessage->m_mapParameters[COMMANDPARAMETER_Blue_Level_CONST].c_str());
if (red > 255)
red = 255;
if (red < 0)
red = 0;
if (green > 255)
green = 255;
if (green < 0)
green = 0;
if (blue > 255)
blue = 255;
if (blue < 0)
blue = 0;
int white = 255;
// Need to set white values to 0 to turn on RGB
if (red > 0 || green > 0 || blue > 0)
white = 0;
char buffer [11];
buffer[10] = 0;
sprintf(&buffer[0], "%02X", (unsigned char)red);
sprintf(&buffer[2], "%02X", (unsigned char)green);
sprintf(&buffer[4], "%02X", (unsigned char)blue);
sprintf(&buffer[6], "%02X", (unsigned char)white);
sprintf(&buffer[8], "%02X", (unsigned char)white);
string color = "#";
color += buffer;
LoggerWrapper::GetInstance()->Write(LV_ZWAVE,"Color: %s", color.c_str());
if (OpenZWave::Manager::Get()->SetValue(*valueID, color)) {
LoggerWrapper::GetInstance()->Write(LV_ZWAVE,"Set Color successful");
} else {
LoggerWrapper::GetInstance()->Write(LV_ZWAVE,"Set Color FAILED!");
}
} else {
LoggerWrapper::GetInstance()->Write(LV_ZWAVE,"No 'Color' label available on node");
}
break;
;;
}
case COMMAND_Set_Temperature_CONST:
{
temp = atoi(pMessage->m_mapParameters[COMMANDPARAMETER_Value_To_Assign_CONST].c_str());
string unit = pDeviceData_Impl->m_mapParameters_Find(DEVICEDATA_Units_CONST);
......
......@@ -2,6 +2,9 @@
#define __Define_Criteria_H__
#define CRITERIA_Leave_Home_CONST 1
#define CRITERIA_Watching_Media_CONST 2
#define CRITERIA_Stop_Watching_CONST 3
#define CRITERIA_TABLE "Criteria"
#define CRITERIA_PK_CRITERIA_FIELD "PK_Criteria"
......
......@@ -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'];
......@@ -145,7 +144,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 +156,38 @@ class AlexaController extends AppController
$this->set(compact('reply'));
$this->set('_serialize', 'reply');
}
public function colorCommand(){
$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' => "OK",
'timeSent'=>$now,
'error'=>"none",
'colordata'=>$rep
);
$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 +220,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 +229,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 +240,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 +250,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 +266,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,50 @@ class DceCommandExecutorComponent extends Component
$response = $this->executeFormedCommand($device, $params);
return $response;
}
function sendColorCommand($data){
$params=array(
'msgid' => 1115,
'params' => array(
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);
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){
$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"]*.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*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