small fixes in plantcare and orderbutton
This commit is contained in:
parent
4f36f7c543
commit
2ddf19b6da
@ -174,9 +174,9 @@ DeviceManager::DeviceError DevicePluginOrderButton::executeAction(Device *device
|
|||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("coap");
|
url.setScheme("coap");
|
||||||
url.setHost(device->paramValue("host").toString());
|
url.setHost(device->paramValue("host").toString());
|
||||||
url.setPath("/a/reset");
|
url.setPath("/s/count");
|
||||||
|
|
||||||
CoapReply *reply = m_coap->post(CoapRequest(url));
|
CoapReply *reply = m_coap->post(CoapRequest(url), QByteArray("count=0"));
|
||||||
if (reply->isFinished() && reply->error() != CoapReply::NoError) {
|
if (reply->isFinished() && reply->error() != CoapReply::NoError) {
|
||||||
qCWarning(dcOrderButton) << "CoAP reply finished with error" << reply->errorString();
|
qCWarning(dcOrderButton) << "CoAP reply finished with error" << reply->errorString();
|
||||||
setReachable(device, false);
|
setReachable(device, false);
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
{
|
{
|
||||||
"name": "guh",
|
"name": "guh",
|
||||||
"idName": "guh",
|
"idName": "guh",
|
||||||
"id": "76df1ad2-c179-4842-94ea-2da6e4796339",
|
"id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6",
|
||||||
"deviceClasses": [
|
"deviceClasses": [
|
||||||
{
|
{
|
||||||
"deviceClassId": "af4df281-2b3b-490f-8352-2b99ff23fc15",
|
"deviceClassId": "af4df281-2b3b-490f-8352-2b99ff23fc15",
|
||||||
|
|||||||
@ -189,15 +189,15 @@ DeviceManager::DeviceError DevicePluginPlantCare::executeAction(Device *device,
|
|||||||
m_asyncActions.insert(action.id(), device);
|
m_asyncActions.insert(action.id(), device);
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
|
||||||
} else if(action.actionTypeId() == brightnessActionTypeId) {
|
} else if(action.actionTypeId() == ledPowerActionTypeId) {
|
||||||
int light = qRound(action.param("brightness").value().toInt() * 255.0 / 100.0);
|
int power = action.param("led power").value().toInt();
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("coap");
|
url.setScheme("coap");
|
||||||
url.setHost(device->paramValue("host").toString());
|
url.setHost(device->paramValue("host").toString());
|
||||||
url.setPath("/a/light");
|
url.setPath("/a/light");
|
||||||
|
|
||||||
QByteArray payload = QString("pwm=%1").arg(QString::number(light)).toUtf8();
|
QByteArray payload = QString("pwm=%1").arg(QString::number(power)).toUtf8();
|
||||||
qCDebug(dcPlantCare()) << "Sending" << payload << url.path();
|
qCDebug(dcPlantCare()) << "Sending" << payload << url.path();
|
||||||
CoapReply *reply = m_coap->post(CoapRequest(url), payload);
|
CoapReply *reply = m_coap->post(CoapRequest(url), payload);
|
||||||
if (reply->isFinished() && reply->error() != CoapReply::NoError) {
|
if (reply->isFinished() && reply->error() != CoapReply::NoError) {
|
||||||
@ -207,7 +207,7 @@ DeviceManager::DeviceError DevicePluginPlantCare::executeAction(Device *device,
|
|||||||
return DeviceManager::DeviceErrorHardwareFailure;
|
return DeviceManager::DeviceErrorHardwareFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_setBrightness.insert(reply, action);
|
m_setLedPower.insert(reply, action);
|
||||||
m_asyncActions.insert(action.id(), device);
|
m_asyncActions.insert(action.id(), device);
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
|
|
||||||
@ -451,8 +451,13 @@ void DevicePluginPlantCare::coapReplyFinished(CoapReply *reply)
|
|||||||
qCDebug(dcPlantCare()) << "Updated pump value:" << reply->payload();
|
qCDebug(dcPlantCare()) << "Updated pump value:" << reply->payload();
|
||||||
device->setStateValue(waterPumpStateTypeId, QVariant(reply->payload().toInt()).toBool());
|
device->setStateValue(waterPumpStateTypeId, QVariant(reply->payload().toInt()).toBool());
|
||||||
} else if (urlPath == "/a/light") {
|
} else if (urlPath == "/a/light") {
|
||||||
qCDebug(dcPlantCare()) << "Updated brightness value:" << reply->payload();
|
qCDebug(dcPlantCare()) << "Updated led power value:" << reply->payload();
|
||||||
device->setStateValue(brightnessStateTypeId, qRound(reply->payload().toInt() * 100.0 / 255.0));
|
int powerValue = reply->payload().toInt();
|
||||||
|
if (powerValue > 0) {
|
||||||
|
device->setStateValue(ledPowerStateTypeId, false);
|
||||||
|
} else {
|
||||||
|
device->setStateValue(ledPowerStateTypeId, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (m_toggleLightRequests.contains(reply)) {
|
} else if (m_toggleLightRequests.contains(reply)) {
|
||||||
@ -478,13 +483,13 @@ void DevicePluginPlantCare::coapReplyFinished(CoapReply *reply)
|
|||||||
// Tell the user about the action execution result
|
// Tell the user about the action execution result
|
||||||
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError);
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError);
|
||||||
|
|
||||||
} else if (m_setBrightness.contains(reply)) {
|
} else if (m_setLedPower.contains(reply)) {
|
||||||
Action action = m_setBrightness.take(reply);
|
Action action = m_setLedPower.take(reply);
|
||||||
Device *device = m_asyncActions.take(action.id());
|
Device *device = m_asyncActions.take(action.id());
|
||||||
|
|
||||||
// check CoAP reply error
|
// check CoAP reply error
|
||||||
if (reply->error() != CoapReply::NoError) {
|
if (reply->error() != CoapReply::NoError) {
|
||||||
qCWarning(dcPlantCare) << "CoAP set brightness reply finished with error" << reply->errorString();
|
qCWarning(dcPlantCare) << "CoAP set led power reply finished with error" << reply->errorString();
|
||||||
setReachable(device, false);
|
setReachable(device, false);
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure);
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure);
|
||||||
@ -493,14 +498,14 @@ void DevicePluginPlantCare::coapReplyFinished(CoapReply *reply)
|
|||||||
|
|
||||||
// Check CoAP status code
|
// Check CoAP status code
|
||||||
if (reply->statusCode() != CoapPdu::Content) {
|
if (reply->statusCode() != CoapPdu::Content) {
|
||||||
qCWarning(dcPlantCare) << "Set brightness status code error:" << reply;
|
qCWarning(dcPlantCare) << "Set led power status code error:" << reply;
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure);
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the state here, so we don't have to wait for the notification
|
// Update the state here, so we don't have to wait for the notification
|
||||||
device->setStateValue(brightnessStateTypeId, action.param("brightness").value().toInt());
|
device->setStateValue(ledPowerStateTypeId, action.param("led power").value().toBool());
|
||||||
// Tell the user about the action execution result
|
// Tell the user about the action execution result
|
||||||
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError);
|
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError);
|
||||||
|
|
||||||
@ -574,6 +579,11 @@ void DevicePluginPlantCare::onNotificationReceived(const CoapObserveResource &re
|
|||||||
} else if (resource.url().path() == "/a/pump") {
|
} else if (resource.url().path() == "/a/pump") {
|
||||||
device->setStateValue(waterPumpStateTypeId, QVariant(payload.toInt()).toBool());
|
device->setStateValue(waterPumpStateTypeId, QVariant(payload.toInt()).toBool());
|
||||||
} else if (resource.url().path() == "/a/light") {
|
} else if (resource.url().path() == "/a/light") {
|
||||||
device->setStateValue(brightnessStateTypeId, qRound(payload.toInt() * 100.0 / 255.0));
|
int powerValue = QVariant(payload).toInt();
|
||||||
|
if (powerValue > 0) {
|
||||||
|
device->setStateValue(ledPowerStateTypeId, false);
|
||||||
|
} else {
|
||||||
|
device->setStateValue(ledPowerStateTypeId, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ private:
|
|||||||
QHash<ActionId, Device *> m_asyncActions;
|
QHash<ActionId, Device *> m_asyncActions;
|
||||||
|
|
||||||
QHash<CoapReply *, Action> m_toggleLightRequests;
|
QHash<CoapReply *, Action> m_toggleLightRequests;
|
||||||
QHash<CoapReply *, Action> m_setBrightness;
|
QHash<CoapReply *, Action> m_setLedPower;
|
||||||
QHash<CoapReply *, Action> m_setPumpPower;
|
QHash<CoapReply *, Action> m_setPumpPower;
|
||||||
|
|
||||||
void pingDevice(Device *device);
|
void pingDevice(Device *device);
|
||||||
|
|||||||
@ -57,14 +57,11 @@
|
|||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "21b51fc9-1bfd-4970-a50d-e697a58df1bf",
|
"id": "819aca98-25e5-4733-81e0-5921478b3e89",
|
||||||
"idName": "brightness",
|
"idName": "ledPower",
|
||||||
"name": "brightness",
|
"name": "led power",
|
||||||
"unit": "Percentage",
|
"type": "bool",
|
||||||
"type": "int",
|
"defaultValue": false,
|
||||||
"minValue": 0,
|
|
||||||
"maxValue": 100,
|
|
||||||
"defaultValue": 0,
|
|
||||||
"writable": true
|
"writable": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user