Merge PR #128: Tasmota: Use new powerswitch interface

This commit is contained in:
Jenkins 2019-09-02 18:02:05 +02:00
commit df91880f5b
2 changed files with 21 additions and 2 deletions

View File

@ -213,6 +213,10 @@ Device::DeviceError DevicePluginTasmota::executeAction(Device *device, const Act
if (m_powerStateTypeMap.contains(device->deviceClassId())) { if (m_powerStateTypeMap.contains(device->deviceClassId())) {
Device *parentDev = myDevices().findById(device->parentId()); Device *parentDev = myDevices().findById(device->parentId());
MqttChannel *channel = m_mqttChannels.value(parentDev); MqttChannel *channel = m_mqttChannels.value(parentDev);
if (!channel) {
qCWarning(dcTasmota()) << "No mqtt channel for this device.";
return Device::DeviceErrorHardwareNotAvailable;
}
ParamTypeId channelParamTypeId = m_channelParamTypeMap.value(device->deviceClassId()); ParamTypeId channelParamTypeId = m_channelParamTypeMap.value(device->deviceClassId());
ParamTypeId powerActionParamTypeId = ParamTypeId(m_powerStateTypeMap.value(device->deviceClassId()).toString()); ParamTypeId powerActionParamTypeId = ParamTypeId(m_powerStateTypeMap.value(device->deviceClassId()).toString());
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString() << (action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF"); qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString() << (action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF");
@ -223,6 +227,10 @@ Device::DeviceError DevicePluginTasmota::executeAction(Device *device, const Act
if (device->deviceClassId() == tasmotaShutterDeviceClassId) { if (device->deviceClassId() == tasmotaShutterDeviceClassId) {
Device *parentDev = myDevices().findById(device->parentId()); Device *parentDev = myDevices().findById(device->parentId());
MqttChannel *channel = m_mqttChannels.value(parentDev); MqttChannel *channel = m_mqttChannels.value(parentDev);
if (!channel) {
qCWarning(dcTasmota()) << "No mqtt channel for this device.";
return Device::DeviceErrorHardwareNotAvailable;
}
ParamTypeId openingChannelParamTypeId = m_openingChannelParamTypeMap.value(device->deviceClassId()); ParamTypeId openingChannelParamTypeId = m_openingChannelParamTypeMap.value(device->deviceClassId());
ParamTypeId closingChannelParamTypeId = m_closingChannelParamTypeMap.value(device->deviceClassId()); ParamTypeId closingChannelParamTypeId = m_closingChannelParamTypeMap.value(device->deviceClassId());
if (action.actionTypeId() == tasmotaShutterOpenActionTypeId) { if (action.actionTypeId() == tasmotaShutterOpenActionTypeId) {
@ -291,6 +299,10 @@ void DevicePluginTasmota::onPublishReceived(MqttChannel *channel, const QString
if (m_powerStateTypeMap.contains(child->deviceClassId())) { if (m_powerStateTypeMap.contains(child->deviceClassId())) {
child->setStateValue(m_powerStateTypeMap.value(child->deviceClassId()), payload == "ON"); child->setStateValue(m_powerStateTypeMap.value(child->deviceClassId()), payload == "ON");
} }
if (child->deviceClassId() == tasmotaSwitchDeviceClassId) {
Event event(tasmotaSwitchPressedEventTypeId, child->id());
emit emitEvent(event);
}
} }
} }
if (topic.startsWith(channel->topicPrefix() + "/sonoff/STATE")) { if (topic.startsWith(channel->topicPrefix() + "/sonoff/STATE")) {

View File

@ -5,7 +5,7 @@
"vendors": [ "vendors": [
{ {
"name": "tasmota", "name": "tasmota",
"displayName": "Sonoff-Tasmota", "displayName": "Tasmota",
"id": "789e6173-3de3-44ef-8664-9492c9d15d44", "id": "789e6173-3de3-44ef-8664-9492c9d15d44",
"deviceClasses": [ "deviceClasses": [
{ {
@ -147,7 +147,7 @@
"name": "tasmotaSwitch", "name": "tasmotaSwitch",
"displayName": "Tasmota power switch", "displayName": "Tasmota power switch",
"createMethods": ["auto"], "createMethods": ["auto"],
"interfaces": ["power", "connectable"], "interfaces": ["powerswitch", "connectable"],
"paramTypes": [ "paramTypes": [
{ {
"id": "564cf6c6-86eb-41a5-9b87-fb32f1b6fcd6", "id": "564cf6c6-86eb-41a5-9b87-fb32f1b6fcd6",
@ -176,6 +176,13 @@
"defaultValue": false, "defaultValue": false,
"writable": true "writable": true
} }
],
"eventTypes": [
{
"id": "1be4d6a1-475e-43bb-a47c-9063e279e78d",
"name": "pressed",
"displayName": "Pressed"
}
] ]
}, },
{ {