fix wemo plugin
make edit possible and remove rediscovery action
This commit is contained in:
parent
6d13366fc7
commit
5de104ec3d
@ -179,27 +179,6 @@ void Light::setColor(const QColor &color)
|
|||||||
quint16 hue = color.hue() * 65535 / 360;
|
quint16 hue = color.hue() * 65535 / 360;
|
||||||
quint8 sat = color.saturation();
|
quint8 sat = color.saturation();
|
||||||
|
|
||||||
// // Transform from RGB to XYZ
|
|
||||||
// QGenericMatrix<3, 3, qreal> rgb2xyzMatrix;
|
|
||||||
// rgb2xyzMatrix(0, 0) = 0.412453; rgb2xyzMatrix(0, 1) = 0.357580; rgb2xyzMatrix(0, 2) = 0.180423;
|
|
||||||
// rgb2xyzMatrix(1, 0) = 0.212671; rgb2xyzMatrix(1, 1) = 0.715160; rgb2xyzMatrix(1, 2) = 0.072169;
|
|
||||||
// rgb2xyzMatrix(2, 0) = 0.019334; rgb2xyzMatrix(2, 1) = 0.119193; rgb2xyzMatrix(2, 2) = 0.950227;
|
|
||||||
|
|
||||||
// QGenericMatrix<1, 3, qreal> rgbMatrix;
|
|
||||||
// rgbMatrix(0, 0) = 1.0 * color.red() / 255;
|
|
||||||
// rgbMatrix(1, 0) = 1.0 * color.green() / 255;
|
|
||||||
// rgbMatrix(2, 0) = 1.0 * color.blue() / 255;
|
|
||||||
|
|
||||||
// QGenericMatrix<1, 3, qreal> xyzMatrix = rgb2xyzMatrix * rgbMatrix;
|
|
||||||
|
|
||||||
// // transform from XYZ to CIELUV u' and v'
|
|
||||||
// qreal u = 4*xyzMatrix(0, 0) / (xyzMatrix(0, 0) + 15*xyzMatrix(1, 0) + 3*xyzMatrix(2, 0));
|
|
||||||
// qreal v = 9*xyzMatrix(1, 0) / (xyzMatrix(0, 0) + 15*xyzMatrix(1, 0) + 3*xyzMatrix(2, 0));
|
|
||||||
|
|
||||||
// Transform from CIELUV to (x,y)
|
|
||||||
// qreal x = 27*u / (18*u - 48*v + 36);
|
|
||||||
// qreal y = 12*v / (18*u - 48*v + 36);
|
|
||||||
|
|
||||||
qDebug() << "setting color" << color;
|
qDebug() << "setting color" << color;
|
||||||
if (m_busyStateChangeId == -1) {
|
if (m_busyStateChangeId == -1) {
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
@ -210,11 +189,6 @@ void Light::setColor(const QColor &color)
|
|||||||
// Lets just assume it always succeeds
|
// Lets just assume it always succeeds
|
||||||
m_sat = sat;
|
m_sat = sat;
|
||||||
|
|
||||||
// QVariantList xyList;
|
|
||||||
// xyList << x << y;
|
|
||||||
// params.insert("xy", xyList);
|
|
||||||
|
|
||||||
|
|
||||||
params.insert("on", true);
|
params.insert("on", true);
|
||||||
m_busyStateChangeId = m_bridge->put(m_ip, m_username, "lights/" + QString::number(m_id) + "/state", params, this, "setStateFinished");
|
m_busyStateChangeId = m_bridge->put(m_ip, m_username, "lights/" + QString::number(m_id) + "/state", params, this, "setStateFinished");
|
||||||
} else {
|
} else {
|
||||||
@ -222,8 +196,6 @@ void Light::setColor(const QColor &color)
|
|||||||
m_hueDirty = true;
|
m_hueDirty = true;
|
||||||
m_dirtySat = sat;
|
m_dirtySat = sat;
|
||||||
m_satDirty = true;
|
m_satDirty = true;
|
||||||
// m_xyDirty = true;
|
|
||||||
// m_dirtyXy = QPointF(x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +313,7 @@ void Light::responseReceived(int id, const QVariant &response)
|
|||||||
m_reachable = stateMap.value("reachable").toBool();
|
m_reachable = stateMap.value("reachable").toBool();
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
|
|
||||||
// qDebug() << "got light response" << m_modelId << m_type << m_swversion << m_on << m_bri << m_reachable;
|
qDebug() << "got light response" << m_modelId << m_type << m_swversion << m_on << m_bri << m_reachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Light::setDescriptionFinished(int id, const QVariant &response)
|
void Light::setDescriptionFinished(int id, const QVariant &response)
|
||||||
|
|||||||
@ -84,20 +84,14 @@ DeviceManager::DeviceError DevicePluginWemo::discoverDevices(const DeviceClassId
|
|||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginWemo::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginWemo::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == wemoSwitchDeviceClassId) {
|
if (device->deviceClassId() != wemoSwitchDeviceClassId) {
|
||||||
foreach (Device *d, myDevices()) {
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
if (d->paramValue("serial number").toString() == device->paramValue("serial number").toString()) {
|
|
||||||
qWarning() << "WeMo Switch " << device->paramValue("serial number").toString() << " allready added...";
|
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
device->setName("WeMo Switch (" + device->paramValue("serial number").toString() + ")");
|
|
||||||
|
|
||||||
refresh(device);
|
|
||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
|
||||||
}
|
}
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
|
||||||
|
device->setName("WeMo Switch (" + device->paramValue("serial number").toString() + ")");
|
||||||
|
|
||||||
|
refresh(device);
|
||||||
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginWemo::requiredHardware() const
|
DeviceManager::HardwareResources DevicePluginWemo::requiredHardware() const
|
||||||
@ -126,11 +120,6 @@ DeviceManager::DeviceError DevicePluginWemo::executeAction(Device *device, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rediscover
|
|
||||||
if (action.actionTypeId() == rediscoverActionTypeId) {
|
|
||||||
upnpDiscover("upnp:rootdevice");
|
|
||||||
return DeviceManager::DeviceErrorNoError;
|
|
||||||
}
|
|
||||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,16 +186,14 @@ void DevicePluginWemo::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &
|
|||||||
QList<DeviceDescriptor> deviceDescriptors;
|
QList<DeviceDescriptor> deviceDescriptors;
|
||||||
foreach (UpnpDeviceDescriptor upnpDeviceDescriptor, upnpDeviceDescriptorList) {
|
foreach (UpnpDeviceDescriptor upnpDeviceDescriptor, upnpDeviceDescriptorList) {
|
||||||
if (upnpDeviceDescriptor.friendlyName() == "WeMo Switch") {
|
if (upnpDeviceDescriptor.friendlyName() == "WeMo Switch") {
|
||||||
if (!verifyExistingDevices(upnpDeviceDescriptor)) {
|
DeviceDescriptor descriptor(wemoSwitchDeviceClassId, "WemoSwitch", upnpDeviceDescriptor.serialNumber());
|
||||||
DeviceDescriptor descriptor(wemoSwitchDeviceClassId, "WemoSwitch", upnpDeviceDescriptor.serialNumber());
|
ParamList params;
|
||||||
ParamList params;
|
params.append(Param("name", upnpDeviceDescriptor.friendlyName()));
|
||||||
params.append(Param("name", upnpDeviceDescriptor.friendlyName()));
|
params.append(Param("host address", upnpDeviceDescriptor.hostAddress().toString()));
|
||||||
params.append(Param("host address", upnpDeviceDescriptor.hostAddress().toString()));
|
params.append(Param("port", upnpDeviceDescriptor.port()));
|
||||||
params.append(Param("port", upnpDeviceDescriptor.port()));
|
params.append(Param("serial number", upnpDeviceDescriptor.serialNumber()));
|
||||||
params.append(Param("serial number", upnpDeviceDescriptor.serialNumber()));
|
descriptor.setParams(params);
|
||||||
descriptor.setParams(params);
|
deviceDescriptors.append(descriptor);
|
||||||
deviceDescriptors.append(descriptor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit devicesDiscovered(wemoSwitchDeviceClassId, deviceDescriptors);
|
emit devicesDiscovered(wemoSwitchDeviceClassId, deviceDescriptors);
|
||||||
@ -217,30 +204,6 @@ void DevicePluginWemo::upnpNotifyReceived(const QByteArray ¬ifyData)
|
|||||||
Q_UNUSED(notifyData);
|
Q_UNUSED(notifyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginWemo::verifyExistingDevices(UpnpDeviceDescriptor deviceDescriptor)
|
|
||||||
{
|
|
||||||
foreach (Device* device, myDevices()) {
|
|
||||||
// check if we allready have added this Wemo device and verify the params
|
|
||||||
if (device->paramValue("serial number").toString() == deviceDescriptor.serialNumber()) {
|
|
||||||
qDebug() << "verify wemo paramters... of" << deviceDescriptor.serialNumber();
|
|
||||||
// now check if ip or port changed
|
|
||||||
bool somethingChanged = false;
|
|
||||||
if (device->paramValue("host address").toString() != deviceDescriptor.hostAddress().toString()) {
|
|
||||||
device->setParamValue("host address", deviceDescriptor.hostAddress().toString());
|
|
||||||
somethingChanged = true;
|
|
||||||
}
|
|
||||||
if(device->paramValue("port").toInt() != deviceDescriptor.port()){
|
|
||||||
device->setParamValue("port", deviceDescriptor.port());
|
|
||||||
somethingChanged = true;
|
|
||||||
}
|
|
||||||
if (somethingChanged) {
|
|
||||||
refresh(device);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DevicePluginWemo::refresh(Device *device)
|
void DevicePluginWemo::refresh(Device *device)
|
||||||
{
|
{
|
||||||
@ -277,6 +240,7 @@ bool DevicePluginWemo::setPower(Device *device, const bool &power, const ActionI
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DevicePluginWemo::processRefreshData(const QByteArray &data, Device *device)
|
void DevicePluginWemo::processRefreshData(const QByteArray &data, Device *device)
|
||||||
{
|
{
|
||||||
if (data.contains("<BinaryState>0</BinaryState>")) {
|
if (data.contains("<BinaryState>0</BinaryState>")) {
|
||||||
|
|||||||
@ -49,7 +49,6 @@ private:
|
|||||||
QHash<QNetworkReply *, Device *> m_refreshReplies;
|
QHash<QNetworkReply *, Device *> m_refreshReplies;
|
||||||
QHash<QNetworkReply *, Device *> m_setPowerReplies;
|
QHash<QNetworkReply *, Device *> m_setPowerReplies;
|
||||||
QHash<QNetworkReply *, ActionId> m_runningActionExecutions;
|
QHash<QNetworkReply *, ActionId> m_runningActionExecutions;
|
||||||
bool verifyExistingDevices(UpnpDeviceDescriptor deviceDescriptor);
|
|
||||||
|
|
||||||
void refresh(Device* device);
|
void refresh(Device* device);
|
||||||
bool setPower(Device *device, const bool &power, const ActionId &actionId);
|
bool setPower(Device *device, const bool &power, const ActionId &actionId);
|
||||||
|
|||||||
@ -49,13 +49,6 @@
|
|||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"actionTypes": [
|
|
||||||
{
|
|
||||||
"id": "269cf3b8-d4dd-42e9-8309-6cb3ca8842df",
|
|
||||||
"idName": "rediscover",
|
|
||||||
"name": "rediscover"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user