Skip to content

ADR-147: Add ProgramDelegate support to CommandServiceBase#103

Merged
jodavis merged 2 commits intodev/jodavis/ADR-128-spec-programmable-ir-commandsfrom
copilot/implement-adr-147-component
Feb 26, 2026
Merged

ADR-147: Add ProgramDelegate support to CommandServiceBase#103
jodavis merged 2 commits intodev/jodavis/ADR-128-spec-programmable-ir-commandsfrom
copilot/implement-adr-147-component

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

Extends CommandServiceBase<T> and Command to support an optional ProgramDelegate action for IR command learning, with the same error handling, logging, and UI state lifecycle as ExecuteDelegate. Services that don't support programming return null from CreateProgramHandler() and are unaffected.

Model

  • Command: Added ProgramAsync (ExecuteDelegate?) property with MVVM support. null means "not programmable."

CommandServiceBase

  • CreateProgramHandler(CommandType): new virtual method, returns null by default; override to enable programming
  • InitializeAsync: calls CreateProgramHandler per command; wraps non-null results and sets command.ProgramAsync, tracks programmable commands
  • CleanUpAsync: sets a "was shut down" handler on programmable commands (consistent with ExecuteAsync behavior); non-programmable commands stay null
  • CreateWrappedProgramHandler: mirrors execute wrapper — sets IsActive, logs start/success/cancel/error, propagates exceptions
// Subclass opts in by overriding CreateProgramHandler:
protected override Command.ExecuteDelegate? CreateProgramHandler(IRCommand command)
{
    return cancellationToken => _connection!.LearnIRAsync(cancellationToken);
}

Logging & Errors

  • Five new MessageLogger entries (EventIds 607–611): Programming, Programmed, ProgramError, ProgramCancelled, ProgramWasShutDown
  • Errors.CommandService_ProgramWasShutDown for post-shutdown calls

Tests

  • MockProgrammableCommandService test double overrides both CreateHandler and CreateProgramHandler
  • 13 new unit tests covering: constructor/init/cleanup state for programmable and non-programmable services; IsActive lifecycle; success, long-running (via TaskCompletionSource), error, and cancellation paths; cancellation token propagation; and shutdown handler behavior

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement task ADR-147 with unit tests for edge cases ADR-147: Add ProgramDelegate support to CommandServiceBase Feb 26, 2026
@jodavis jodavis marked this pull request as ready for review February 26, 2026 20:42
@jodavis jodavis merged commit 04ace21 into dev/jodavis/ADR-128-spec-programmable-ir-commands Feb 26, 2026
jodavis added a commit that referenced this pull request Feb 27, 2026
* ADR-147: Add ProgramDelegate support to CommandServiceBase
---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
jodavis added a commit that referenced this pull request Mar 11, 2026
* ADR-147: Add ProgramDelegate support to CommandServiceBase
---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jodavis <6740581+jodavis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants