Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Commands state machine #66

Open
tommasobertoni opened this issue Mar 5, 2021 · 0 comments
Open

Commands state machine #66

tommasobertoni opened this issue Mar 5, 2021 · 0 comments

Comments

@tommasobertoni
Copy link
Contributor

At the moment, the commands are registered and then they're all available to be invoked at any time.
Sometimes, though, it would be nice to be able to specify when the commands can be invoked, by dynamically changing the available commands.

Proposal:

interface ICommandsProvider
{
    IReadOnlyList<Command> AvailableCommands { get; }
}

The implementation would contain the state machine determining which commands can be executed by the engine:

class CommandsProvider : ICommandsProvider
{
    private readonly State _state;

    public CommandsProvider(State state /* custom-defined type, not in Covox */) =>
        _state = state;

    public IReadOnlyList<ICommand> AvailableCommands => ListAvailableCommands();

    private IReadOnlyList<ICommand> ListAvailableCommands()
    {
        if (state.IsLightOn)
            return new[] { TurnOffLightsCommand };
        else
            return new[] { TurnOnLightsCommand };
    }
}

// ...

covox.UseCommandsProvider(new CommandsProvider());

Covox would invoke ICommandsProvider.AvailableCommands after the speech recognition in order to do the understanding on the available commands.

Note: only one source of commands can be used, either RegisterCommands or UseCommandsProvider.

@tommasobertoni tommasobertoni added enhancement New feature or request API proposal labels Mar 5, 2021
@tommasobertoni tommasobertoni removed the enhancement New feature or request label Mar 5, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant