Add settings support
parent
4b70216f65
commit
07997b6dce
|
|
@ -1323,6 +1323,9 @@ void IntegrationPluginShelly::setupGen1(ThingSetupInfo *info)
|
|||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(url));
|
||||
qCDebug(dcShelly()) << "Setting configuration:" << url.toString();
|
||||
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) {
|
||||
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){
|
||||
|
|
@ -1427,9 +1432,35 @@ void IntegrationPluginShelly::setupShellyChild(ThingSetupInfo *info)
|
|||
qCDebug(dcShelly()) << "Parent for" << info->thing()->name() << "is set up. Finishing child setup.";
|
||||
|
||||
// Connect to settings changes to store them to the thing
|
||||
connect(info->thing(), &Thing::settingChanged, this, [this, thing](const ParamTypeId ¶mTypeId, const QVariant &value){
|
||||
Thing *parentDevice = myThings().findById(thing->parentId());
|
||||
pluginStorage()->beginGroup(parentDevice->id().toString());
|
||||
connect(info->thing(), &Thing::settingChanged, this, [this, thing, parent](const ParamTypeId ¶mTypeId, const QVariant &value){
|
||||
if (parent->paramValue("id").toString().contains("Plus")) {
|
||||
ShellyJsonRpcClient *client = m_rpcClients.value(parent);
|
||||
QVariantMap params;
|
||||
params.insert("id", thing->paramValue("channel").toInt() - 1);
|
||||
|
||||
if (paramTypeId == shellySwitchSettingsButtonTypeParamTypeId) {
|
||||
QVariantMap inputConfig;
|
||||
if (value == "toggle" || value == "edge") {
|
||||
inputConfig.insert("type", "switch");
|
||||
} else {
|
||||
inputConfig.insert("type", "button");
|
||||
}
|
||||
params["config"] = inputConfig;
|
||||
client->sendRequest("Input.SetConfig", params);
|
||||
|
||||
QVariantMap switchConfig;
|
||||
switchConfig.insert("in_mode", value.toString().replace("toggle", "follow").replace("edge", "flip"));
|
||||
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();
|
||||
|
||||
|
|
@ -1438,8 +1469,8 @@ void IntegrationPluginShelly::setupShellyChild(ThingSetupInfo *info)
|
|||
url.setHost(address);
|
||||
url.setPort(80);
|
||||
url.setPath(QString("/settings/relay/%0").arg(thing->paramValue(channelParamTypeMap.value(thing->thingClassId())).toInt() - 1));
|
||||
url.setUserName(parentDevice->paramValue(usernameParamTypeMap.value(parentDevice->thingClassId())).toString());
|
||||
url.setPassword(parentDevice->paramValue(passwordParamTypeMap.value(parentDevice->thingClassId())).toString());
|
||||
url.setUserName(parent->paramValue(usernameParamTypeMap.value(parent->thingClassId())).toString());
|
||||
url.setPassword(parent->paramValue(passwordParamTypeMap.value(parent->thingClassId())).toString());
|
||||
|
||||
QUrlQuery query;
|
||||
if (paramTypeId == shellySwitchSettingsButtonTypeParamTypeId) {
|
||||
|
|
@ -1455,6 +1486,10 @@ void IntegrationPluginShelly::setupShellyChild(ThingSetupInfo *info)
|
|||
|
||||
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();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ ShellyRpcReply *ShellyJsonRpcClient::sendRequest(const QString &method, const QV
|
|||
});
|
||||
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));
|
||||
|
||||
return reply;
|
||||
|
|
|
|||
Loading…
Reference in New Issue