Merge branch 'development' of https://github.com/arendst/Sonoff-Tasmota into development

This commit is contained in:
localhost61 2019-03-21 19:48:13 +01:00
commit 42c7eba189
2 changed files with 16 additions and 18 deletions

View File

@ -615,6 +615,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
if (Settings.flag3.hass_tele_on_power) { if (Settings.flag3.hass_tele_on_power) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
} }
#ifdef USE_HOME_ASSISTANT
if (Settings.flag.hass_discovery) {
HAssPublishStatus();
}
#endif // USE_HOME_ASSISTANT
} }
else if (CMND_SLEEP == command_code) { else if (CMND_SLEEP == command_code) {
if ((payload >= 0) && (payload < 251)) { if ((payload >= 0) && (payload < 251)) {
@ -1547,11 +1552,7 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source)
#ifdef USE_KNX #ifdef USE_KNX
KnxUpdatePowerState(device, power); KnxUpdatePowerState(device, power);
#endif // USE_KNX #endif // USE_KNX
if (publish_power && Settings.flag3.hass_tele_on_power) { if (publish_power && Settings.flag3.hass_tele_on_power) { MqttPublishTeleState(); }
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On
SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0); SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0);
} }
@ -1778,6 +1779,13 @@ void MqttShowState(void)
mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount(), WifiDowntime().c_str()); mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WifiLinkCount(), WifiDowntime().c_str());
} }
void MqttPublishTeleState(void)
{
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
bool MqttShowSensor(void) bool MqttShowSensor(void)
{ {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str()); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_JSON_TIME "\":\"%s\""), mqtt_data, GetDateAndTime(DT_LOCAL).c_str());
@ -1855,9 +1863,7 @@ void PerformEverySecond(void)
if (tele_period >= Settings.tele_period) { if (tele_period >= Settings.tele_period) {
tele_period = 0; tele_period = 0;
mqtt_data[0] = '\0'; MqttPublishTeleState();
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
if (MqttShowSensor()) { if (MqttShowSensor()) {

View File

@ -793,11 +793,7 @@ void LightPreparePower(void)
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
DomoticzUpdatePowerState(light_device); DomoticzUpdatePowerState(light_device);
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
if (Settings.flag3.hass_tele_on_power) { if (Settings.flag3.hass_tele_on_power) { MqttPublishTeleState(); }
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
LightState(0); LightState(0);
} }
@ -1456,11 +1452,7 @@ bool LightCommand(void)
LightPowerOn(); LightPowerOn();
strip_timer_counter = 0; strip_timer_counter = 0;
// Publish state message for Hass // Publish state message for Hass
if (Settings.flag3.hass_tele_on_power) { if (Settings.flag3.hass_tele_on_power) { MqttPublishTeleState(); }
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.light_scheme); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.light_scheme);
} }