improved device detection

This commit is contained in:
Bernhard Trinnes 2018-06-12 15:45:21 +02:00 committed by Michael Zanetti
parent c8c730fe00
commit f96b2ab3c8

View File

@ -498,11 +498,13 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
}
if (obj["dev"] == "relay") {
qCDebug(dcUniPi()) << "Relay:" << obj["dev"].toString() << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toInt() << "Relay Type:" << obj["relay_type"].toInt() ;
qCDebug(dcUniPi()) << "Relay:" << obj["dev"].toString() << "Circuit:" << obj["circuit"].toString() << "Value:" << obj["value"].toInt() << "Relay Type:" << obj["relay_type"].toString() ;
QString circuit = obj["circuit"].toString();
bool value = QVariant(obj["value"].toInt()).toBool();
if (obj["relay_type"].toString() == "physical") {
if (!m_relais.contains(circuit)) {
//New Device detected
m_relais.append(circuit);
@ -545,6 +547,22 @@ void DevicePluginUniPi::onWebSocketTextMessageReceived(QString message)
}
}
}
} else if (obj["relay_type"].toString() == "digtial") {
if (!m_digitalOutputs.contains(obj["circuit"].toString())){
//New Device detected
m_digitalOutputs.append(obj["circuit"].toString());
} else {
foreach (Device *device, myDevices()) {
if (device->deviceClassId() == digitalOutputDeviceClassId) {
if (obj["circuit"] == device->paramValue(digitalOutputDigitalOutputNumberParamTypeId).toString()) {
device->setStateValue(digitalOutputDigitalOutputStatusStateTypeId, QVariant(obj["value"].toInt()).toBool());
break;
}
}
}
}
}
}
if (obj["dev"] == "input") {