fix tune plugin and some hue modifications
This commit is contained in:
parent
4e09d25296
commit
f2baa2659b
@ -187,6 +187,7 @@ void Device::setStateValue(const StateTypeId &stateTypeId, const QVariant &value
|
|||||||
for (int i = 0; i < m_states.count(); ++i) {
|
for (int i = 0; i < m_states.count(); ++i) {
|
||||||
if (m_states.at(i).stateTypeId() == stateTypeId) {
|
if (m_states.at(i).stateTypeId() == stateTypeId) {
|
||||||
if (m_states.at(i).value() == value) {
|
if (m_states.at(i).value() == value) {
|
||||||
|
//qDebug() << name() << m_states.at(i).value() << "-----> value unchanged";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
State newState(stateTypeId, m_id);
|
State newState(stateTypeId, m_id);
|
||||||
|
|||||||
@ -106,8 +106,6 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceC
|
|||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
qDebug() << "setupDevice" << device->params();
|
|
||||||
|
|
||||||
Light *light = nullptr;
|
Light *light = nullptr;
|
||||||
|
|
||||||
// Lets see if this a a newly added device... In which case its hue id number is not set, well, -1...
|
// Lets see if this a a newly added device... In which case its hue id number is not set, well, -1...
|
||||||
@ -283,11 +281,6 @@ void DevicePluginPhilipsHue::getLightsFinished(int id, const QVariant ¶ms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit pairingFinished(pairingInfo.pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess);
|
emit pairingFinished(pairingInfo.pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess);
|
||||||
|
|
||||||
// If we have more than one device on that bridge, tell DeviceManager that there are more.
|
|
||||||
if (params.toMap().count() > 1) {
|
|
||||||
// emit autoDevicesAppeared();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginPhilipsHue::getFinished(int id, const QVariant ¶ms)
|
void DevicePluginPhilipsHue::getFinished(int id, const QVariant ¶ms)
|
||||||
|
|||||||
@ -98,6 +98,9 @@ void HueBridgeConnection::slotCreateUserFinished()
|
|||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
|
|
||||||
|
qDebug() << jsonDoc.toJson();
|
||||||
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
QVariantMap errorMap;
|
QVariantMap errorMap;
|
||||||
@ -119,6 +122,7 @@ void HueBridgeConnection::slotGetFinished()
|
|||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
QVariantMap errorMap;
|
QVariantMap errorMap;
|
||||||
@ -128,6 +132,10 @@ void HueBridgeConnection::slotGetFinished()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jsonDoc.toJson().contains("error")){
|
||||||
|
qDebug() << jsonDoc.toJson();
|
||||||
|
}
|
||||||
|
|
||||||
QVariant response = jsonDoc.toVariant();
|
QVariant response = jsonDoc.toVariant();
|
||||||
emit getFinished(c.id, response.toMap());
|
emit getFinished(c.id, response.toMap());
|
||||||
if (c.obj) {
|
if (c.obj) {
|
||||||
|
|||||||
@ -132,8 +132,13 @@ void Light::setBri(quint8 bri)
|
|||||||
qDebug() << "setting brightness to" << bri << m_busyStateChangeId;
|
qDebug() << "setting brightness to" << bri << m_busyStateChangeId;
|
||||||
if (m_busyStateChangeId == -1) {
|
if (m_busyStateChangeId == -1) {
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("bri", bri);
|
if (bri == 0) {
|
||||||
params.insert("on", true);
|
params.insert("bri", bri);
|
||||||
|
params.insert("on", false);
|
||||||
|
} else {
|
||||||
|
params.insert("bri", bri);
|
||||||
|
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 {
|
||||||
m_dirtyBri = bri;
|
m_dirtyBri = bri;
|
||||||
|
|||||||
@ -126,7 +126,7 @@ void DevicePluginTune::tuneAutodetected()
|
|||||||
QList<DeviceDescriptor> descriptorList;
|
QList<DeviceDescriptor> descriptorList;
|
||||||
DeviceDescriptor descriptor(tuneDeviceClassId);
|
DeviceDescriptor descriptor(tuneDeviceClassId);
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params.append(Param("name", "Wohnzimmer"));
|
params.append(Param("name", "Living room"));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
descriptorList.append(descriptor);
|
descriptorList.append(descriptor);
|
||||||
metaObject()->invokeMethod(this, "autoDevicesAppeared", Qt::QueuedConnection, Q_ARG(DeviceClassId, tuneDeviceClassId), Q_ARG(QList<DeviceDescriptor>, descriptorList));
|
metaObject()->invokeMethod(this, "autoDevicesAppeared", Qt::QueuedConnection, Q_ARG(DeviceClassId, tuneDeviceClassId), Q_ARG(QList<DeviceDescriptor>, descriptorList));
|
||||||
@ -151,9 +151,11 @@ void DevicePluginTune::tuneConnectionStatusChanged(const bool &connected)
|
|||||||
void DevicePluginTune::updateMood(const QVariantMap &message)
|
void DevicePluginTune::updateMood(const QVariantMap &message)
|
||||||
{
|
{
|
||||||
QVariantMap mood = message.value("mood").toMap();
|
QVariantMap mood = message.value("mood").toMap();
|
||||||
|
qDebug () << QJsonDocument::fromVariant(message).toJson();
|
||||||
Device *device = deviceManager()->findConfiguredDevice(DeviceId(mood.value("deviceId").toString()));
|
Device *device = deviceManager()->findConfiguredDevice(DeviceId(mood.value("deviceId").toString()));
|
||||||
if (device) {
|
if (device) {
|
||||||
QVariantMap states = mood.value("states").toMap();
|
QVariantMap states = mood.value("states").toMap();
|
||||||
|
//qDebug() << "======>" << device->name() << states.value("active").toBool() << states.value("value").toInt();
|
||||||
device->setStateValue(activeStateTypeId, states.value("active").toBool());
|
device->setStateValue(activeStateTypeId, states.value("active").toBool());
|
||||||
device->setStateValue(valueStateTypeId, states.value("value").toInt());
|
device->setStateValue(valueStateTypeId, states.value("value").toInt());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ JsonRpcServer::JsonRpcServer(QObject *parent) :
|
|||||||
|
|
||||||
connect(m_manager, &TuneManager::tuneConnectionStatusChanged, this, &JsonRpcServer::connectionStatusChanged);
|
connect(m_manager, &TuneManager::tuneConnectionStatusChanged, this, &JsonRpcServer::connectionStatusChanged);
|
||||||
connect(m_manager, &TuneManager::dataReady, this, &JsonRpcServer::processData);
|
connect(m_manager, &TuneManager::dataReady, this, &JsonRpcServer::processData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcServer::start()
|
void JsonRpcServer::start()
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "tunemanager.h"
|
#include "tunemanager.h"
|
||||||
#include "plugin/device.h"
|
#include "plugin/device.h"
|
||||||
|
|||||||
@ -100,14 +100,14 @@ bool TuneManager::start()
|
|||||||
delete m_server;
|
delete m_server;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug() << " --> Tune server started" << localhost << m_port;
|
qDebug() << "--> Tune server started" << localhost << m_port;
|
||||||
connect(m_server, &QTcpServer::newConnection, this, &TuneManager::tuneConnected);
|
connect(m_server, &QTcpServer::newConnection, this, &TuneManager::tuneConnected);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuneManager::stop()
|
void TuneManager::stop()
|
||||||
{
|
{
|
||||||
qDebug() << " --> close Tune server" << m_server->serverAddress().toString();
|
qDebug() << "--> close Tune server" << m_server->serverAddress().toString();
|
||||||
m_server->close();
|
m_server->close();
|
||||||
delete m_server;
|
delete m_server;
|
||||||
m_server = 0;
|
m_server = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user