New topic for MQTT Switches

This commit is contained in:
Federico Leoni 2020-11-03 10:09:23 -03:00
parent 1e640b0a09
commit e74fdee05e

View File

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