Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Command presets #439

Open
mStirner opened this issue Feb 16, 2024 · 2 comments
Open

Command presets #439

mStirner opened this issue Feb 16, 2024 · 2 comments

Comments

@mStirner
Copy link
Member

mStirner commented Feb 16, 2024

Command presets: Like a scene but for commands pattern.
E.g. "TuneIn: Radio PSR":

  • AV Receiver On
  • Select "TuneIn"
  • Go to Radio Presets
  • Select second entry (Radio PSR)
  • Click "OK/Enter"
  • Wait for response/stream start

A plugin should register preset, and handle the request/repsone correctly to avoid delays/wait like in scenes.

Pseudo code:

const endpoint = await C_ENDPOINT.find({
    labels: [
        "manufacturer=pioneer",
        "av-reciever=true",
        "type=audio",
        "tunein=true"
    ]
});


const preset = new endpoint.preset([
    endpoint.commands[0],    // POWER_ON
    endpoint.commands[4],    // Source = NET
    endpoint.commands[35],   // OK
    endpoint.commands[38],   // Arrow key right
    endpoint.commands[35],   // OK
    endpoint.commands[36],   // Arrow key down
    endpoint.commands[35],   // OK
    endpoint.commands[35],   // OK
    endpoint.commands[36],   // Arrow key down
    endpoint.commands[35],   // OK
]);

endpoint.registerPreset("TuneIn: Radio PSR", preset);
@mStirner
Copy link
Member Author

mStirner commented Feb 16, 2024

For that it would be nice to not rely on the command index, instead us the command key/alias.
But that would require a custom array, where the alias is mapped on the array object.

Draft:

class Commands extends Array{

    constructor(...args){

        super(...args);

        this.forEach((cmd) => {
            this[cmd.alias] = cmd;
        });

    }
 
}

TODO: Implement add/remove operations, perhaps with a proxy/object get/set trap.

@mStirner
Copy link
Member Author

Call commands as promise?

const arr = new Array(10).fill(null).map((e, i) => {
    return () => {

        console.log("Promise #" + i);

        return new Promise((resolve) => {
            setTimeout(resolve, 100);
        });

    };
});


(async () => {

    for (let i = 0; i < arr.length; i++) {
        await arr[i]();
        console.log(`#${i} done`);
    }

    console.log("Stack done");

})();

For that the command.trigger() needs to be promisifed.

  • Promisefie command.trigger()

@mStirner mStirner added this to the v4.0.0 release milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant