Skip to content

Commit

Permalink
IRMQTTServer V1.6.1 (#1740)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
crankyoldgit authored Jan 20, 2022
1 parent 91a528e commit ccb8542
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/IRMQTTServer/IRMQTTServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const uint16_t kJsonAcStateMaxSize = 1024; // Bytes
// ----------------- End of User Configuration Section -------------------------

// Constants
#define _MY_VERSION_ "v1.6.0"
#define _MY_VERSION_ "v1.6.1"

const uint8_t kRebootTime = 15; // Seconds
const uint8_t kQuickDisplayTime = 2; // Seconds
Expand Down
9 changes: 6 additions & 3 deletions examples/IRMQTTServer/IRMQTTServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,8 @@ bool sendInt(const String topic, const int32_t num, const bool retain) {
bool sendBool(const String topic, const bool on, const bool retain) {
#if MQTT_ENABLE
mqttSentCounter++;
return mqtt_client.publish(topic.c_str(), (on ? "on" : "off"), retain);
return mqtt_client.publish(topic.c_str(), (on ? D_STR_ON : D_STR_OFF),
retain);
#else // MQTT_ENABLE
return true;
#endif // MQTT_ENABLE
Expand Down Expand Up @@ -2991,12 +2992,14 @@ void updateClimate(stdAc::state_t *state, const String str,
} else if (str.equals(prefix + F(KEY_POWER))) {
state->power = IRac::strToBool(payload.c_str());
#if MQTT_CLIMATE_HA_MODE
// When in Home Assistant mode, Power Off, means turn the Mode to Off too.
if (!state->power) state->mode = stdAc::opmode_t::kOff;
#endif // MQTT_CLIMATE_HA_MODE
} else if (str.equals(prefix + F(KEY_MODE))) {
state->mode = IRac::strToOpmode(payload.c_str());
#if MQTT_CLIMATE_HA_MODE
state->power = (state->mode != stdAc::opmode_t::kOff);
// When in Home Assistant mode, a Mode of Off, means turn the Power off too.
if (state->mode == stdAc::opmode_t::kOff) state->power = false;
#endif // MQTT_CLIMATE_HA_MODE
} else if (str.equals(prefix + F(KEY_TEMP))) {
state->degrees = payload.toFloat();
Expand Down Expand Up @@ -3055,7 +3058,7 @@ bool sendClimate(const String topic_prefix, const bool retain,
// Home Assistant want's these two bound together.
if (prev.power != next.power || prev.mode != next.mode || forceMQTT) {
success &= sendBool(topic_prefix + KEY_POWER, next.power, retain);
if (!next.power) mode_str = F("off");
if (!next.power) mode_str = kOffStr;
#else // MQTT_CLIMATE_HA_MODE
// In non-Home Assistant mode, power and mode are not bound together.
if (prev.power != next.power || forceMQTT) {
Expand Down

0 comments on commit ccb8542

Please sign in to comment.