moved sendState before webSocketEvent

This commit is contained in:
Deb 2018-03-12 22:53:40 -04:00 committed by GitHub
parent 69a22006c8
commit d7c0113110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,6 +259,32 @@ void getModesJSON() {
server.send ( 200, "application/json", listModesJSON() );
}
#ifdef ENABLE_HOMEASSISTANT
/********************************** START SEND STATE*****************************************/
void sendState() {
StaticJsonBuffer<JSON_OBJECT_SIZE(10)> 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<JSON_OBJECT_SIZE(10)> 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) {