feat(comms): Stage 2 — all 10 domain handlers implemented
Adds the complete set of v2 command handlers. Old CommandHandler is
untouched — handlers are standalone and not yet wired to anything.
Handlers added:
PlaybackHandler — playback (1 dependency)
LoggingHandler — log.set_serial/sd/mqtt
FileHandler — files.list/list_builtin/download/delete
TelemetryHandler — telemetry.get_strikes/reset_strikes/get_loads
RelayHandler — relay.set_durations/set_outputs/get_config/test_output
FirmwareHandler — firmware.status/commit/rollback + ota.update/custom
NetworkHandler — network.info/status/set_config
MQTTHandler — mqtt.enable/disable
SystemHandler — ping/identify + system.* commands (8 total)
ClockHandler — 16 clock.* commands
Notable fixes vs. original CommandHandler:
- clock.set_timings now sets pulseDuration/pauseDuration correctly
(original called updateClockOutputs — was a bug)
- system.restart uses a deferred FreeRTOS task (no blocking delay)
- relay.test_output safety-gated: player must be fully stopped
- Timekeeper class name (lowercase k) corrected throughout
Two compile-time fixes applied during build:
- JsonVariantConst → const_cast<JsonDocument&>().as<JsonVariant>()
(ConfigManager methods take non-const JsonVariant)
- class TimeKeeper → class Timekeeper (actual class name in header)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include "MQTTHandler.hpp"
|
||||
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||
#include "../../../Communication/MQTTAsyncClient/MQTTAsyncClient.hpp"
|
||||
#include "../../../Logging/Logging.hpp"
|
||||
|
||||
#define TAG "MQTTHandler"
|
||||
|
||||
MQTTHandler::MQTTHandler(ConfigManager& configManager, MQTTAsyncClient& mqttClient)
|
||||
: _configManager(configManager), _mqttClient(mqttClient) {}
|
||||
|
||||
std::vector<String> MQTTHandler::commands() const {
|
||||
return { "mqtt.enable", "mqtt.disable" };
|
||||
}
|
||||
|
||||
CommandResult MQTTHandler::execute(const CommandEnvelope& envelope) {
|
||||
bool enable = (envelope.command == "mqtt.enable");
|
||||
|
||||
_configManager.setMqttEnabled(enable);
|
||||
if (!_configManager.saveGeneralConfig()) {
|
||||
return CommandResult::err(envelope.command,
|
||||
"MQTT state changed but failed to save to SD");
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
_mqttClient.connect();
|
||||
} else {
|
||||
_mqttClient.disconnect();
|
||||
}
|
||||
|
||||
LOG_INFO(TAG, "MQTT %s by user command", enable ? "enabled" : "disabled");
|
||||
return CommandResult::ok(envelope.command,
|
||||
String("MQTT ") + (enable ? "enabled" : "disabled") + " and saved");
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../ICommandHandler.hpp"
|
||||
|
||||
class ConfigManager;
|
||||
|
||||
// Forward declare the transport so we don't pull in all of MQTT yet.
|
||||
// In Stage 3 this will be MQTTTransport; for now it wraps MQTTAsyncClient.
|
||||
class MQTTAsyncClient;
|
||||
|
||||
class MQTTHandler : public ICommandHandler {
|
||||
public:
|
||||
MQTTHandler(ConfigManager& configManager, MQTTAsyncClient& mqttClient);
|
||||
|
||||
std::vector<String> commands() const override;
|
||||
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||
|
||||
private:
|
||||
ConfigManager& _configManager;
|
||||
MQTTAsyncClient& _mqttClient;
|
||||
};
|
||||
Reference in New Issue
Block a user