fix(ClockHandler): backlight key mismatch, bell get_config conversion, timezone in get_config

- updateClockBacklight: fix key names to match wire format
  (backlight/backlight_output/backlight_on/backlight_off instead of enabled/output/onTime/offTime)
- handleGetConfig: convert stored 0-based bell indices back to 1-based for hour_bell/half_bell/quarter_bell
  (255 disabled sentinel passed through unchanged)
- handleGetConfig: include gmt_offset_sec, dst_offset_sec, ntp_server from TimeConfig
  so clock.get_config supersedes clock.get_timezone

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-12 19:37:31 +03:00
co-authored by Claude Sonnet 4.6
parent 0ac63e82ed
commit eb440a9888
2 changed files with 18 additions and 17 deletions
@@ -238,9 +238,10 @@ CommandResult ClockHandler::handleGetConfig(const CommandEnvelope& e) {
doc["last_sync_time"] = cc.lastSyncTime; doc["last_sync_time"] = cc.lastSyncTime;
doc["alert_type"] = cc.alertType; doc["alert_type"] = cc.alertType;
doc["alert_interval"] = cc.alertRingInterval; doc["alert_interval"] = cc.alertRingInterval;
doc["hour_bell"] = cc.hourBell; // Stored 0-based internally; report 1-based to match API convention (255 = disabled, unchanged)
doc["half_bell"] = cc.halfBell; doc["hour_bell"] = (cc.hourBell == 255) ? 255 : cc.hourBell + 1;
doc["quarter_bell"] = cc.quarterBell; doc["half_bell"] = (cc.halfBell == 255) ? 255 : cc.halfBell + 1;
doc["quarter_bell"] = (cc.quarterBell == 255) ? 255 : cc.quarterBell + 1;
doc["backlight"] = cc.backlight; doc["backlight"] = cc.backlight;
doc["backlight_output"] = cc.backlightOutput; doc["backlight_output"] = cc.backlightOutput;
doc["backlight_on"] = cc.backlightOnTime; doc["backlight_on"] = cc.backlightOnTime;
@@ -251,6 +252,10 @@ CommandResult ClockHandler::handleGetConfig(const CommandEnvelope& e) {
doc["night_silence"] = cc.nighttimeSilenceEnabled; doc["night_silence"] = cc.nighttimeSilenceEnabled;
doc["night_on"] = cc.nighttimeSilenceOnTime; doc["night_on"] = cc.nighttimeSilenceOnTime;
doc["night_off"] = cc.nighttimeSilenceOffTime; doc["night_off"] = cc.nighttimeSilenceOffTime;
const auto& tc = _configManager.getTimeConfig();
doc["gmt_offset_sec"] = tc.gmtOffsetSec;
doc["dst_offset_sec"] = tc.daylightOffsetSec;
doc["ntp_server"] = tc.ntpServer;
return CommandResult::ok("clock.get_config", doc); return CommandResult::ok("clock.get_config", doc);
} }
@@ -295,12 +300,8 @@ CommandResult ClockHandler::handleSetConfig(const CommandEnvelope& e) {
} }
if (hasEnabled) _configManager.setClockEnabled(c["enabled"].as<bool>()); if (hasEnabled) _configManager.setClockEnabled(c["enabled"].as<bool>());
if (hasC1 || hasC2) { if (hasC1) _configManager.setClockOutput1(c["c1"].as<uint8_t>());
JsonDocument tmp; if (hasC2) _configManager.setClockOutput2(c["c2"].as<uint8_t>());
if (hasC1) tmp["c1output"] = c["c1"].as<int>();
if (hasC2) tmp["c2output"] = c["c2"].as<int>();
_configManager.updateClockOutputs(tmp.as<JsonVariant>());
}
if (hasPulseDuration) _configManager.setClockPulseDuration(c["pulse_duration"].as<uint16_t>()); if (hasPulseDuration) _configManager.setClockPulseDuration(c["pulse_duration"].as<uint16_t>());
if (hasPauseDuration) _configManager.setClockPauseDuration(c["pause_duration"].as<uint16_t>()); if (hasPauseDuration) _configManager.setClockPauseDuration(c["pause_duration"].as<uint16_t>());
+8 -8
View File
@@ -633,17 +633,17 @@ void ConfigManager::updateClockAlerts(JsonVariant doc) {
} }
void ConfigManager::updateClockBacklight(JsonVariant doc) { void ConfigManager::updateClockBacklight(JsonVariant doc) {
if (doc.containsKey("enabled")) { if (doc.containsKey("backlight")) {
clockConfig.backlight = doc["enabled"].as<bool>(); clockConfig.backlight = doc["backlight"].as<bool>();
} }
if (doc.containsKey("output")) { if (doc.containsKey("backlight_output")) {
clockConfig.backlightOutput = doc["output"].as<uint8_t>(); clockConfig.backlightOutput = doc["backlight_output"].as<uint8_t>();
} }
if (doc.containsKey("onTime")) { if (doc.containsKey("backlight_on")) {
clockConfig.backlightOnTime = doc["onTime"].as<String>(); clockConfig.backlightOnTime = doc["backlight_on"].as<String>();
} }
if (doc.containsKey("offTime")) { if (doc.containsKey("backlight_off")) {
clockConfig.backlightOffTime = doc["offTime"].as<String>(); clockConfig.backlightOffTime = doc["backlight_off"].as<String>();
} }
LOG_DEBUG(TAG, "ConfigManager - Updated Clock backlight"); LOG_DEBUG(TAG, "ConfigManager - Updated Clock backlight");
} }