moving shelly i3 to switches

This commit is contained in:
Herb Paar 2021-01-25 22:40:09 +01:00
parent 6608a3ecb6
commit 7c71b48284
2 changed files with 41 additions and 39 deletions

View File

@ -69,7 +69,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_idParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingIdParamTypeId; m_idParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingIdParamTypeId;
m_idParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingIdParamTypeId; m_idParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingIdParamTypeId;
m_idParamTypeMap[shellyHTThingClassId] = shellyHTThingIdParamTypeId; m_idParamTypeMap[shellyHTThingClassId] = shellyHTThingIdParamTypeId;
m_idParamTypeMap[shellyix3ThingClassId] = shellyix3ThingIdParamTypeId; m_idParamTypeMap[shellyI3ThingClassId] = shellyI3ThingIdParamTypeId;
m_usernameParamTypeMap[shelly1ThingClassId] = shelly1ThingUsernameParamTypeId; m_usernameParamTypeMap[shelly1ThingClassId] = shelly1ThingUsernameParamTypeId;
m_usernameParamTypeMap[shelly1pmThingClassId] = shelly1pmThingUsernameParamTypeId; m_usernameParamTypeMap[shelly1pmThingClassId] = shelly1pmThingUsernameParamTypeId;
@ -82,7 +82,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_usernameParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingUsernameParamTypeId; m_usernameParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingUsernameParamTypeId;
m_usernameParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingUsernameParamTypeId; m_usernameParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingUsernameParamTypeId;
m_usernameParamTypeMap[shellyHTThingClassId] = shellyHTThingUsernameParamTypeId; m_usernameParamTypeMap[shellyHTThingClassId] = shellyHTThingUsernameParamTypeId;
m_usernameParamTypeMap[shellyix3ThingClassId] = shellyix3ThingUsernameParamTypeId; m_usernameParamTypeMap[shellyI3ThingClassId] = shellyI3ThingUsernameParamTypeId;
m_passwordParamTypeMap[shelly1ThingClassId] = shelly1ThingPasswordParamTypeId; m_passwordParamTypeMap[shelly1ThingClassId] = shelly1ThingPasswordParamTypeId;
m_passwordParamTypeMap[shelly1pmThingClassId] = shelly1pmThingPasswordParamTypeId; m_passwordParamTypeMap[shelly1pmThingClassId] = shelly1pmThingPasswordParamTypeId;
@ -95,7 +95,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_passwordParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingPasswordParamTypeId; m_passwordParamTypeMap[shellyButton1ThingClassId] = shellyButton1ThingPasswordParamTypeId;
m_passwordParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingPasswordParamTypeId; m_passwordParamTypeMap[shellyEm3ThingClassId] = shellyEm3ThingPasswordParamTypeId;
m_passwordParamTypeMap[shellyHTThingClassId] = shellyHTThingPasswordParamTypeId; m_passwordParamTypeMap[shellyHTThingClassId] = shellyHTThingPasswordParamTypeId;
m_passwordParamTypeMap[shellyix3ThingClassId] = shellyix3ThingPasswordParamTypeId; m_passwordParamTypeMap[shellyI3ThingClassId] = shellyI3ThingPasswordParamTypeId;
m_connectedDeviceParamTypeMap[shelly2ThingClassId] = shelly2ThingConnectedDevice1ParamTypeId; m_connectedDeviceParamTypeMap[shelly2ThingClassId] = shelly2ThingConnectedDevice1ParamTypeId;
m_connectedDeviceParamTypeMap[shelly25ThingClassId] = shelly25ThingConnectedDevice1ParamTypeId; m_connectedDeviceParamTypeMap[shelly25ThingClassId] = shelly25ThingConnectedDevice1ParamTypeId;
@ -131,7 +131,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_connectedStateTypesMap[shellyLightPMThingClassId] = shellyLightPMConnectedStateTypeId; m_connectedStateTypesMap[shellyLightPMThingClassId] = shellyLightPMConnectedStateTypeId;
m_connectedStateTypesMap[shellySocketPMThingClassId] = shellySocketPMConnectedStateTypeId; m_connectedStateTypesMap[shellySocketPMThingClassId] = shellySocketPMConnectedStateTypeId;
m_connectedStateTypesMap[shellyRollerThingClassId] = shellyRollerConnectedStateTypeId; m_connectedStateTypesMap[shellyRollerThingClassId] = shellyRollerConnectedStateTypeId;
m_connectedStateTypesMap[shellyix3ThingClassId] = shellyix3ConnectedStateTypeId; m_connectedStateTypesMap[shellyI3ThingClassId] = shellyI3ConnectedStateTypeId;
m_signalStrengthStateTypesMap[shelly1ThingClassId] = shelly1SignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shelly1ThingClassId] = shelly1SignalStrengthStateTypeId;
m_signalStrengthStateTypesMap[shelly1pmThingClassId] = shelly1pmSignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shelly1pmThingClassId] = shelly1pmSignalStrengthStateTypeId;
@ -152,7 +152,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_signalStrengthStateTypesMap[shellyLightPMThingClassId] = shellyLightPMSignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shellyLightPMThingClassId] = shellyLightPMSignalStrengthStateTypeId;
m_signalStrengthStateTypesMap[shellySocketPMThingClassId] = shellySocketPMSignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shellySocketPMThingClassId] = shellySocketPMSignalStrengthStateTypeId;
m_signalStrengthStateTypesMap[shellyRollerThingClassId] = shellyRollerSignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shellyRollerThingClassId] = shellyRollerSignalStrengthStateTypeId;
m_signalStrengthStateTypesMap[shellyix3ThingClassId] = shellyix3SignalStrengthStateTypeId; m_signalStrengthStateTypesMap[shellyI3ThingClassId] = shellyI3SignalStrengthStateTypeId;
m_powerStateTypeMap[shelly1ThingClassId] = shelly1PowerStateTypeId; m_powerStateTypeMap[shelly1ThingClassId] = shelly1PowerStateTypeId;
m_powerStateTypeMap[shelly1pmThingClassId] = shelly1pmPowerStateTypeId; m_powerStateTypeMap[shelly1pmThingClassId] = shelly1pmPowerStateTypeId;
@ -203,7 +203,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_updateStatusStateTypesMap[shellyButton1ThingClassId] = shellyButton1UpdateStatusStateTypeId; m_updateStatusStateTypesMap[shellyButton1ThingClassId] = shellyButton1UpdateStatusStateTypeId;
m_updateStatusStateTypesMap[shellyEm3ThingClassId] = shellyEm3UpdateStatusStateTypeId; m_updateStatusStateTypesMap[shellyEm3ThingClassId] = shellyEm3UpdateStatusStateTypeId;
m_updateStatusStateTypesMap[shellyHTThingClassId] = shellyHTUpdateStatusStateTypeId; m_updateStatusStateTypesMap[shellyHTThingClassId] = shellyHTUpdateStatusStateTypeId;
m_updateStatusStateTypesMap[shellyix3ThingClassId] = shellyix3UpdateStatusStateTypeId; m_updateStatusStateTypesMap[shellyI3ThingClassId] = shellyI3UpdateStatusStateTypeId;
m_currentVersionStateTypesMap[shelly1ThingClassId] = shelly1CurrentVersionStateTypeId; m_currentVersionStateTypesMap[shelly1ThingClassId] = shelly1CurrentVersionStateTypeId;
m_currentVersionStateTypesMap[shelly1pmThingClassId] = shelly1pmCurrentVersionStateTypeId; m_currentVersionStateTypesMap[shelly1pmThingClassId] = shelly1pmCurrentVersionStateTypeId;
@ -216,7 +216,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_currentVersionStateTypesMap[shellyButton1ThingClassId] = shellyButton1CurrentVersionStateTypeId; m_currentVersionStateTypesMap[shellyButton1ThingClassId] = shellyButton1CurrentVersionStateTypeId;
m_currentVersionStateTypesMap[shellyEm3ThingClassId] = shellyEm3CurrentVersionStateTypeId; m_currentVersionStateTypesMap[shellyEm3ThingClassId] = shellyEm3CurrentVersionStateTypeId;
m_currentVersionStateTypesMap[shellyHTThingClassId] = shellyHTCurrentVersionStateTypeId; m_currentVersionStateTypesMap[shellyHTThingClassId] = shellyHTCurrentVersionStateTypeId;
m_currentVersionStateTypesMap[shellyix3ThingClassId] = shellyix3CurrentVersionStateTypeId; m_currentVersionStateTypesMap[shellyI3ThingClassId] = shellyI3CurrentVersionStateTypeId;
m_availableVersionStateTypesMap[shelly1ThingClassId] = shelly1AvailableVersionStateTypeId; m_availableVersionStateTypesMap[shelly1ThingClassId] = shelly1AvailableVersionStateTypeId;
m_availableVersionStateTypesMap[shelly1pmThingClassId] = shelly1pmAvailableVersionStateTypeId; m_availableVersionStateTypesMap[shelly1pmThingClassId] = shelly1pmAvailableVersionStateTypeId;
@ -229,7 +229,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_availableVersionStateTypesMap[shellyButton1ThingClassId] = shellyButton1AvailableVersionStateTypeId; m_availableVersionStateTypesMap[shellyButton1ThingClassId] = shellyButton1AvailableVersionStateTypeId;
m_availableVersionStateTypesMap[shellyEm3ThingClassId] = shellyEm3AvailableVersionStateTypeId; m_availableVersionStateTypesMap[shellyEm3ThingClassId] = shellyEm3AvailableVersionStateTypeId;
m_availableVersionStateTypesMap[shellyHTThingClassId] = shellyHTAvailableVersionStateTypeId; m_availableVersionStateTypesMap[shellyHTThingClassId] = shellyHTAvailableVersionStateTypeId;
m_availableVersionStateTypesMap[shellyix3ThingClassId] = shellyix3AvailableVersionStateTypeId; m_availableVersionStateTypesMap[shellyI3ThingClassId] = shellyI3AvailableVersionStateTypeId;
m_batteryLevelStateTypeMap[shellyButton1ThingClassId] = shellyButton1BatteryLevelStateTypeId; m_batteryLevelStateTypeMap[shellyButton1ThingClassId] = shellyButton1BatteryLevelStateTypeId;
m_batteryLevelStateTypeMap[shellyHTThingClassId] = shellyHTBatteryLevelStateTypeId; m_batteryLevelStateTypeMap[shellyHTThingClassId] = shellyHTBatteryLevelStateTypeId;
@ -246,7 +246,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_rebootActionTypeMap[shellyDimmerRebootActionTypeId] = shellyDimmerThingClassId; m_rebootActionTypeMap[shellyDimmerRebootActionTypeId] = shellyDimmerThingClassId;
m_rebootActionTypeMap[shelly2RebootActionTypeId] = shelly2ThingClassId; m_rebootActionTypeMap[shelly2RebootActionTypeId] = shelly2ThingClassId;
m_rebootActionTypeMap[shelly25RebootActionTypeId] = shelly25ThingClassId; m_rebootActionTypeMap[shelly25RebootActionTypeId] = shelly25ThingClassId;
m_rebootActionTypeMap[shellyix3RebootActionTypeId] = shellyix3ThingClassId; m_rebootActionTypeMap[shellyI3RebootActionTypeId] = shellyI3ThingClassId;
m_powerActionTypesMap[shelly1PowerActionTypeId] = shelly1ThingClassId; m_powerActionTypesMap[shelly1PowerActionTypeId] = shelly1ThingClassId;
m_powerActionTypesMap[shelly1pmPowerActionTypeId] = shelly1pmThingClassId; m_powerActionTypesMap[shelly1pmPowerActionTypeId] = shelly1pmThingClassId;
@ -305,7 +305,7 @@ IntegrationPluginShelly::IntegrationPluginShelly()
m_updateActionTypesMap[shellyButton1PerformUpdateActionTypeId] = shellyButton1ThingClassId; m_updateActionTypesMap[shellyButton1PerformUpdateActionTypeId] = shellyButton1ThingClassId;
m_updateActionTypesMap[shellyEm3PerformUpdateActionTypeId] = shellyEm3ThingClassId; m_updateActionTypesMap[shellyEm3PerformUpdateActionTypeId] = shellyEm3ThingClassId;
m_updateActionTypesMap[shellyHTPerformUpdateActionTypeId] = shellyHTThingClassId; m_updateActionTypesMap[shellyHTPerformUpdateActionTypeId] = shellyHTThingClassId;
m_updateActionTypesMap[shellyix3PerformUpdateActionTypeId] = shellyix3ThingClassId; m_updateActionTypesMap[shellyI3PerformUpdateActionTypeId] = shellyI3ThingClassId;
} }
IntegrationPluginShelly::~IntegrationPluginShelly() IntegrationPluginShelly::~IntegrationPluginShelly()
@ -344,7 +344,7 @@ void IntegrationPluginShelly::discoverThings(ThingDiscoveryInfo *info)
namePattern = QRegExp("^shellyem3-[0-9A-Z]+$"); namePattern = QRegExp("^shellyem3-[0-9A-Z]+$");
} else if (info->thingClassId() == shellyHTThingClassId) { } else if (info->thingClassId() == shellyHTThingClassId) {
namePattern = QRegExp("shellyht-[0-9A-Z]+$"); namePattern = QRegExp("shellyht-[0-9A-Z]+$");
} else if (info->thingClassId() == shellyix3ThingClassId) { } else if (info->thingClassId() == shellyI3ThingClassId) {
namePattern = QRegExp("shellyix3-[0-9A-Z]+$"); namePattern = QRegExp("shellyix3-[0-9A-Z]+$");
} }
if (!entry.name().contains(namePattern)) { if (!entry.name().contains(namePattern)) {
@ -671,6 +671,10 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
// "1" or "0" // "1" or "0"
// Emit event button pressed // Emit event button pressed
bool on = payload == "1"; bool on = payload == "1";
if (thing->thingClassId() == shellyI3ThingClassId) {
thing->emitEvent(shellyI3PressEventTypeId, ParamList() << Param(shellyI3PressEventOriginParamTypeId, QString::number(channel +1)));
return;
}
foreach (Thing *child, myThings().filterByParentId(thing->id())) { foreach (Thing *child, myThings().filterByParentId(thing->id())) {
if (child->thingClassId() == shellySwitchThingClassId && child->paramValue(shellySwitchThingChannelParamTypeId).toInt() == channel + 1) { if (child->thingClassId() == shellySwitchThingClassId && child->paramValue(shellySwitchThingChannelParamTypeId).toInt() == channel + 1) {
if (child->stateValue(shellySwitchPowerStateTypeId).toBool() != on) { if (child->stateValue(shellySwitchPowerStateTypeId).toBool() != on) {
@ -692,7 +696,6 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
if (m_powerStateTypeMap.contains(thing->thingClassId())) { if (m_powerStateTypeMap.contains(thing->thingClassId())) {
thing->setStateValue(m_powerStateTypeMap.value(thing->thingClassId()), on); thing->setStateValue(m_powerStateTypeMap.value(thing->thingClassId()), on);
} }
// And switch all childs of this shelly too // And switch all childs of this shelly too
foreach (Thing *child, myThings().filterByParentId(thing->id())) { foreach (Thing *child, myThings().filterByParentId(thing->id())) {
if (m_powerStateTypeMap.contains(child->thingClassId())) { if (m_powerStateTypeMap.contains(child->thingClassId())) {
@ -829,9 +832,9 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
} }
} }
if (topic == "shellies/" + shellyId + "/input_event/") { if (topic.startsWith("shellies/" + shellyId + "/input_event/")) {
int channel = topic.split("/").last().toInt(); int channel = topic.split("/").last().toInt();
if (thing->thingClassId() == shellyButton1ThingClassId) { // it can be onlz at channel 0 if (thing->thingClassId() == shellyButton1ThingClassId) { // it can be only at channel 0
QJsonParseError error; QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(payload, &error); QJsonDocument jsonDoc = QJsonDocument::fromJson(payload, &error);
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
@ -847,7 +850,7 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
QString param = QString::number(event.length()); QString param = QString::number(event.length());
thing->emitEvent(eventTypeId, ParamList() << Param(paramTypeId, param)); thing->emitEvent(eventTypeId, ParamList() << Param(paramTypeId, param));
} }
if (thing->thingClassId() == shellyix3ThingClassId) { if (thing->thingClassId() == shellyI3ThingClassId) {
QJsonParseError error; QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(payload, &error); QJsonDocument jsonDoc = QJsonDocument::fromJson(payload, &error);
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
@ -859,9 +862,9 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
return; return;
} }
QString param = ""; QString param = "";
EventTypeId eventTypeId = shellyix3LongPressedEventTypeId;; EventTypeId eventTypeId = shellyI3LongPressedEventTypeId;;
ParamTypeId paramTypeId = shellyix3LongPressedEventButtonNameParamTypeId; ParamTypeId paramTypeId = shellyI3LongPressedEventButtonNameParamTypeId;
ParamTypeId param2TypeId = shellyix3LongPressedEventPressOriginParamTypeId; ParamTypeId param2TypeId = shellyI3LongPressedEventPressOriginParamTypeId;
if (event == "L") { if (event == "L") {
param = "1"; param = "1";
} else if (event == "SL") { } else if (event == "SL") {
@ -870,9 +873,9 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
param = "3"; param = "3";
} else { // short press } else { // short press
param = QString::number(event.length()); param = QString::number(event.length());
eventTypeId = shellyix3PressedEventTypeId; eventTypeId = shellyI3PressedEventTypeId;
paramTypeId = shellyix3PressedEventButtonNameParamTypeId; paramTypeId = shellyI3PressedEventButtonNameParamTypeId;
param2TypeId = shellyix3PressedEventPressOriginParamTypeId; param2TypeId = shellyI3PressedEventPressOriginParamTypeId;
} }
QString usedSwitch = QString::number(channel + 1); QString usedSwitch = QString::number(channel + 1);
thing->emitEvent(eventTypeId, ParamList() << Param(paramTypeId, param) << Param(param2TypeId, usedSwitch)); thing->emitEvent(eventTypeId, ParamList() << Param(paramTypeId, param) << Param(param2TypeId, usedSwitch));
@ -1109,21 +1112,6 @@ void IntegrationPluginShelly::setupShellyGateway(ThingSetupInfo *info)
autoChilds.append(switch2Child); autoChilds.append(switch2Child);
} }
// Create 3 switches for shelly ix3
if (info->thing()->thingClassId() == shellyix3ThingClassId ) {
ThingDescriptor switchChild(shellySwitchThingClassId, info->thing()->name() + " switch 1", QString(), info->thing()->id());
switchChild.setParams(ParamList() << Param(shellySwitchThingChannelParamTypeId, 1));
autoChilds.append(switchChild);
ThingDescriptor switch2Child(shellySwitchThingClassId, info->thing()->name() + " switch 2", QString(), info->thing()->id());
switch2Child.setParams(ParamList() << Param(shellySwitchThingChannelParamTypeId, 2));
autoChilds.append(switch2Child);
ThingDescriptor switch3Child(shellySwitchThingClassId, info->thing()->name() + " switch 3", QString(), info->thing()->id());
switch3Child.setParams(ParamList() << Param(shellySwitchThingChannelParamTypeId, 3));
autoChilds.append(switch3Child);
}
// Add connected devices as configured in params // Add connected devices as configured in params
// No PM devices for shelly 1 and 2 // No PM devices for shelly 1 and 2
if (info->thing()->thingClassId() == shelly1ThingClassId if (info->thing()->thingClassId() == shelly1ThingClassId

View File

@ -1100,8 +1100,8 @@
}, },
{ {
"id": "a4557bcc-bdae-4178-b774-5881a8ae490a", "id": "a4557bcc-bdae-4178-b774-5881a8ae490a",
"name": "shellyix3", "name": "shellyI3",
"displayName": "Shelly i3", "displayName": "Shelly I3",
"createMethods": ["discovery"], "createMethods": ["discovery"],
"interfaces": [ "longpressmultibutton", "wirelessconnectable", "update" ], "interfaces": [ "longpressmultibutton", "wirelessconnectable", "update" ],
"paramTypes": [ "paramTypes": [
@ -1200,10 +1200,24 @@
} }
], ],
"eventTypes": [ "eventTypes": [
{
"id": "724d18ff-693b-4a9c-aa72-66557e0069d6",
"name": "press",
"displayName": "Press",
"paramTypes": [
{
"id": "ee2e1728-dfb3-4c0b-a131-0b7798415b2c",
"name": "origin",
"displayName": "Switch",
"type": "QString",
"allowedValues": ["1", "2", "3"]
}
]
},
{ {
"id": "79648810-b2f4-4aa5-902f-2875242e7bf8", "id": "79648810-b2f4-4aa5-902f-2875242e7bf8",
"name": "pressed", "name": "pressed",
"displayName": "Pressed", "displayName": "Short Pressed",
"paramTypes": [ "paramTypes": [
{ {
"id": "146313a1-cfb6-4732-a1be-86ec575bcbdb", "id": "146313a1-cfb6-4732-a1be-86ec575bcbdb",