feat(F-040,F-041,F-042): relay.set_config, output numbering fix, clock batch commands
Enforce 1-based output numbering throughout the entire stack. Stored values, MQTT wire format, and console UI are all 1-based; the single 0-based conversion happens only in OutputManager::getPhysicalOutput(). Fixed createDefaultBellConfig (was setting identity 0-based map instead of 0=disabled), updateBellDurations and updateBellOutputs (support both v2 0/1 and v1 b1/b2 keys), all call sites that bypassed getPhysicalOutput, and fireClockOutput conversion. New commands: - relay.set_config: combined durations + outputs in one round trip (F-040) - clock.set_config: enabled/c1/c2/pulse_duration/pause_duration in one call (F-042) - clock.set_alerts_config: alert type, bells, and silence windows in one call (F-042) Feature catalog updated with F-040, F-041, F-042 detail sections. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ RelayHandler::RelayHandler(ConfigManager& configManager, OutputManager& outputMa
|
||||
|
||||
std::vector<String> RelayHandler::commands() const {
|
||||
return {
|
||||
"relay.set_durations", "relay.set_outputs", "relay.get_config",
|
||||
"relay.set_durations", "relay.set_outputs", "relay.set_config", "relay.get_config",
|
||||
"relay.test_output", "relay.test_bell", "relay.test_batch"
|
||||
};
|
||||
}
|
||||
@@ -19,6 +19,7 @@ std::vector<String> RelayHandler::commands() const {
|
||||
CommandResult RelayHandler::execute(const CommandEnvelope& envelope) {
|
||||
if (envelope.command == "relay.set_durations") return handleSetDurations(envelope);
|
||||
if (envelope.command == "relay.set_outputs") return handleSetOutputs(envelope);
|
||||
if (envelope.command == "relay.set_config") return handleSetConfig(envelope);
|
||||
if (envelope.command == "relay.get_config") return handleGetConfig(envelope);
|
||||
if (envelope.command == "relay.test_output") return handleTestOutput(envelope);
|
||||
if (envelope.command == "relay.test_bell") return handleTestBell(envelope);
|
||||
@@ -56,6 +57,34 @@ CommandResult RelayHandler::handleSetOutputs(const CommandEnvelope& e) {
|
||||
return CommandResult::ok("relay.set_outputs", "Bell outputs updated and saved");
|
||||
}
|
||||
|
||||
CommandResult RelayHandler::handleSetConfig(const CommandEnvelope& e) {
|
||||
JsonVariant contents = const_cast<JsonDocument&>(e.contents).as<JsonVariant>();
|
||||
|
||||
bool hasDurations = contents["durations"].is<JsonObject>();
|
||||
bool hasOutputs = contents["outputs"].is<JsonObject>();
|
||||
|
||||
if (!hasDurations && !hasOutputs) {
|
||||
return CommandResult::err("relay.set_config", "Provide 'durations' and/or 'outputs' objects");
|
||||
}
|
||||
|
||||
if (hasDurations) {
|
||||
_configManager.updateBellDurations(contents["durations"].as<JsonVariant>());
|
||||
if (!_configManager.saveBellDurations()) {
|
||||
return CommandResult::err("relay.set_config", "Durations applied but failed to save to SD");
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOutputs) {
|
||||
_configManager.updateBellOutputs(contents["outputs"].as<JsonVariant>());
|
||||
if (!_configManager.saveBellOutputs()) {
|
||||
return CommandResult::err("relay.set_config", "Outputs applied but failed to save to SD");
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO(TAG, "relay.config applied (durations=%d outputs=%d)", hasDurations, hasOutputs);
|
||||
return CommandResult::ok("relay.set_config", "Bell configuration updated and saved");
|
||||
}
|
||||
|
||||
CommandResult RelayHandler::handleGetConfig(const CommandEnvelope& e) {
|
||||
JsonDocument doc;
|
||||
JsonObject durations = doc["durations"].to<JsonObject>();
|
||||
@@ -104,15 +133,19 @@ CommandResult RelayHandler::handleTestBell(const CommandEnvelope& e) {
|
||||
return CommandResult::err("relay.test_bell", "bell must be 0-15");
|
||||
}
|
||||
|
||||
uint8_t output = (uint8_t)_configManager.getBellOutput(bell);
|
||||
uint8_t output = _outputManager.getPhysicalOutput((uint8_t)bell);
|
||||
uint16_t durationMs = _configManager.getBellDuration(bell);
|
||||
|
||||
if (output == 255) {
|
||||
return CommandResult::err("relay.test_bell", "Bell " + String(bell) + " is disabled or unconfigured");
|
||||
}
|
||||
|
||||
_outputManager.fireOutputForDuration(output, durationMs);
|
||||
LOG_INFO(TAG, "Test bell %d → output %d for %d ms", bell, output, durationMs);
|
||||
LOG_INFO(TAG, "Test bell %d → chip pin %d for %d ms", bell, output, durationMs);
|
||||
|
||||
JsonDocument doc;
|
||||
doc["bell"] = bell;
|
||||
doc["output"] = output;
|
||||
doc["output"] = output + 1; // 1-based for human readability
|
||||
doc["duration_ms"] = durationMs;
|
||||
return CommandResult::ok("relay.test_bell", doc);
|
||||
}
|
||||
@@ -134,8 +167,9 @@ CommandResult RelayHandler::handleTestBatch(const CommandEnvelope& e) {
|
||||
if (!v.is<int>()) continue;
|
||||
int bell = v.as<int>();
|
||||
if (bell < 0 || bell > 15) continue;
|
||||
uint8_t output = (uint8_t)_configManager.getBellOutput((uint8_t)bell);
|
||||
uint8_t output = _outputManager.getPhysicalOutput((uint8_t)bell);
|
||||
uint16_t durationMs = _configManager.getBellDuration((uint8_t)bell);
|
||||
if (output == 255) continue; // disabled/unconfigured — skip silently
|
||||
_outputManager.fireOutputForDuration(output, durationMs);
|
||||
fired++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user