Merge PR #416: Tasmota: Add support for the Sonoff Dimmer
This commit is contained in:
commit
e22b71c664
@ -44,6 +44,9 @@
|
||||
static QHash<QString, StateTypeId> sonoff_basicPowerStateTypeIds = {
|
||||
{"POWER1", sonoff_basicPowerStateTypeId},
|
||||
};
|
||||
static QHash<QString, StateTypeId> sonoff_dimmerPowerStateTypeIds = {
|
||||
{"POWER1", sonoff_dimmerPowerStateTypeId},
|
||||
};
|
||||
static QHash<QString, StateTypeId> sonoff_dualPowerStateTypeIds = {
|
||||
{"POWER1", sonoff_dualPowerCH1StateTypeId},
|
||||
{"POWER2", sonoff_dualPowerCH2StateTypeId},
|
||||
@ -64,6 +67,7 @@ static QHash<ThingClassId, QHash<QString, StateTypeId>> stateMaps = {
|
||||
{sonoff_dualThingClassId, sonoff_dualPowerStateTypeIds},
|
||||
{sonoff_triThingClassId, sonoff_triPowerStateTypeIds},
|
||||
{sonoff_quadThingClassId, sonoff_quadPowerStateTypeIds},
|
||||
{sonoff_dimmerThingClassId, sonoff_dimmerPowerStateTypeIds}
|
||||
};
|
||||
|
||||
IntegrationPluginTasmota::IntegrationPluginTasmota()
|
||||
@ -73,6 +77,7 @@ IntegrationPluginTasmota::IntegrationPluginTasmota()
|
||||
m_ipAddressParamTypeMap[sonoff_dualThingClassId] = sonoff_dualThingIpAddressParamTypeId;
|
||||
m_ipAddressParamTypeMap[sonoff_triThingClassId] = sonoff_triThingIpAddressParamTypeId;
|
||||
m_ipAddressParamTypeMap[sonoff_quadThingClassId] = sonoff_quadThingIpAddressParamTypeId;
|
||||
m_ipAddressParamTypeMap[sonoff_dimmerThingClassId] = sonoff_dimmerThingIpAddressParamTypeId;
|
||||
|
||||
m_attachedDeviceParamTypeIdMap[sonoff_basicThingClassId] << sonoff_basicThingAttachedDeviceCH1ParamTypeId;
|
||||
m_attachedDeviceParamTypeIdMap[sonoff_dualThingClassId] << sonoff_dualThingAttachedDeviceCH1ParamTypeId << sonoff_dualThingAttachedDeviceCH2ParamTypeId;
|
||||
@ -103,6 +108,7 @@ IntegrationPluginTasmota::IntegrationPluginTasmota()
|
||||
m_connectedStateTypeMap[sonoff_dualThingClassId] = sonoff_dualConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[sonoff_triThingClassId] = sonoff_triConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[sonoff_quadThingClassId] = sonoff_quadConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[sonoff_dimmerThingClassId] = sonoff_dimmerConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[tasmotaSwitchThingClassId] = tasmotaSwitchConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[tasmotaLightThingClassId] = tasmotaLightConnectedStateTypeId;
|
||||
m_connectedStateTypeMap[tasmotaShutterThingClassId] = tasmotaShutterConnectedStateTypeId;
|
||||
@ -112,10 +118,13 @@ IntegrationPluginTasmota::IntegrationPluginTasmota()
|
||||
m_signalStrengthStateTypeMap[sonoff_dualThingClassId] = sonoff_dualSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[sonoff_triThingClassId] = sonoff_triSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[sonoff_quadThingClassId] = sonoff_quadSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[sonoff_dimmerThingClassId] = sonoff_dimmerSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[tasmotaSwitchThingClassId] = tasmotaSwitchSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[tasmotaLightThingClassId] = tasmotaLightSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[tasmotaShutterThingClassId] = tasmotaShutterSignalStrengthStateTypeId;
|
||||
m_signalStrengthStateTypeMap[tasmotaBlindsThingClassId] = tasmotaBlindsSignalStrengthStateTypeId;
|
||||
|
||||
m_brightnessStateTypeMap[sonoff_dimmerThingClassId] = sonoff_dimmerBrightnessStateTypeId;
|
||||
}
|
||||
|
||||
IntegrationPluginTasmota::~IntegrationPluginTasmota()
|
||||
@ -285,7 +294,8 @@ void IntegrationPluginTasmota::executeAction(ThingActionInfo *info)
|
||||
if (thing->thingClassId() == sonoff_basicThingClassId
|
||||
|| thing->thingClassId() == sonoff_dualThingClassId
|
||||
|| thing->thingClassId() == sonoff_triThingClassId
|
||||
|| thing->thingClassId() == sonoff_quadThingClassId) {
|
||||
|| thing->thingClassId() == sonoff_quadThingClassId
|
||||
|| action.actionTypeId() == sonoff_dimmerPowerActionTypeId) {
|
||||
MqttChannel *channel = m_mqttChannels.value(thing);
|
||||
if (!channel) {
|
||||
qCWarning(dcTasmota()) << "No MQTT channel for this thing.";
|
||||
@ -293,8 +303,24 @@ void IntegrationPluginTasmota::executeAction(ThingActionInfo *info)
|
||||
return;
|
||||
}
|
||||
QString channelName = stateMaps.value(thing->thingClassId()).key(action.actionTypeId());
|
||||
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefixList().first() + "/sonoff/cmnd/" + channelName << (action.paramValue(action.actionTypeId()).toBool() ? "ON" : "OFF");
|
||||
channel->publish(channel->topicPrefixList().first() + "/sonoff/cmnd/" + channelName, action.paramValue(action.actionTypeId()).toBool() ? "ON" : "OFF");
|
||||
QByteArray payload = action.paramValue(action.actionTypeId()).toBool() ? "ON" : "OFF";
|
||||
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefixList().first() + "/sonoff/cmnd/" + channelName << payload;
|
||||
channel->publish(channel->topicPrefixList().first() + "/sonoff/cmnd/" + channelName, payload);
|
||||
thing->setStateValue(action.actionTypeId(), action.paramValue(action.actionTypeId()));
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
if (action.actionTypeId() == sonoff_dimmerBrightnessActionTypeId) {
|
||||
MqttChannel *channel = m_mqttChannels.value(thing);
|
||||
if (!channel) {
|
||||
qCWarning(dcTasmota()) << "No MQTT channel for this thing:" << thing->name();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||
return;
|
||||
}
|
||||
QString channelName = stateMaps.value(thing->thingClassId()).key(action.actionTypeId());
|
||||
QByteArray payload = QByteArray::number(action.paramValue(action.actionTypeId()).toInt());
|
||||
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefixList().first() + "/sonoff/cmnd/DIMMER1" + channelName << payload;
|
||||
channel->publish(channel->topicPrefixList().first() + "/sonoff/cmnd/DIMMER1" + channelName, payload);
|
||||
thing->setStateValue(action.actionTypeId(), action.paramValue(action.actionTypeId()));
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
@ -404,6 +430,10 @@ void IntegrationPluginTasmota::onPublishReceived(MqttChannel *channel, const QSt
|
||||
QVariantMap dataMap = jsonDoc.toVariant().toMap();
|
||||
thing->setStateValue(m_signalStrengthStateTypeMap.value(thing->thingClassId()), dataMap.value("Wifi").toMap().value("RSSI").toInt());
|
||||
|
||||
if (m_brightnessStateTypeMap.contains(thing->thingClassId())) {
|
||||
thing->setStateValue(m_brightnessStateTypeMap.value(thing->thingClassId()), dataMap.value("Dimmer").toInt());
|
||||
}
|
||||
|
||||
// Legacy (deprecated) connected things by params
|
||||
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
||||
if (m_powerStateTypeMap.contains(child->thingClassId())) {
|
||||
|
||||
@ -77,6 +77,8 @@ private:
|
||||
// Helpers for both devices
|
||||
QHash<ThingClassId, StateTypeId> m_connectedStateTypeMap;
|
||||
QHash<ThingClassId, StateTypeId> m_signalStrengthStateTypeMap;
|
||||
|
||||
QHash<ThingClassId, StateTypeId> m_brightnessStateTypeMap;
|
||||
};
|
||||
|
||||
#endif // INTEGRATIONPLUGINTASMOTA_H
|
||||
|
||||
@ -346,6 +346,65 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "4fb65caa-7f84-4496-91f6-1cd35574cc2e",
|
||||
"name": "sonoff_dimmer",
|
||||
"displayName": "Dimmer (Sonoff D1...)",
|
||||
"createMethods": ["user"],
|
||||
"interfaces": [ "dimmablelight", "wirelessconnectable" ],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "935a5a79-900a-4943-a9e2-5de228d66758",
|
||||
"name":"ipAddress",
|
||||
"displayName": "IP address",
|
||||
"type": "QString"
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "1078dd25-b5bd-4005-8c1f-005ddca7ea21",
|
||||
"name": "connected",
|
||||
"displayName": "Connected",
|
||||
"displayNameEvent": "Connected changed",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "662d99de-bfce-4cf0-8029-108e9911866c",
|
||||
"name": "signalStrength",
|
||||
"displayName": "Signal strength",
|
||||
"displayNameEvent": "Signal strength changed",
|
||||
"type": "uint",
|
||||
"unit": "Percentage",
|
||||
"minValue": 0,
|
||||
"maxValue": 100,
|
||||
"defaultValue": -1
|
||||
},
|
||||
{
|
||||
"id": "c8ec62d4-024b-4770-b893-6288b64f0dfe",
|
||||
"name": "power",
|
||||
"displayName": "Power",
|
||||
"displayNameEvent": "Power changed",
|
||||
"displayNameAction": "Set power",
|
||||
"type": "bool",
|
||||
"writable": true,
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "5cd8d0df-1188-4da1-9a87-bff991d3b2af",
|
||||
"name": "brightness",
|
||||
"displayName": "Brightness",
|
||||
"displayNameEvent": "Brightness changed",
|
||||
"displayNameAction": "Set brightness",
|
||||
"type": "int",
|
||||
"minValue": 0,
|
||||
"maxValue": 100,
|
||||
"defaultValue": 50,
|
||||
"writable": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "8a5e69c0-14ad-4ae8-9ff9-10055de6ffdf",
|
||||
"name": "tasmotaSwitch",
|
||||
|
||||
@ -33,7 +33,9 @@
|
||||
</message>
|
||||
<message>
|
||||
<source>IP address</source>
|
||||
<extracomment>The name of the ParamType (ThingClass: sonoff_quad, Type: thing, ID: {dbc3f3b3-2d17-40e9-8f6e-dde0b26952bc})
|
||||
<extracomment>The name of the ParamType (ThingClass: sonoff_dimmer, Type: thing, ID: {935a5a79-900a-4943-a9e2-5de228d66758})
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_quad, Type: thing, ID: {dbc3f3b3-2d17-40e9-8f6e-dde0b26952bc})
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_tri, Type: thing, ID: {b7532005-4157-4687-952f-ac3cd6b7f606})
|
||||
----------
|
||||
@ -57,6 +59,8 @@ The name of the EventType ({72050de9-c318-4e53-93e5-36f7c2fc7cab}) of ThingClass
|
||||
----------
|
||||
The name of the EventType ({b4607e5d-70c4-4e76-9d9a-c6de7c50377e}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the EventType ({1078dd25-b5bd-4005-8c1f-005ddca7ea21}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the EventType ({5b422d28-9f60-4ea9-ab23-42a0ec605b9e}) of ThingClass sonoff_quad
|
||||
----------
|
||||
The name of the EventType ({e6439ea4-4373-4ac1-a790-748604cf2830}) of ThingClass sonoff_tri
|
||||
@ -84,6 +88,10 @@ The name of the ParamType (ThingClass: tasmotaSwitch, EventType: connected, ID:
|
||||
----------
|
||||
The name of the StateType ({b4607e5d-70c4-4e76-9d9a-c6de7c50377e}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_dimmer, EventType: connected, ID: {1078dd25-b5bd-4005-8c1f-005ddca7ea21})
|
||||
----------
|
||||
The name of the StateType ({1078dd25-b5bd-4005-8c1f-005ddca7ea21}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_quad, EventType: connected, ID: {5b422d28-9f60-4ea9-ab23-42a0ec605b9e})
|
||||
----------
|
||||
The name of the StateType ({5b422d28-9f60-4ea9-ab23-42a0ec605b9e}) of ThingClass sonoff_quad
|
||||
@ -159,6 +167,8 @@ The name of the ParamType (ThingClass: tasmotaSwitch, Type: thing, ID: {564cf6c6
|
||||
----------
|
||||
The name of the EventType ({413503d7-fc9f-417a-95fa-5c350a6f69f9}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the EventType ({c8ec62d4-024b-4770-b893-6288b64f0dfe}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the EventType ({0b5a48c9-73b8-42ab-9909-71b8dc2227e3}) of ThingClass sonoff_basic</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@ -176,6 +186,12 @@ The name of the ParamType (ThingClass: tasmotaSwitch, EventType: power, ID: {413
|
||||
----------
|
||||
The name of the StateType ({413503d7-fc9f-417a-95fa-5c350a6f69f9}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_dimmer, ActionType: power, ID: {c8ec62d4-024b-4770-b893-6288b64f0dfe})
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_dimmer, EventType: power, ID: {c8ec62d4-024b-4770-b893-6288b64f0dfe})
|
||||
----------
|
||||
The name of the StateType ({c8ec62d4-024b-4770-b893-6288b64f0dfe}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_basic, ActionType: power, ID: {0b5a48c9-73b8-42ab-9909-71b8dc2227e3})
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_basic, EventType: power, ID: {0b5a48c9-73b8-42ab-9909-71b8dc2227e3})
|
||||
@ -189,6 +205,8 @@ The name of the StateType ({0b5a48c9-73b8-42ab-9909-71b8dc2227e3}) of ThingClass
|
||||
----------
|
||||
The name of the ActionType ({413503d7-fc9f-417a-95fa-5c350a6f69f9}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the ActionType ({c8ec62d4-024b-4770-b893-6288b64f0dfe}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the ActionType ({0b5a48c9-73b8-42ab-9909-71b8dc2227e3}) of ThingClass sonoff_basic</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
@ -275,6 +293,10 @@ The name of the ParamType (ThingClass: tasmotaSwitch, EventType: signalStrength,
|
||||
----------
|
||||
The name of the StateType ({34e54234-d2d6-4c93-8d52-bada19e5ff23}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_dimmer, EventType: signalStrength, ID: {662d99de-bfce-4cf0-8029-108e9911866c})
|
||||
----------
|
||||
The name of the StateType ({662d99de-bfce-4cf0-8029-108e9911866c}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_quad, EventType: signalStrength, ID: {d80d8f37-f3c0-4364-998b-312339fd1fa8})
|
||||
----------
|
||||
The name of the StateType ({d80d8f37-f3c0-4364-998b-312339fd1fa8}) of ThingClass sonoff_quad
|
||||
@ -302,6 +324,8 @@ The name of the EventType ({dcc39f5e-6bcb-4c04-910e-8dd5f9ad5402}) of ThingClass
|
||||
----------
|
||||
The name of the EventType ({34e54234-d2d6-4c93-8d52-bada19e5ff23}) of ThingClass tasmotaSwitch
|
||||
----------
|
||||
The name of the EventType ({662d99de-bfce-4cf0-8029-108e9911866c}) of ThingClass sonoff_dimmer
|
||||
----------
|
||||
The name of the EventType ({d80d8f37-f3c0-4364-998b-312339fd1fa8}) of ThingClass sonoff_quad
|
||||
----------
|
||||
The name of the EventType ({08b4ec84-1aec-4e68-a3b4-ae251b8cbe6d}) of ThingClass sonoff_tri
|
||||
@ -437,5 +461,29 @@ The name of the ActionType ({156f285d-e474-43d9-9a9d-17b3bcaef893}) of ThingClas
|
||||
<extracomment>The name of the ActionType ({4060baa0-2b11-4905-908c-b6f1c3b6a892}) of ThingClass sonoff_quad</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Brightness</source>
|
||||
<extracomment>The name of the ParamType (ThingClass: sonoff_dimmer, ActionType: brightness, ID: {5cd8d0df-1188-4da1-9a87-bff991d3b2af})
|
||||
----------
|
||||
The name of the ParamType (ThingClass: sonoff_dimmer, EventType: brightness, ID: {5cd8d0df-1188-4da1-9a87-bff991d3b2af})
|
||||
----------
|
||||
The name of the StateType ({5cd8d0df-1188-4da1-9a87-bff991d3b2af}) of ThingClass sonoff_dimmer</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Brightness changed</source>
|
||||
<extracomment>The name of the EventType ({5cd8d0df-1188-4da1-9a87-bff991d3b2af}) of ThingClass sonoff_dimmer</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Dimmer (Sonoff D1...)</source>
|
||||
<extracomment>The name of the ThingClass ({4fb65caa-7f84-4496-91f6-1cd35574cc2e})</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Set brightness</source>
|
||||
<extracomment>The name of the ActionType ({5cd8d0df-1188-4da1-9a87-bff991d3b2af}) of ThingClass sonoff_dimmer</extracomment>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user