Add settings support
parent
4b70216f65
commit
07997b6dce
|
|
@ -1323,6 +1323,9 @@ void IntegrationPluginShelly::setupGen1(ThingSetupInfo *info)
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(url));
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(url));
|
||||||
qCDebug(dcShelly()) << "Setting configuration:" << url.toString();
|
qCDebug(dcShelly()) << "Setting configuration:" << url.toString();
|
||||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
|
connect(reply, &QNetworkReply::finished, [reply](){
|
||||||
|
qCDebug(dcShelly) << "Set config reply:" << reply->error() << reply->errorString() << reply->readAll();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1375,7 +1378,9 @@ void IntegrationPluginShelly::setupGen2(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == QAbstractSocket::UnconnectedState) {
|
if (state == QAbstractSocket::UnconnectedState) {
|
||||||
client->open(getIP(thing), "admin", thing->paramValue("password").toString(), thing->paramValue("id").toString());
|
QTimer::singleShot(1000, thing, [this, client, thing](){
|
||||||
|
client->open(getIP(thing), "admin", thing->paramValue("password").toString(), thing->paramValue("id").toString());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(client, &ShellyJsonRpcClient::notificationReceived, thing, [thing, this](const QVariantMap ¬ification){
|
connect(client, &ShellyJsonRpcClient::notificationReceived, thing, [thing, this](const QVariantMap ¬ification){
|
||||||
|
|
@ -1427,34 +1432,64 @@ void IntegrationPluginShelly::setupShellyChild(ThingSetupInfo *info)
|
||||||
qCDebug(dcShelly()) << "Parent for" << info->thing()->name() << "is set up. Finishing child setup.";
|
qCDebug(dcShelly()) << "Parent for" << info->thing()->name() << "is set up. Finishing child setup.";
|
||||||
|
|
||||||
// Connect to settings changes to store them to the thing
|
// Connect to settings changes to store them to the thing
|
||||||
connect(info->thing(), &Thing::settingChanged, this, [this, thing](const ParamTypeId ¶mTypeId, const QVariant &value){
|
connect(info->thing(), &Thing::settingChanged, this, [this, thing, parent](const ParamTypeId ¶mTypeId, const QVariant &value){
|
||||||
Thing *parentDevice = myThings().findById(thing->parentId());
|
if (parent->paramValue("id").toString().contains("Plus")) {
|
||||||
pluginStorage()->beginGroup(parentDevice->id().toString());
|
ShellyJsonRpcClient *client = m_rpcClients.value(parent);
|
||||||
QString address = pluginStorage()->value("cachedAddress").toString();
|
QVariantMap params;
|
||||||
pluginStorage()->endGroup();
|
params.insert("id", thing->paramValue("channel").toInt() - 1);
|
||||||
|
|
||||||
QUrl url;
|
if (paramTypeId == shellySwitchSettingsButtonTypeParamTypeId) {
|
||||||
url.setScheme("http");
|
QVariantMap inputConfig;
|
||||||
url.setHost(address);
|
if (value == "toggle" || value == "edge") {
|
||||||
url.setPort(80);
|
inputConfig.insert("type", "switch");
|
||||||
url.setPath(QString("/settings/relay/%0").arg(thing->paramValue(channelParamTypeMap.value(thing->thingClassId())).toInt() - 1));
|
} else {
|
||||||
url.setUserName(parentDevice->paramValue(usernameParamTypeMap.value(parentDevice->thingClassId())).toString());
|
inputConfig.insert("type", "button");
|
||||||
url.setPassword(parentDevice->paramValue(passwordParamTypeMap.value(parentDevice->thingClassId())).toString());
|
}
|
||||||
|
params["config"] = inputConfig;
|
||||||
|
client->sendRequest("Input.SetConfig", params);
|
||||||
|
|
||||||
QUrlQuery query;
|
QVariantMap switchConfig;
|
||||||
if (paramTypeId == shellySwitchSettingsButtonTypeParamTypeId) {
|
switchConfig.insert("in_mode", value.toString().replace("toggle", "follow").replace("edge", "flip"));
|
||||||
query.addQueryItem("btn_type", value.toString());
|
params["config"] = switchConfig;
|
||||||
|
client->sendRequest("Switch.SetConfig", params);
|
||||||
|
|
||||||
|
} else if (paramTypeId == shellySwitchSettingsInvertButtonParamTypeId) {
|
||||||
|
QVariantMap config;
|
||||||
|
config.insert("invert", value.toBool());
|
||||||
|
params.insert("config", config);
|
||||||
|
client->sendRequest("Input.SetConfig", params);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pluginStorage()->beginGroup(parent->id().toString());
|
||||||
|
QString address = pluginStorage()->value("cachedAddress").toString();
|
||||||
|
pluginStorage()->endGroup();
|
||||||
|
|
||||||
|
QUrl url;
|
||||||
|
url.setScheme("http");
|
||||||
|
url.setHost(address);
|
||||||
|
url.setPort(80);
|
||||||
|
url.setPath(QString("/settings/relay/%0").arg(thing->paramValue(channelParamTypeMap.value(thing->thingClassId())).toInt() - 1));
|
||||||
|
url.setUserName(parent->paramValue(usernameParamTypeMap.value(parent->thingClassId())).toString());
|
||||||
|
url.setPassword(parent->paramValue(passwordParamTypeMap.value(parent->thingClassId())).toString());
|
||||||
|
|
||||||
|
QUrlQuery query;
|
||||||
|
if (paramTypeId == shellySwitchSettingsButtonTypeParamTypeId) {
|
||||||
|
query.addQueryItem("btn_type", value.toString());
|
||||||
|
}
|
||||||
|
if (paramTypeId == shellySwitchSettingsInvertButtonParamTypeId) {
|
||||||
|
query.addQueryItem("btn_reverse", value.toBool() ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
url.setQuery(query);
|
||||||
|
|
||||||
|
qCDebug(dcShelly) << "Setting configuration:" << url.toString();
|
||||||
|
|
||||||
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(url));
|
||||||
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
|
connect(reply, &QNetworkReply::finished, [reply](){
|
||||||
|
qCDebug(dcShelly) << "Set config reply:" << reply->error() << reply->errorString() << reply->readAll();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (paramTypeId == shellySwitchSettingsInvertButtonParamTypeId) {
|
|
||||||
query.addQueryItem("btn_reverse", value.toBool() ? "1" : "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
url.setQuery(query);
|
|
||||||
|
|
||||||
qCDebug(dcShelly) << "Setting configuration:" << url.toString();
|
|
||||||
|
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(url));
|
|
||||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ ShellyRpcReply *ShellyJsonRpcClient::sendRequest(const QString &method, const QV
|
||||||
});
|
});
|
||||||
m_pendingReplies.insert(id, reply);
|
m_pendingReplies.insert(id, reply);
|
||||||
|
|
||||||
qCDebug(dcShelly) << "Sending request" << QJsonDocument::fromVariant(data).toJson();
|
qCDebug(dcShelly) << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(data).toJson());
|
||||||
m_socket->sendTextMessage(QJsonDocument::fromVariant(data).toJson(QJsonDocument::Compact));
|
m_socket->sendTextMessage(QJsonDocument::fromVariant(data).toJson(QJsonDocument::Compact));
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue