Commit 2fcfdc07 authored by golgoj4's avatar golgoj4

refs #1767 - Update hue controller.

parent 04ba0946
......@@ -351,9 +351,9 @@ void HueController::ReceivedCommandForChild(DeviceData_Impl *pDeviceData_Impl,st
int ID=0;
for (int f = 0; f < hueBulbs.size(); ++f){
if(hueBulbs.at(f)->getLinuxMceId()==device){
qDebug() << Q_FUNC_INFO << hueBulbs.at(f)->lightName;
ID = hueBulbs.at(f)->getInternalId();
if(hueBulbs.at(f)->linuxmceId()==device){
qDebug() << Q_FUNC_INFO << hueBulbs.at(f)->displayName();
ID = hueBulbs.at(f)->id();
}
}
......@@ -505,9 +505,9 @@ void HueController::CreateChildren()
qDebug() << "Light ID " << lightID;
for (int n = 0; n < hueBulbs.size(); n++){
if(hueBulbs.at(n)->controller==p.at(0)&& hueBulbs.at(n)->getInternalId()==lightID ){
hueBulbs.at(n)->linuxmceId = linuxmceID;
qDebug() << "Linked existing light with linuxmce db. " << hueBulbs.at(n)->lightName;
if(hueBulbs.at(n)->getController()->getIpAddress() == p.at(0)&& hueBulbs.at(n)->id()==lightID ){
hueBulbs.at(n)->setLinuxmceId(linuxmceID);
qDebug() << "Linked existing light with linuxmce db. " << hueBulbs.at(n)->displayName();
}
}
}
......@@ -682,11 +682,11 @@ void HueController::CMD_Report_Child_Devices(string &sCMD_Result,Message *pMessa
QList<int>added;
for(int n=0; n < hueBulbs.size(); n++ ){
qDebug()<< "Current Light: \t" << hueBulbs.at(n)->lightName;
qDebug()<< "Current Light LMCE id \t" << hueBulbs.at(n)->getLinuxMceId();
if(hueBulbs.at(n)->getLinuxMceId()==0){
qDebug() << hueBulbs.at(n)->lightName << " has no linuxmce id. it should be added.";
LoggerWrapper::GetInstance()->Write(LV_STATUS, "%s has no LinuxMCE Device number, it should be added.", hueBulbs.at(n)->lightName.toStdString().c_str());
qDebug()<< "Current Light: \t" << hueBulbs.at(n)->displayName();
qDebug()<< "Current Light LMCE id \t" << hueBulbs.at(n)->linuxmceId();
if(hueBulbs.at(n)->linuxmceId()==0){
qDebug() << hueBulbs.at(n)->displayName() << " has no linuxmce id. it should be added.";
LoggerWrapper::GetInstance()->Write(LV_STATUS, "%s has no LinuxMCE Device number, it should be added.", hueBulbs.at(n)->displayName().toStdString().c_str());
for( int i=0; i < (int)m_pData->m_vectDeviceData_Impl_Children.size(); i++ )
{
......@@ -694,56 +694,55 @@ void HueController::CMD_Report_Child_Devices(string &sCMD_Result,Message *pMessa
if (existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST)=="" && added.indexOf(existingBulb->m_dwPK_Device)==-1 ){
qDebug () << "Setting ID for existing light with unknown configuration with " << hueBulbs.at(n)->lightName;
CMD_Set_Device_Data setUnit(this->m_dwPK_Device, 4, existingBulb->m_dwPK_Device,StringUtils::itos(hueBulbs.at(n)->getInternalId()),DEVICEDATA_UnitNo_CONST);
qDebug () << "Setting ID for existing light with unknown configuration with " << hueBulbs.at(n)->displayName();
CMD_Set_Device_Data setUnit(this->m_dwPK_Device, 4, existingBulb->m_dwPK_Device,StringUtils::itos(hueBulbs.at(n)->id()),DEVICEDATA_UnitNo_CONST);
string pResonseA = "";
if(SendCommand(setUnit, &pResonseA)){
qDebug() << "Set internal id";
}
QString chanaddress = hueBulbs.at(n)->getController()+":"+QString::number(hueBulbs.at(n)->getInternalId());
QString chanaddress = hueBulbs.at(n)->getController()->getIpAddress()+":"+QString::number(hueBulbs.at(n)->id());
qDebug()<< chanaddress;
CMD_Set_Device_Data setController(this->m_dwPK_Device, 4, existingBulb->m_dwPK_Device,chanaddress.toStdString(),DEVICEDATA_PortChannel_Number_CONST);
if(SendCommand(setController)){
qDebug() << "Set port / channel";
}
CMD_Set_Device_Data setName(m_dwPK_Device, 4, existingBulb->m_dwPK_Device, hueBulbs.at(n)->lightName.toStdString(), DEVICEDATA_Name_CONST);
CMD_Set_Device_Data setName(m_dwPK_Device, 4, existingBulb->m_dwPK_Device, hueBulbs.at(n)->displayName().toStdString(), DEVICEDATA_Name_CONST);
if(SendCommand(setName)){
qDebug()<<"Set Device Name";
}
added.append(existingBulb->m_dwPK_Device);
}
else{
qDebug() << hueBulbs.at(n)->getLinuxMceId();
qDebug() << hueBulbs.at(n)->linuxmceId();
}
// qDebug() << "There are no more bulbs in the linuxmce system, but the controller has more." <<hueBulbs.at(n)->lightName << "is being added them now. ";
}
if(hueBulbs.at(n)->getLinuxMceId()==0){
qDebug() << "Not found in system, need to add "<< hueBulbs.at(n)->lightName;
if(hueBulbs.at(n)->linuxmceId()==0){
qDebug() << "Not found in system, need to add "<< hueBulbs.at(n)->displayName();
qDebug() << "Creating...";
int newDevice;
string cResponse="";
DCE::CMD_Create_Device createLight(this->m_dwPK_Device, 4, DEVICETEMPLATE_Hue_Lightbulb_CONST, "", 0, "", "", 0, this->m_dwPK_Device, hueBulbs.at(n)->lightName.toStdString(), 0, 0, &newDevice);
DCE::CMD_Create_Device createLight(this->m_dwPK_Device, 4, DEVICETEMPLATE_Hue_Lightbulb_CONST, "", 0, "", "", 0, this->m_dwPK_Device, hueBulbs.at(n)->displayName().toStdString(), 0, 0, &newDevice);
if(SendCommand(createLight, &cResponse)){
qDebug() << cResponse.c_str();
qDebug() << "New Device id " << newDevice;
CMD_Set_Device_Data setUnit(this->m_dwPK_Device, 4,newDevice,StringUtils::itos(hueBulbs.at(n)->getInternalId()),DEVICEDATA_UnitNo_CONST);
CMD_Set_Device_Data setUnit(this->m_dwPK_Device, 4,newDevice,StringUtils::itos(hueBulbs.at(n)->id()),DEVICEDATA_UnitNo_CONST);
string pResonseA = "";
if(SendCommand(setUnit, &pResonseA)){
qDebug() << "Set internal id";
}
QString chanaddress = hueBulbs.at(n)->getController()+":"+QString::number(hueBulbs.at(n)->getInternalId());
QString chanaddress = hueBulbs.at(n)->getController()->getIpAddress()+":"+QString::number(hueBulbs.at(n)->id());
qDebug()<< chanaddress;
CMD_Set_Device_Data setController(this->m_dwPK_Device, 4, newDevice,chanaddress.toStdString(),DEVICEDATA_PortChannel_Number_CONST);
if(SendCommand(setController)){
qDebug() << "Set port / channel";
}
CMD_Set_Device_Data setName(m_dwPK_Device, 4, newDevice, hueBulbs.at(n)->lightName.toStdString(), DEVICEDATA_Name_CONST);
CMD_Set_Device_Data setName(m_dwPK_Device, 4, newDevice, hueBulbs.at(n)->displayName().toStdString(), DEVICEDATA_Name_CONST);
if(SendCommand(setName)){
qDebug()<<"Set Device Name";
}
......@@ -934,27 +933,33 @@ bool HueController::downloadControllerConfig(QUrl deviceIp)
QMap<QString, QVariant>::const_iterator i;
for(i=lightNest.begin(); i!= lightNest.constEnd(); i++ )
{
HueBulb *b = new HueBulb();
HueBulb *b = new HueBulb(hueControllers.at(index));
// << " :: " << i.value();
QVariantMap light = i.value().toMap();
QVariantMap state = light["state"].toMap();
QString fd = state["on"].toString();
b->powerState = fd;
b->lightId = i.key().toInt();
b->lightName = light["name"].toString();
b->modelId = light["model"].toString();
b->linuxmceId=0;
b->controller=hueControllers.at(index)->m_ipAddress;
qDebug() << i.key() << "::" << light["name"].toString() ;
b->setPowerOn(state["on"].toBool());
b->setId(i.key().toInt());
if(light["manufacturername"].isValid()){ b->setManufacturerName(light["manufacturername"].toString()); } //hue software 1.4
if(light["uniqueid"].isValid()) { b->setUniqueId(light["uniqueid"].toString()); } //hue software 1.7
b->setDisplayName(light["name"].toString());
b->setLightModel(light["modelid"].toString());
b->setLinuxmceId(0);
// qDebug() << i.key() << "::" << light["name"].toString() ;
for( int l=0; l < (int)m_pData->m_vectDeviceData_Impl_Children.size(); l++ ){
DeviceData_Impl *existingBulb = m_pData->m_vectDeviceData_Impl_Children.at(l);
qDebug() << "Existing light UnitNo :: " << existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST).c_str();
if(existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST).c_str() == QString::number(b->lightId)){
qDebug() << "Matched existing light";
b->linuxmceId = existingBulb->m_dwPK_Device;
//qDebug() << "Existing light UnitNo :: " << existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST).c_str();
if(existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST).c_str() == QString::number(b->id())){
qDebug() << "Matched existing light" << b->displayName();
b->setLinuxmceId(existingBulb->m_dwPK_Device);
} else {
qDebug() << "no match existing light" << existingBulb->mapParameters_Find(DEVICEDATA_UnitNo_CONST).c_str() << "::" << b->id();
}
}
......
......@@ -49,7 +49,8 @@ SOURCES += ../Main.cpp \
../HueController.cpp \
huecontrollerhardware.cpp \
huebulb.cpp \
../huecommand.cpp
../huecommand.cpp \
abstractwirelessbulb.cpp
HEADERS += ../../PlutoUtils/ThreadedClass.h \
../../PlutoUtils/MultiThreadIncludes.h \
......@@ -75,4 +76,5 @@ HEADERS += ../../PlutoUtils/ThreadedClass.h \
../HueController.h \
huecontrollerhardware.h \
huebulb.h \
../huecommand.h
../huecommand.h \
abstractwirelessbulb.h
#include "abstractwirelessbulb.h"
#include "qdebug.h"
AbstractWirelessBulb::AbstractWirelessBulb(HueControllerHardware *p_controller, QObject *parent) : QObject(parent), mp_controller(p_controller)
{
qDebug() << Q_FUNC_INFO << "ctor";
if(mp_controller){
qDebug() << Q_FUNC_INFO << mp_controller->getIpAddress();
} else {
qDebug() << Q_FUNC_INFO << "invalid controller!";
}
}
QString AbstractWirelessBulb::displayName() const
{
return ms_displayName;
}
void AbstractWirelessBulb::setDisplayName(const QString &value)
{
if(ms_displayName==value) return;
ms_displayName= value;
emit displayNameChanged();
}
QString AbstractWirelessBulb::serialNumber() const
{
return ms_serialNumber;
}
void AbstractWirelessBulb::setSerialNumber(const QString &s)
{
if(ms_serialNumber== s)return;
ms_serialNumber=s;
emit serialNumberChanged();
}
QColor AbstractWirelessBulb::color() const
{
return m_color;
}
void AbstractWirelessBulb::setColor(const QColor &color)
{
if(m_color==color) return;
m_color = color;
emit colorChanged();
}
int AbstractWirelessBulb::id()
{
return m_id;
}
void AbstractWirelessBulb::setId( int id)
{
if(m_id==id) return;
m_id = id;
emit idChanged();
}
double AbstractWirelessBulb::CurrentLevel() const
{
return m_CurrentLevel;
}
void AbstractWirelessBulb::setCurrentLevel(double CurrentLevel)
{
if(m_CurrentLevel == CurrentLevel) return;
m_CurrentLevel = CurrentLevel;
emit currentLevelChanged();
}
bool AbstractWirelessBulb::powerOn() const
{
return m_powerOn;
}
void AbstractWirelessBulb::setPowerOn(bool powerOn)
{
if(m_powerOn == powerOn) return;
m_powerOn = powerOn;
emit powerOnChanged();
}
int AbstractWirelessBulb::bulbType() const
{
return m_bulbType;
}
void AbstractWirelessBulb::setBulbType(int bulbType)
{
if(m_bulbType==bulbType) return;
m_bulbType = bulbType;
emit bulbTypeChanged();
}
QString AbstractWirelessBulb::effect() const
{
return m_effect;
}
void AbstractWirelessBulb::setEffect(const QString &effect)
{
if(m_effect==effect);return;
m_effect = effect;
emit effectChanged();
}
QString AbstractWirelessBulb::alert() const
{
return m_alert;
}
void AbstractWirelessBulb::setAlert(const QString &alert)
{
if(m_alert==alert) return;
m_alert = alert;
emit alertChanged();
}
bool AbstractWirelessBulb::online() const
{
return m_online;
}
void AbstractWirelessBulb::setOnline(bool online)
{
if(m_online==online)return;
m_online = online;
emit onlineChanged();
}
HueControllerHardware *AbstractWirelessBulb::getController()
{
return mp_controller;
}
void AbstractWirelessBulb::setController(HueControllerHardware *c)
{
mp_controller=c;
}
QString AbstractWirelessBulb::getUniqueId() const
{
return m_uniqueId;
}
void AbstractWirelessBulb::setUniqueId(const QString &uniqueId)
{
m_uniqueId = uniqueId;
emit uniqueIdChanged();
}
QString AbstractWirelessBulb::getManufacturerName() const
{
return m_manufacturerName;
}
void AbstractWirelessBulb::setManufacturerName(const QString &manufacturerName)
{
m_manufacturerName = manufacturerName;
emit manufacturerChanged();
}
QString AbstractWirelessBulb::getSoftwareVersion() const
{
return m_softwareVersion;
}
void AbstractWirelessBulb::setSoftwareVersion(const QString &softwareVersion)
{
m_softwareVersion = softwareVersion;
emit softwareVersionChanged();
}
QString AbstractWirelessBulb::getLightModel() const
{
return m_lightModel;
}
void AbstractWirelessBulb::setLightModel(const QString &lightModel)
{
m_lightModel = lightModel;
emit lightModelChanged();
}
int AbstractWirelessBulb::linuxmceId() const
{
return m_linuxmceId;
}
void AbstractWirelessBulb::setLinuxmceId(int value)
{
m_linuxmceId = value;
emit linuxmceIdChanged();
}
#ifndef ABSTRACTWIRELESSBULB_H
#define ABSTRACTWIRELESSBULB_H
#include <QObject>
#include <qcolor.h>
#include <qmap.h>
#include "huecontrollerhardware.h"
class AbstractWirelessBulb : public QObject
{
Q_OBJECT
public:
explicit AbstractWirelessBulb(HueControllerHardware* p_controller, QObject *parent = 0);
AbstractWirelessBulb() {}
enum BulbType{
PHILLIPS_HUE,
PHILLIPS_HUE_LUX,
PHILLIPS_HUE_LIGHTSTRIPS,
PHILLIPS_HUE_BLOOM,
CREE_WIRELESS_LED
};
enum alert {
NOALERT,BLINK,FLASH
};
enum effect {
NOEFFECT,COLORLOOP
};
enum colormode{
HUESAT,COLORTEMP,XY
};
QString displayName() const;
void setDisplayName(const QString &value);
QString serialNumber() const;
void setSerialNumber(const QString &s);
QColor color() const;
void setColor(const QColor &color);
int id();
void setId( int id);
double CurrentLevel() const;
void setCurrentLevel(double CurrentLevel);
bool powerOn() const;
void setPowerOn(bool powerOn);
int bulbType() const;
void setBulbType(int bulbType);
QString effect() const;
void setEffect(const QString &effect);
QString alert() const;
void setAlert(const QString &alert);
bool online() const;
void setOnline(bool online);
int linuxmceId() const;
void setLinuxmceId(int value);
QString getLightModel() const;
void setLightModel(const QString &lightModel);
QString getSoftwareVersion() const;
void setSoftwareVersion(const QString &softwareVersion);
QString getManufacturerName() const;
void setManufacturerName(const QString &manufacturerName);
QString getUniqueId() const;
void setUniqueId(const QString &uniqueId);
signals:
void serialNumberChanged();
void displayNameChanged();
void colorChanged();
void idChanged();
void powerOnChanged();
void alertChanged();
void effectChanged();
void bulbTypeChanged();
void onlineChanged();
void currentLevelChanged();
void linuxmceIdChanged();
void lightModelChanged();
void softwareVersionChanged();
void manufacturerChanged();
void uniqueIdChanged();
public slots:
HueControllerHardware * getController();
void setController(HueControllerHardware * c);
private:
QString m_lightModel;
QString ms_serialNumber;
QString ms_displayName;
QString m_softwareVersion;
QString m_manufacturerName;
QString m_uniqueId;
quint8 m_brightness;
quint16 m_hue;
quint8 m_saturation;
QMap<QString, float>xy;
QColor m_color;
int m_id;
int m_linuxmceId;
double m_CurrentLevel;
bool m_powerOn;
int m_bulbType;
QString m_effect;
QString m_alert;
bool m_online;
HueControllerHardware *mp_controller;
QMap<QString, int> deviceMap;
};
#endif // ABSTRACTWIRELESSBULB_H
#include "huebulb.h"
HueBulb::HueBulb(QObject *parent) :
QObject(parent)
HueBulb::HueBulb(HueControllerHardware *hw)
{
powerState="";
int lightId =0 ;
int linuxmceId =0;
QString powerState = "";
quint8 bri = 0;
quint16 hue =0;
quint8 sat = 0;
QMap<QString*, float> xy;
quint16 colorTemp = 0;
QString alertStatus = "";
QString effectStatus ="";
QString currentColorMode = "";
bool reachable = true;
QString lightType = "";
QString lightName = "";
QString modelId = "";
QString swVersion = "";
QString controller= "";
setController(hw);
}
......@@ -22,51 +22,20 @@
#include <QObject>
#include <QMap>
#include <abstractwirelessbulb.h>
class HueBulb : public QObject
class HueBulb : public AbstractWirelessBulb
{
Q_OBJECT
public:
explicit HueBulb(QObject *parent = 0);
enum alert {
NOALERT,BLINK,FLASH
};
enum effect {
NOEFFECT,COLORLOOP
};
enum colormode{
HUESAT,COLORTEMP,XY
};
int lightId;
int linuxmceId;
QString powerState;
quint8 bri;
quint16 hue;
quint8 sat;
QMap<QString*, float> xy;
quint16 colorTemp;
QString alertStatus;
QString effectStatus;
QString currentColorMode;
bool reachable;
QString lightType;
QString lightName;
QString modelId;
QString swVersion;
QString controller;
explicit HueBulb(HueControllerHardware *hw);
HueBulb(){}
signals:
public slots:
int getInternalId() {return lightId;}
int getLinuxMceId() {return linuxmceId;}
QString getController() {return controller;}
......
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