unify command components
This commit is contained in:
parent
08ff0ba367
commit
7412029272
26
include/ha.h
26
include/ha.h
@ -64,30 +64,12 @@ namespace Ha {
|
||||
}
|
||||
};
|
||||
|
||||
void buildRestartConfig(char(&output)[JSON_SIZE], const char* topic) {
|
||||
void buildCommandConfig(char(&output)[JSON_SIZE], const char* name, const char* uniqueId, const char* commandTopic) {
|
||||
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
||||
buildDeviceConfig(jsonDoc);
|
||||
jsonDoc["name"] = "Restart";
|
||||
jsonDoc["unique_id"] = "esp_clock_restart";
|
||||
jsonDoc["command_topic"] = topic;
|
||||
serializeJson(jsonDoc, output);
|
||||
}
|
||||
|
||||
void buildLedConfig(char(&output)[JSON_SIZE], const char* topic) {
|
||||
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
||||
buildDeviceConfig(jsonDoc);
|
||||
jsonDoc["name"] = "ESP Clock Led";
|
||||
jsonDoc["unique_id"] = "esp_clock_led";
|
||||
jsonDoc["command_topic"] = topic;
|
||||
serializeJson(jsonDoc, output);
|
||||
}
|
||||
|
||||
void buildHourFormatConfig(char(&output)[JSON_SIZE], const char* topic) {
|
||||
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
||||
buildDeviceConfig(jsonDoc);
|
||||
jsonDoc["name"] = "ESP Clock Format 24h";
|
||||
jsonDoc["unique_id"] = "esp_clock_format_24h";
|
||||
jsonDoc["command_topic"] = topic;
|
||||
jsonDoc["name"] = name;
|
||||
jsonDoc["unique_id"] = uniqueId;
|
||||
jsonDoc["command_topic"] = commandTopic;
|
||||
serializeJson(jsonDoc, output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,19 +69,19 @@ namespace Mqtt {
|
||||
|
||||
void publishRestartConfig() {
|
||||
char message[JSON_SIZE];
|
||||
Ha::buildRestartConfig(message, restartTopic);
|
||||
Ha::buildCommandConfig(message, "Restart", "esp_clock_restart", restartTopic);
|
||||
client.publish("homeassistant/button/esp_clock/restart/config", 0, true, message);
|
||||
}
|
||||
|
||||
void publishLedConfig() {
|
||||
char message[JSON_SIZE];
|
||||
Ha::buildLedConfig(message, ledTopic);
|
||||
Ha::buildCommandConfig(message, "ESP Clock Led", "esp_clock_led", ledTopic);
|
||||
client.publish("homeassistant/switch/esp_clock/led/config", 0, true, message);
|
||||
}
|
||||
|
||||
void publishHourFormatConfig() {
|
||||
char message[JSON_SIZE];
|
||||
Ha::buildHourFormatConfig(message, hourFormatTopic);
|
||||
Ha::buildCommandConfig(message, "ESP Clock Format 24h", "esp_clock_format_24h", hourFormatTopic);
|
||||
client.publish("homeassistant/switch/esp_clock/hour_format/config", 0, true, message);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user