Fixed publish_current_state()

This commit is contained in:
2021-01-18 05:53:11 +01:00
parent e9143b6ca8
commit 5676b5d63c
5 changed files with 39 additions and 14 deletions

View File

@@ -106,12 +106,30 @@ void State::publish_current_state() {
StaticJsonDocument<512> json;
json["state"] = (mode==AM_OFF) ? "OFF" : "ON";
json["brightness"] = FastLED.getBrightness();
json["effect"] = mode;
json["effect"] = animation_mode_names[get_active_mode()];
JsonObject rgb = json.createNestedObject("rgb");
rgb["r"] = color.r;
rgb["g"] = color.g;
rgb["b"] = color.b;
String result = "";
serializeJson(json, result);
LOGln("Reporting current state: %s", result.c_str());
mqtt_publish_current_state(result);
}
AnimationMode State::get_active_mode() {
AnimationMode active_mode = mode;
if (temp_mode_until > 0) {
if (temp_mode_until>millis()) {
active_mode = temp_mode;
} else {
temp_mode_until = 0;
if (return_to_brightness != -1) {
FastLED.setBrightness(return_to_brightness);
return_to_brightness = -1;
}
State::publish_current_state();
}
}
return active_mode;
}