allow only one mood enabled (tune side)
This commit is contained in:
parent
eff573ce78
commit
6baa7584ad
@ -46,13 +46,13 @@ DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device)
|
|||||||
{
|
{
|
||||||
|
|
||||||
// tune
|
// tune
|
||||||
if (device->deviceClassId() == tuneDeviceClassId && !tuneAdded()) {
|
if (device->deviceClassId() == tuneDeviceClassId && !tuneAlreadyAdded()) {
|
||||||
m_tuneDeviceId = device->id();
|
m_tuneDeviceId = device->id();
|
||||||
return DeviceManager::DeviceSetupStatusSuccess;
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mood
|
// mood
|
||||||
if ((device->deviceClassId() == moodDeviceClassId) && tuneAdded()) {
|
if ((device->deviceClassId() == moodDeviceClassId) && tuneAlreadyAdded()) {
|
||||||
|
|
||||||
// check index position
|
// check index position
|
||||||
int position = device->paramValue("position").toInt();
|
int position = device->paramValue("position").toInt();
|
||||||
@ -143,7 +143,7 @@ bool DevicePluginTune::sync()
|
|||||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
||||||
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
||||||
|
|
||||||
//qDebug() << jsonDoc.toJson();
|
qDebug() << jsonDoc.toJson();
|
||||||
|
|
||||||
m_manager->sendData(data);
|
m_manager->sendData(data);
|
||||||
return true;
|
return true;
|
||||||
@ -182,7 +182,7 @@ void DevicePluginTune::syncStates(Device *device)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginTune::tuneAdded()
|
bool DevicePluginTune::tuneAlreadyAdded()
|
||||||
{
|
{
|
||||||
foreach (Device *device, myDevices()) {
|
foreach (Device *device, myDevices()) {
|
||||||
if (device->deviceClassId() == tuneDeviceClassId) {
|
if (device->deviceClassId() == tuneDeviceClassId) {
|
||||||
@ -203,10 +203,24 @@ void DevicePluginTune::tuneAutodetected()
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginTune::activateMood(Device *device)
|
||||||
|
{
|
||||||
|
foreach (Device* d, myDevices()) {
|
||||||
|
if (d->deviceClassId() == moodDeviceClassId) {
|
||||||
|
if (d->id() == device->id()) {
|
||||||
|
d->setStateValue(activeStateTypeId, true);
|
||||||
|
} else {
|
||||||
|
d->setStateValue(activeStateTypeId, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
void DevicePluginTune::tuneConnectionStatusChanged(const bool &connected)
|
void DevicePluginTune::tuneConnectionStatusChanged(const bool &connected)
|
||||||
{
|
{
|
||||||
if (connected) {
|
if (connected) {
|
||||||
if (!tuneAdded()) {
|
if (!tuneAlreadyAdded()) {
|
||||||
tuneAutodetected();
|
tuneAutodetected();
|
||||||
} else {
|
} else {
|
||||||
Device *device = deviceManager()->findConfiguredDevice(m_tuneDeviceId);
|
Device *device = deviceManager()->findConfiguredDevice(m_tuneDeviceId);
|
||||||
@ -241,9 +255,12 @@ void DevicePluginTune::tuneDataAvailable(const QByteArray &data)
|
|||||||
bool activeValue = states.value("active").toBool();
|
bool activeValue = states.value("active").toBool();
|
||||||
int value = states.value("value").toInt();
|
int value = states.value("value").toInt();
|
||||||
|
|
||||||
// TODO: disable other mood befor enabling this one...
|
if (activeValue) {
|
||||||
|
// disable any active mood
|
||||||
device->setStateValue(activeStateTypeId, activeValue);
|
activateMood(device);
|
||||||
|
} else {
|
||||||
|
device->setStateValue(activeStateTypeId, activeValue);
|
||||||
|
}
|
||||||
device->setStateValue(valueStateTypeId, value);
|
device->setStateValue(valueStateTypeId, value);
|
||||||
}
|
}
|
||||||
} else if (message.contains("tune")) {
|
} else if (message.contains("tune")) {
|
||||||
|
|||||||
@ -44,8 +44,9 @@ private:
|
|||||||
bool sync();
|
bool sync();
|
||||||
void syncStates(Device *device);
|
void syncStates(Device *device);
|
||||||
|
|
||||||
bool tuneAdded();
|
bool tuneAlreadyAdded();
|
||||||
void tuneAutodetected();
|
void tuneAutodetected();
|
||||||
|
void activateMood(Device* device);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void tuneConnectionStatusChanged(const bool &connected);
|
void tuneConnectionStatusChanged(const bool &connected);
|
||||||
|
|||||||
@ -60,9 +60,9 @@
|
|||||||
"idName": "value",
|
"idName": "value",
|
||||||
"name": "value",
|
"name": "value",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"minimumValue": 0,
|
"minValue": 0,
|
||||||
"maximumValue": 100,
|
"maxValue": 100,
|
||||||
"defaultValue": 50,
|
"defaultValue": 100,
|
||||||
"writable": true
|
"writable": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -123,6 +123,9 @@
|
|||||||
"idName": "brightness",
|
"idName": "brightness",
|
||||||
"name": "brightness",
|
"name": "brightness",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100,
|
||||||
|
"defaultValue": 100,
|
||||||
"writable": true
|
"writable": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -46,7 +46,7 @@ void TuneManager::tuneConnected()
|
|||||||
QTcpSocket *socket = m_server->nextPendingConnection();
|
QTcpSocket *socket = m_server->nextPendingConnection();
|
||||||
|
|
||||||
if (m_tune) {
|
if (m_tune) {
|
||||||
qWarning() << "--> ATTENTION: tune allready connected! connection refused.";
|
qWarning() << "--> ATTENTION: tune already connected! connection refused.";
|
||||||
socket->disconnect();
|
socket->disconnect();
|
||||||
delete socket;
|
delete socket;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user