Merge PR #606: MyStrom: Fix discovery for Swiss plugs

master
jenkins 2022-09-26 17:40:09 +02:00
commit fc4024cf14
1 changed files with 8 additions and 2 deletions

View File

@ -44,6 +44,12 @@
// API doc:
// https://api.mystrom.ch/
QList<int> supportedPlugs {
101, // Switch CH v1
106, // Switch CH v2
107 // Switch EU
};
IntegrationPluginMyStrom::IntegrationPluginMyStrom()
{
}
@ -93,7 +99,7 @@ void IntegrationPluginMyStrom::discoverThings(ThingDiscoveryInfo *info)
qCDebug(dcMyStrom) << "Info response:" << qUtf8Printable(jsonDoc.toJson());
QVariantMap deviceInfo = jsonDoc.toVariant().toMap();
if (deviceInfo.value("type").toInt() == 107) {
if (supportedPlugs.contains(deviceInfo.value("type").toInt())) {
ThingDescriptor descriptor(switchThingClassId, entry.name(), entry.hostAddress().toString());
descriptor.setParams({Param(switchThingIdParamTypeId, entry.txt("id"))});
info->addThingDescriptor(descriptor);
@ -135,7 +141,7 @@ void IntegrationPluginMyStrom::setupThing(ThingSetupInfo *info)
qCDebug(dcMyStrom()) << "Device info:" << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented));
QVariantMap deviceInfo = jsonDoc.toVariant().toMap();
if (deviceInfo.value("type").toInt() != 107) {
if (!supportedPlugs.contains(deviceInfo.value("type").toInt())) {
qCWarning(dcMyStrom()) << "This device does not seem to be a myStrom WiFi switch";
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("This device does not seem to be a myStrom WiFi switch."));
return;