feat(Player,PlaybackHandler): specific ACK messages for playback.play/stop (F-067)

Every rejection used to reach the caller as "Playback command failed".
Player::command() now returns PlayerCommandResult { ok, message } and
PlaybackHandler forwards the message verbatim:

- busy, missing pid, invalid speed / note_assignments / durations / mode,
  timed|interval without duration, bells disabled, bell overload lockout,
  melody failed to load (incl. 0-byte file), not found without url,
  needs download but no SD card
- success: "Playback started", "Melody download started — …",
  "Playback stopped", and "Already stopped" (stop while idle stays SUCCESS —
  idempotent, goal state reached)

Validation runs before setMelodyAttributes(), so a rejected play no longer
half-applies its fields. Also fixes: url was sticky (a later play of another
pid could download the old URL under the new name); bells.disable let a play
"succeed" and report playing with silent bells; a non-string name/pid
assigned nullptr to std::string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 20:17:47 +03:00
co-authored by Claude Opus 5.5
parent 92a0a8d5e8
commit 46a1a2567f
9 changed files with 331 additions and 117 deletions
@@ -32,15 +32,18 @@ CommandResult PlaybackHandler::handlePlay(const CommandEnvelope& envelope) {
// whether it was set by the V1 adapter or arrived as a bare V2 play command.
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
contents["action"] = "play";
bool ok = _player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin));
if (ok) return CommandResult::ok("playback", "Playback command executed");
return CommandResult::err("playback", "Playback command failed");
return toResult(_player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin)));
}
CommandResult PlaybackHandler::handleStop(const CommandEnvelope& envelope) {
JsonDocument& contents = const_cast<JsonDocument&>(envelope.contents);
contents["action"] = "stop";
bool ok = _player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin));
if (ok) return CommandResult::ok("playback", "Playback command executed");
return CommandResult::err("playback", "Playback command failed");
return toResult(_player.command(contents.as<JsonVariant>(), sourceFromOrigin(envelope.origin)));
}
// Player supplies the exact reply text — success wording or the specific
// rejection reason — so the ACK tells the caller *why*, not just "failed".
CommandResult PlaybackHandler::toResult(const PlayerCommandResult& r) {
return r.ok ? CommandResult::ok("playback", r.message)
: CommandResult::err("playback", r.message);
}
@@ -4,6 +4,7 @@
#include "../ICommandHandler.hpp"
class Player;
struct PlayerCommandResult;
class PlaybackHandler : public ICommandHandler {
public:
@@ -17,4 +18,5 @@ private:
CommandResult handlePlay(const CommandEnvelope& envelope);
CommandResult handleStop(const CommandEnvelope& envelope);
static CommandResult toResult(const PlayerCommandResult& r);
};