configure 24h format over MQTT
This commit is contained in:
parent
6711b58f20
commit
ea8c9a150c
@ -21,12 +21,13 @@ namespace Display {
|
|||||||
uint8_t brightness = BRIGHTNESS_NIGHT;
|
uint8_t brightness = BRIGHTNESS_NIGHT;
|
||||||
int currentHour = -1;
|
int currentHour = -1;
|
||||||
int currentMin = -1;
|
int currentMin = -1;
|
||||||
|
bool hourFormat24 = false;
|
||||||
|
|
||||||
// Create display object
|
// Create display object
|
||||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||||
|
|
||||||
void drawTime() {
|
void drawTime() {
|
||||||
int displayHour = hourFormat12();
|
int displayHour = hourFormat24 ? hour() : hourFormat12();
|
||||||
int displayMinute = minute();
|
int displayMinute = minute();
|
||||||
int displayValue = displayHour * 100 + displayMinute;
|
int displayValue = displayHour * 100 + displayMinute;
|
||||||
|
|
||||||
|
|||||||
@ -85,4 +85,13 @@ namespace Ha {
|
|||||||
jsonDoc["command_topic"] = topic;
|
jsonDoc["command_topic"] = topic;
|
||||||
serializeJson(jsonDoc, output);
|
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;
|
||||||
|
serializeJson(jsonDoc, output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,7 @@ namespace Mqtt {
|
|||||||
const char* bmpTopic = "homeassistant/sensor/esp_clock/state";
|
const char* bmpTopic = "homeassistant/sensor/esp_clock/state";
|
||||||
const char* restartTopic = "homeassistant/button/esp_clock/restart";
|
const char* restartTopic = "homeassistant/button/esp_clock/restart";
|
||||||
const char* ledTopic = "homeassistant/switch/esp_clock/led/set";
|
const char* ledTopic = "homeassistant/switch/esp_clock/led/set";
|
||||||
|
const char* hourFormatTopic = "homeassistant/switch/esp_clock/hour_format/set";
|
||||||
const char* espClockTopic = "homeassistant/+/esp_clock/#";
|
const char* espClockTopic = "homeassistant/+/esp_clock/#";
|
||||||
|
|
||||||
void connect() {
|
void connect() {
|
||||||
@ -78,12 +79,19 @@ namespace Mqtt {
|
|||||||
client.publish("homeassistant/switch/esp_clock/led/config", 0, true, message);
|
client.publish("homeassistant/switch/esp_clock/led/config", 0, true, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishHourFormatConfig() {
|
||||||
|
char message[JSON_SIZE];
|
||||||
|
Ha::buildHourFormatConfig(message, hourFormatTopic);
|
||||||
|
client.publish("homeassistant/switch/esp_clock/hour_format/config", 0, true, message);
|
||||||
|
}
|
||||||
|
|
||||||
void publishConfig() {
|
void publishConfig() {
|
||||||
publishTempConfig();
|
publishTempConfig();
|
||||||
publishPressureConfig();
|
publishPressureConfig();
|
||||||
publishAltitudeConfig();
|
publishAltitudeConfig();
|
||||||
publishRestartConfig();
|
publishRestartConfig();
|
||||||
publishLedConfig();
|
publishLedConfig();
|
||||||
|
publishHourFormatConfig();
|
||||||
ts.deleteTask(tPublishConfig);
|
ts.deleteTask(tPublishConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +132,15 @@ namespace Mqtt {
|
|||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (String{ hourFormatTopic }.equals(topic)) {
|
||||||
|
if (String{ "ON" }.equals(msg)) {
|
||||||
|
Display::hourFormat24 = true;
|
||||||
|
Display::drawTime();
|
||||||
|
} else {
|
||||||
|
Display::hourFormat24 = false;
|
||||||
|
Display::drawTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user