update communication
This commit is contained in:
parent
4ff255cecb
commit
ef482afebc
@ -41,15 +41,16 @@ DeviceManager::HardwareResources DevicePluginTune::requiredHardware() const
|
|||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
if (!m_manager->tuneAvailable()) {
|
|
||||||
qWarning() << "WARNING: tune not connected!";
|
|
||||||
}
|
|
||||||
|
|
||||||
// check index position
|
// check index position
|
||||||
int position = device->paramValue("position").toInt();
|
int position = device->paramValue("position").toInt();
|
||||||
|
|
||||||
if (position >= myDevices().count()) {
|
if (position >= myDevices().count()) {
|
||||||
device->setParamValue("position", myDevices().count());
|
device->setParamValue("position", myDevices().count());
|
||||||
} else {
|
} else {
|
||||||
|
if (position <= 0) {
|
||||||
|
device->setParamValue("position", 0);
|
||||||
|
position = 0;
|
||||||
|
}
|
||||||
foreach (Device *d, myDevices()) {
|
foreach (Device *d, myDevices()) {
|
||||||
int currentPosition = d->paramValue("position").toInt();
|
int currentPosition = d->paramValue("position").toInt();
|
||||||
if (currentPosition >= position) {
|
if (currentPosition >= position) {
|
||||||
@ -73,6 +74,12 @@ DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device)
|
|||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginTune::postSetupDevice(Device *device)
|
||||||
|
{
|
||||||
|
Q_UNUSED(device)
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
void DevicePluginTune::deviceRemoved(Device *device)
|
void DevicePluginTune::deviceRemoved(Device *device)
|
||||||
{
|
{
|
||||||
int position = device->paramValue("position").toInt();
|
int position = device->paramValue("position").toInt();
|
||||||
@ -94,18 +101,30 @@ bool DevicePluginTune::sync()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap message;
|
QVariantMap message;
|
||||||
QVariantList devices;
|
QVariantList moods;
|
||||||
|
QVariantList todos;
|
||||||
foreach (Device* device, myDevices()) {
|
foreach (Device* device, myDevices()) {
|
||||||
qDebug() << "device id" << device->id();
|
if (device->deviceClassId() == moodDeviceClassId) {
|
||||||
QVariantMap d;
|
QVariantMap mood;
|
||||||
d.insert("name", device->paramValue("name"));
|
mood.insert("name", device->paramValue("name"));
|
||||||
d.insert("id", device->id());
|
mood.insert("id", device->id());
|
||||||
d.insert("deviceClassId", device->deviceClassId());
|
mood.insert("deviceClassId", device->deviceClassId());
|
||||||
d.insert("pos", device->paramValue("position"));
|
mood.insert("pos", device->paramValue("position"));
|
||||||
d.insert("icon", device->paramValue("icon"));
|
mood.insert("icon", device->paramValue("icon"));
|
||||||
devices.append(d);
|
moods.append(mood);
|
||||||
|
} else if(device->deviceClassId() == todoDeviceClassId) {
|
||||||
|
QVariantMap todo;
|
||||||
|
todo.insert("name", device->paramValue("name"));
|
||||||
|
todo.insert("id", device->id());
|
||||||
|
todo.insert("deviceClassId", device->deviceClassId());
|
||||||
|
todo.insert("pos", device->paramValue("position"));
|
||||||
|
todo.insert("icon", device->paramValue("icon"));
|
||||||
|
todos.append(todo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message.insert("devices", devices);
|
message.insert("method", "Items.Sync");
|
||||||
|
message.insert("moods", moods);
|
||||||
|
message.insert("todos", todos);
|
||||||
|
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
||||||
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
||||||
@ -134,6 +153,12 @@ void DevicePluginTune::tuneDataAvailable(const QByteArray &data)
|
|||||||
}
|
}
|
||||||
qDebug() << jsonDoc.toJson();
|
qDebug() << jsonDoc.toJson();
|
||||||
|
|
||||||
|
|
||||||
|
// Check what happend...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginTune::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginTune::executeAction(Device *device, const Action &action)
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public:
|
|||||||
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
|
void postSetupDevice(Device *device) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -43,8 +43,6 @@ bool TuneManager::sendData(const QByteArray &data)
|
|||||||
|
|
||||||
void TuneManager::tuneConnected()
|
void TuneManager::tuneConnected()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
QTcpSocket *socket = m_server->nextPendingConnection();
|
QTcpSocket *socket = m_server->nextPendingConnection();
|
||||||
|
|
||||||
if (m_tune) {
|
if (m_tune) {
|
||||||
|
|||||||
Reference in New Issue
Block a user