Merge pull request #9725 from effelle/development

New topic for MQTT switches
This commit is contained in:
Theo Arends 2020-11-03 14:22:11 +01:00 committed by GitHub
commit dfd6080d96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -432,23 +432,18 @@ void SwitchHandler(uint8_t mode)
} }
} }
void MqttSwitchTopic(uint8_t switch_id, uint8_t MqttAction) void MqttSwitchTopic(uint32_t switch_id, uint32_t MqttAction) {
{ if (!Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistantautomatic discovery (See SetOption59)
char scommand[CMDSZ]; char mqttstate_str[16];
char stopic[TOPSZ]; char *mqttstate = mqttstate_str;
char mqttstate[16];
if (!Settings.flag.hass_discovery) {
if (MqttAction <= 3) { if (MqttAction <= 3) {
if (MqttAction != 3) { SendKey(KEY_SWITCH, switch_id, MqttAction); } if (MqttAction != 3) { SendKey(KEY_SWITCH, switch_id, MqttAction); }
snprintf_P(mqttstate, sizeof(mqttstate), PSTR("%s"), SettingsText(SET_STATE_TXT1 + MqttAction)); mqttstate = SettingsText(SET_STATE_TXT1 + MqttAction);
} else { } else {
GetTextIndexed(mqttstate, sizeof(mqttstate), MqttAction, kSwitchPressStates); GetTextIndexed(mqttstate_str, sizeof(mqttstate_str), MqttAction, kSwitchPressStates);
} }
snprintf_P(scommand, sizeof(scommand), PSTR("SWITCH%d"), switch_id); Response_P(PSTR("{\"%s\":{\"Action\":\"%s\"}}"), GetSwitchText(switch_id -1).c_str(), mqttstate);
GetTopic_P(stopic, STAT, TasmotaGlobal.mqtt_topic, scommand); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_SWITCH));
Response_P(S_JSON_COMMAND_SVALUE, "ACTION", mqttstate);
MqttPublish(stopic);
} }
} }