Skip to content

Commit ccb8542

Browse files
authored
IRMQTTServer V1.6.1 (#1740)
- Fix the case when `MQTT_CLIMATE_HA_MODE` is enabled & Home Assistant is NOT being used, and `power` is turned off via the http interface, that it also sets the `mode` to Off, and viceversa. Mode "Off" also sets Power "Off". - Move some literal strings to constants for consistency. - Helps with potential internationalisation. - Bump version patch number. Ref #1729 Fixes #1739
1 parent 91a528e commit ccb8542

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

examples/IRMQTTServer/IRMQTTServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ const uint16_t kJsonAcStateMaxSize = 1024; // Bytes
285285
// ----------------- End of User Configuration Section -------------------------
286286

287287
// Constants
288-
#define _MY_VERSION_ "v1.6.0"
288+
#define _MY_VERSION_ "v1.6.1"
289289

290290
const uint8_t kRebootTime = 15; // Seconds
291291
const uint8_t kQuickDisplayTime = 2; // Seconds

examples/IRMQTTServer/IRMQTTServer.ino

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,8 @@ bool sendInt(const String topic, const int32_t num, const bool retain) {
28632863
bool sendBool(const String topic, const bool on, const bool retain) {
28642864
#if MQTT_ENABLE
28652865
mqttSentCounter++;
2866-
return mqtt_client.publish(topic.c_str(), (on ? "on" : "off"), retain);
2866+
return mqtt_client.publish(topic.c_str(), (on ? D_STR_ON : D_STR_OFF),
2867+
retain);
28672868
#else // MQTT_ENABLE
28682869
return true;
28692870
#endif // MQTT_ENABLE
@@ -2991,12 +2992,14 @@ void updateClimate(stdAc::state_t *state, const String str,
29912992
} else if (str.equals(prefix + F(KEY_POWER))) {
29922993
state->power = IRac::strToBool(payload.c_str());
29932994
#if MQTT_CLIMATE_HA_MODE
2995+
// When in Home Assistant mode, Power Off, means turn the Mode to Off too.
29942996
if (!state->power) state->mode = stdAc::opmode_t::kOff;
29952997
#endif // MQTT_CLIMATE_HA_MODE
29962998
} else if (str.equals(prefix + F(KEY_MODE))) {
29972999
state->mode = IRac::strToOpmode(payload.c_str());
29983000
#if MQTT_CLIMATE_HA_MODE
2999-
state->power = (state->mode != stdAc::opmode_t::kOff);
3001+
// When in Home Assistant mode, a Mode of Off, means turn the Power off too.
3002+
if (state->mode == stdAc::opmode_t::kOff) state->power = false;
30003003
#endif // MQTT_CLIMATE_HA_MODE
30013004
} else if (str.equals(prefix + F(KEY_TEMP))) {
30023005
state->degrees = payload.toFloat();
@@ -3055,7 +3058,7 @@ bool sendClimate(const String topic_prefix, const bool retain,
30553058
// Home Assistant want's these two bound together.
30563059
if (prev.power != next.power || prev.mode != next.mode || forceMQTT) {
30573060
success &= sendBool(topic_prefix + KEY_POWER, next.power, retain);
3058-
if (!next.power) mode_str = F("off");
3061+
if (!next.power) mode_str = kOffStr;
30593062
#else // MQTT_CLIMATE_HA_MODE
30603063
// In non-Home Assistant mode, power and mode are not bound together.
30613064
if (prev.power != next.power || forceMQTT) {

0 commit comments

Comments
 (0)