first version of working tune communication
This commit is contained in:
parent
7757277a54
commit
184a904b67
@ -65,12 +65,6 @@ DeviceManager::DeviceSetupStatus DevicePluginTune::setupDevice(Device *device)
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
// todo
|
||||
if (device->deviceClassId() == todoDeviceClassId) {
|
||||
device->setName(device->paramValue("name").toString() + " (Todo)");
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
return DeviceManager::DeviceSetupStatusFailure;
|
||||
}
|
||||
|
||||
@ -102,7 +96,6 @@ bool DevicePluginTune::sync()
|
||||
|
||||
QVariantMap message;
|
||||
QVariantList moods;
|
||||
QVariantList todos;
|
||||
foreach (Device* device, myDevices()) {
|
||||
if (device->deviceClassId() == moodDeviceClassId) {
|
||||
QVariantMap mood;
|
||||
@ -111,29 +104,46 @@ bool DevicePluginTune::sync()
|
||||
mood.insert("deviceClassId", device->deviceClassId().toString());
|
||||
mood.insert("position", device->paramValue("position"));
|
||||
mood.insert("icon", device->paramValue("icon"));
|
||||
QVariantMap states;
|
||||
states.insert("value", device->stateValue(valueStateTypeId).toInt());
|
||||
states.insert("active", device->stateValue(activeStateTypeId).toBool());
|
||||
mood.insert("states", states);
|
||||
moods.append(mood);
|
||||
} else if(device->deviceClassId() == todoDeviceClassId) {
|
||||
QVariantMap todo;
|
||||
todo.insert("name", device->paramValue("name"));
|
||||
todo.insert("deviceId", device->id().toString());
|
||||
todo.insert("deviceClassId", device->deviceClassId().toString());
|
||||
todo.insert("position", device->paramValue("position"));
|
||||
todo.insert("icon", device->paramValue("icon"));
|
||||
todos.append(todo);
|
||||
}
|
||||
}
|
||||
|
||||
message.insert("method", "Items.Sync");
|
||||
message.insert("moods", moods);
|
||||
message.insert("todos", todos);
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
||||
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
||||
|
||||
qDebug() << data;
|
||||
//qDebug() << data;
|
||||
|
||||
m_manager->sendData(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DevicePluginTune::syncStates(Device *device)
|
||||
{
|
||||
QVariantMap message;
|
||||
QVariantMap mood;
|
||||
QVariantMap states;
|
||||
states.insert("value", device->stateValue(valueStateTypeId).toInt());
|
||||
states.insert("active", device->stateValue(activeStateTypeId).toBool());
|
||||
mood.insert("states", states);
|
||||
mood.insert("deviceId", device->id());
|
||||
mood.insert("position", device->paramValue("position"));
|
||||
message.insert("method", "Items.SyncStates");
|
||||
message.insert("mood", mood);
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(message);
|
||||
QByteArray data = jsonDoc.toJson(QJsonDocument::Compact);
|
||||
|
||||
//qDebug() << jsonDoc.toJson();
|
||||
|
||||
m_manager->sendData(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DevicePluginTune::tuneConnectionStatusChanged(const bool &connected)
|
||||
@ -151,14 +161,22 @@ void DevicePluginTune::tuneDataAvailable(const QByteArray &data)
|
||||
if(error.error != QJsonParseError::NoError) {
|
||||
qDebug() << "failed to parse data" << data << ":" << error.errorString();
|
||||
}
|
||||
qDebug() << jsonDoc.toJson();
|
||||
|
||||
|
||||
// Check what happend...
|
||||
|
||||
|
||||
|
||||
QVariantMap message = jsonDoc.toVariant().toMap();
|
||||
if (message.contains("method")) {
|
||||
if (message.value("method").toString() == "Items.SyncStates") {
|
||||
QVariantMap mood = message.value("mood").toMap();
|
||||
|
||||
|
||||
foreach (Device *device, myDevices()) {
|
||||
if (device->id() == DeviceId(mood.value("deviceId").toString())) {
|
||||
device->setStateValue(activeStateTypeId, mood.value("states").toMap().value("active"));
|
||||
device->setStateValue(valueStateTypeId, mood.value("states").toMap().value("value"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DevicePluginTune::executeAction(Device *device, const Action &action)
|
||||
@ -172,19 +190,17 @@ DeviceManager::DeviceError DevicePluginTune::executeAction(Device *device, const
|
||||
if (action.actionTypeId() == toggleActionTypeId) {
|
||||
bool currentState = device->stateValue(activeStateTypeId).toBool();
|
||||
device->setStateValue(activeStateTypeId, !currentState);
|
||||
syncStates(device);
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
if (action.actionTypeId() == setValueActionTypeId) {
|
||||
device->setStateValue(valueStateTypeId, action.param("percentage").value().toInt());
|
||||
syncStates(device);
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
// Todo
|
||||
if (device->deviceClassId() == todoDeviceClassId) {
|
||||
if (action.actionTypeId() == pressActionTypeId) {
|
||||
emit emitEvent(Event(pressedEventTypeId, device->id()));
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
}
|
||||
|
||||
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||
}
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ public:
|
||||
private:
|
||||
TuneManager *m_manager;
|
||||
bool sync();
|
||||
void syncStates(Device *device);
|
||||
|
||||
private slots:
|
||||
void tuneConnectionStatusChanged(const bool &connected);
|
||||
|
||||
@ -26,12 +26,14 @@
|
||||
"type": "QString",
|
||||
"allowedValues": [
|
||||
"IconCouch",
|
||||
"IconWork",
|
||||
"IconToilet",
|
||||
"IconSex",
|
||||
"IconDrinking",
|
||||
"IconEating",
|
||||
"IconSmoking"
|
||||
"IconLamp",
|
||||
"IconLamp1",
|
||||
"IconLamp2",
|
||||
"IconLamp3",
|
||||
"IconSmoking",
|
||||
"IconSocket",
|
||||
"IconThermometer",
|
||||
"IconWork"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -47,7 +49,7 @@
|
||||
"id": "cb8a89c2-dc12-4965-b047-57896058b421",
|
||||
"idName": "value",
|
||||
"name": "value",
|
||||
"type": "uint",
|
||||
"type": "int",
|
||||
"defaultValue": 50
|
||||
}
|
||||
],
|
||||
@ -64,77 +66,13 @@
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "percentage",
|
||||
"type": "uint",
|
||||
"type": "int",
|
||||
"minimumValue": 0,
|
||||
"maximumValue": 100
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"deviceClassId": "56c14ef8-3a19-432f-9d9f-dc7e1d489312",
|
||||
"idName": "todo",
|
||||
"name": "ToDo",
|
||||
"createMethods": ["user"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"name": "position",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"name": "icon",
|
||||
"type": "QString",
|
||||
"allowedValues": [
|
||||
"IconCouch",
|
||||
"IconWork",
|
||||
"IconToilet",
|
||||
"IconSex",
|
||||
"IconDrinking",
|
||||
"IconEating",
|
||||
"IconSmoking"
|
||||
]
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "52b66edc-df40-42ef-a39c-aa2b77fdf42e",
|
||||
"idName": "pressed",
|
||||
"name": "pressed"
|
||||
},
|
||||
{
|
||||
"id": "277f10fd-3fc3-4229-904a-661b6f1cac54",
|
||||
"idName": "todoLeft",
|
||||
"name": "left"
|
||||
},
|
||||
{
|
||||
"id": "a510968e-f313-4880-95bd-786bd3bcb357",
|
||||
"idName": "todoRight",
|
||||
"name": "right"
|
||||
}
|
||||
],
|
||||
"actionTypes": [
|
||||
{
|
||||
"id": "1a2dac4d-26b3-496f-a4c2-8cb90c75e026",
|
||||
"idName": "press",
|
||||
"name": "press"
|
||||
},
|
||||
{
|
||||
"id": "0c461c5a-1334-4559-816b-73b5b2afb3ba",
|
||||
"idName": "tickLeft",
|
||||
"name": "tick left"
|
||||
},
|
||||
{
|
||||
"id": "a67cda4a-2c6f-4815-818a-08094dfcc453",
|
||||
"idName": "tickRight",
|
||||
"name": "tick right"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ void TuneManager::readData()
|
||||
QByteArray message;
|
||||
while (m_tune->canReadLine()) {
|
||||
QByteArray dataLine = m_tune->readLine();
|
||||
qDebug() << " --> tune line in:" << dataLine;
|
||||
//qDebug() << " --> tune line in:" << dataLine;
|
||||
message.append(dataLine);
|
||||
if (dataLine.endsWith('\n')) {
|
||||
emit dataReady(message);
|
||||
|
||||
Reference in New Issue
Block a user