diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 591b6c4..2e077bb 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -259,6 +259,32 @@ void getModesJSON() { server.send ( 200, "application/json", listModesJSON() ); } +#ifdef ENABLE_HOMEASSISTANT +/********************************** START SEND STATE*****************************************/ +void sendState() { + StaticJsonBuffer jsonBuffer; + + JsonObject& root = jsonBuffer.createObject(); + + root["state"] = (stateOn) ? on_cmd : off_cmd; + JsonObject& color = root.createNestedObject("color"); + color["r"] = main_color.red; + color["g"] = main_color.green; + color["b"] = main_color.blue; + + root["brightness"] = brightness; + + char modeName[30]; + strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem + root["effect"] = modeName; + + + char buffer[root.measureLength() + 1]; + root.printTo(buffer, sizeof(buffer)); + + mqtt_client.publish(mqtt_ha_state_out.c_str(), buffer, true); +} +#endif // *************************************************************************** // HTTP request handlers @@ -593,31 +619,6 @@ void checkForRequests() { return true; } - - /********************************** START SEND STATE*****************************************/ - void sendState() { - StaticJsonBuffer jsonBuffer; - - JsonObject& root = jsonBuffer.createObject(); - - root["state"] = (stateOn) ? on_cmd : off_cmd; - JsonObject& color = root.createNestedObject("color"); - color["r"] = main_color.red; - color["g"] = main_color.green; - color["b"] = main_color.blue; - - root["brightness"] = brightness; - - char modeName[30]; - strncpy_P(modeName, (PGM_P)strip.getModeName(strip.getMode()), sizeof(modeName)); // copy from progmem - root["effect"] = modeName; - - - char buffer[root.measureLength() + 1]; - root.printTo(buffer, sizeof(buffer)); - - mqtt_client.publish(mqtt_ha_state_out.c_str(), buffer, true); - } #endif void mqtt_callback(char* topic, byte* payload_in, unsigned int length) {