Log interesting go-eCharger states and fix execute action and discovry

master
Simon Stürz 2021-06-09 09:34:09 +02:00
parent 1a09836dd7
commit 24a7ce13be
2 changed files with 33 additions and 14 deletions

View File

@ -59,9 +59,14 @@ void IntegrationPluginGoECharger::discoverThings(ThingDiscoveryInfo *info)
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) {
qCDebug(dcGoECharger()) << "Found" << networkDevice;
// Filter by hostname
if (!networkDevice.hostName().toLower().contains("go-echarger"))
continue;
// We need also the mac address
if (!networkDevice.macAddress().isEmpty())
continue;
QString title;
if (networkDevice.hostName().isEmpty()) {
title = networkDevice.address().toString();
@ -152,7 +157,8 @@ void IntegrationPluginGoECharger::executeAction(ThingActionInfo *info)
return;
}
if (thing->stateValue(goeHomeConnectedStateTypeId).toBool()) {
if (!thing->stateValue(goeHomeConnectedStateTypeId).toBool()) {
qCWarning(dcGoECharger()) << thing << "failed to execute action. The device seems not to be connected.";
info->finish(Thing::ThingErrorHardwareNotAvailable);
return;
}
@ -246,6 +252,8 @@ void IntegrationPluginGoECharger::onPublishReceived(MqttChannel *channel, const
QString serialNumber = thing->stateValue(goeHomeSerialNumberStateTypeId).toString();
if (topic == QString("go-eCharger/%1/status").arg(serialNumber)) {
update(thing, jsonDoc.toVariant().toMap());
} else {
qCDebug(dcGoECharger()) << "Unhandled topic publish received:" << topic << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Compact));
}
}
@ -338,8 +346,8 @@ void IntegrationPluginGoECharger::sendActionRequest(Thing *thing, ThingActionInf
return;
}
qCDebug(dcGoECharger()) << "Action response" << jsonDoc.toJson(QJsonDocument::Compact);
info->finish(Thing::ThingErrorNoError);
update(thing, jsonDoc.toVariant().toMap());
});
}
@ -349,9 +357,10 @@ void IntegrationPluginGoECharger::setupMqttChannel(ThingSetupInfo *info, const Q
QString serialNumber = statusMap.value("sse").toString();
QString clientId = QString("go-eCharger:%1:%2").arg(serialNumber).arg(statusMap.value("rbc").toInt());
QString statusTopic = QString("go-eCharger/%1/status").arg(serialNumber);
qCDebug(dcGoECharger()) << "Setting up mqtt channel for" << thing << address.toString() << statusTopic;
QString commandTopic = QString("go-eCharger/%1/cmd/req").arg(serialNumber);
qCDebug(dcGoECharger()) << "Setting up mqtt channel for" << thing << address.toString() << statusTopic << commandTopic;
MqttChannel *channel = hardwareManager()->mqttProvider()->createChannel(clientId, address, {statusTopic});
MqttChannel *channel = hardwareManager()->mqttProvider()->createChannel(clientId, address, {statusTopic, commandTopic});
if (!channel) {
qCWarning(dcGoECharger()) << "Failed to create MQTT channel for" << thing;
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Error creating MQTT channel. Please check MQTT server settings."));

View File

@ -50,7 +50,8 @@
"Waiting for vehicle",
"Charging finished and vehicle still connected"
],
"defaultValue": "Ready but no vehicle connected"
"defaultValue": "Ready but no vehicle connected",
"suggestLogging": true
},
{
"id": "d80e1ed8-c3ae-4b68-bf86-21b4d7b2b201",
@ -63,7 +64,8 @@
"RFID",
"Automatic"
],
"defaultValue": "Open"
"defaultValue": "Open",
"suggestLogging": true
},
{
"id": "8a7ab9f1-0143-494c-98ee-69f94125fe42",
@ -96,7 +98,8 @@
"displayNameEvent": "Cloud enabled changed",
"type": "bool",
"defaultValue": true,
"writable": true
"writable": true,
"suggestLogging": true
},
{
"id": "08b107bc-1284-455d-9e5a-6a1c3adc389f",
@ -104,7 +107,8 @@
"displayName": "Update available",
"displayNameEvent": "Update available changed",
"type": "bool",
"defaultValue": false
"defaultValue": false,
"suggestLogging": true
},
{
"id": "d557e59e-ca22-4aff-bf80-dfee44db0f69",
@ -112,7 +116,8 @@
"displayName": "Adapter connected",
"displayNameEvent": "Adapter connected changed",
"type": "bool",
"defaultValue": false
"defaultValue": false,
"suggestLogging": true
},
{
"id": "d8f5abb6-5db3-4040-8829-553b1d881ce4",
@ -130,7 +135,8 @@
"displayNameEvent": "Charge energy changed",
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 0.0
"defaultValue": 0.0,
"suggestLogging": true
},
{
"id": "b06479d5-7a38-4fbd-867e-e55bdb54651b",
@ -161,7 +167,8 @@
"displayNameEvent": "Temperature 1 changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0.0
"defaultValue": 0.0,
"suggestLogging": true
},
{
"id": "558e273a-4028-495a-902a-e4e932a0ae24",
@ -170,7 +177,8 @@
"displayNameEvent": "Temperature 2 changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0.0
"defaultValue": 0.0,
"suggestLogging": true
},
{
"id": "dbf8a5dc-b8f5-437a-ac0c-c4cf8a09aacb",
@ -179,7 +187,8 @@
"displayNameEvent": "Temperature 3 changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0.0
"defaultValue": 0.0,
"suggestLogging": true
},
{
"id": "1953e29f-fe28-4016-9b05-f4baf4c311ff",
@ -188,7 +197,8 @@
"displayNameEvent": "Temperature 4 changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0.0
"defaultValue": 0.0,
"suggestLogging": true
},
{
"id": "5d18b48d-b886-409e-ab2e-336d9c94a55c",