Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Direction of the SonosKeyController #2

Closed
naxels opened this issue Jan 18, 2021 · 11 comments
Closed

Direction of the SonosKeyController #2

naxels opened this issue Jan 18, 2021 · 11 comments
Assignees

Comments

@naxels
Copy link

naxels commented Jan 18, 2021

Hi @pwt,

Today I was thinking about an idea similar to this repo you created, where you have a REPL sort of interface to control the Sonos at your home.

This after using the soco-cli repo you keep updating (thanks for that as well), I found it a little repetitive to always have to fully type out all commands and not send a quick keyboard shortcut.

Could you tell me if you have ideas/plans for the future of the SonosKeyController repo?

I had some thoughts about using the Discover feature and allow the user to list which Sonos he wants to connect to, instead of having to configure it (unless of course you run it automated and don't want any interaction, it should automatically pick the one in config)

And also currently the favorites are pre configured, I was thinking maybe it is possible to get the favorites from the Sonos setup on startup? this way if someone uses the Sonos App, it will reflect on startup of the SonosKeyController more dynamically.

Is it possible to add 'q' as default in the config in order to print the current queue? This will again not help anyone that doesn't have some sort of display next to the running SonosKeyController, however for my idea running it as a REPL helps a lot.

Thank you!

@pwt
Copy link
Owner

pwt commented Jan 18, 2021

Hi Patrick:

Thanks for your questions/ideas.

Interesting thoughts. As you note, my target use case for SonosKeyController is headless operation: I use it with an IR receiver device that acts like a keyboard, but it could be used with any keyboard-like device, of course. I hadn't envisaged it being used as a REPL, which is why it uses static configuration, etc. I don't currently have any plans to extend it for the REPL use case, although I could easily extend it to add q. I'll take a look at that. Nice idea about the favourites: I'll look at that too.

As for SoCo-CLI, its primary target is automation rather than interactive use, but I have to admit that I use it a lot straight from the command line because it's often faster than switching to the Sonos apps. There are ways to reduce typing: the current version now allows partial speaker name matches, so I can type fr instead of "Front Reception", for example. It's also possible to alias commonly used commands, if that makes things easier.

However, I have been wondering whether I could enhance SoCo-CLI with a REPL-style mode of operation. No firm plans at the moment, though.

-- Peter

@pwt pwt self-assigned this Jan 18, 2021
@naxels
Copy link
Author

naxels commented Jan 18, 2021

Thanks Peter,

Appreciate the comment.

The feature I missed most in the Sonos app is just adding URL's to play / queue etc
Now I just do this using the soco-cli.

Then the issue arrises that just like you said, it's faster to just run a command on the CLI than get the Sonos app whenever I'm on any laptop.

I now have SonosKeyController running in a terminal window and that is by far the fastest way to interact with the Sonos, especially using a 1 key interaction.

I'm not experienced in Python, however here are some of the changes I made to provide me the things I needed in a 1 key app:
Functions:
naxels@5843994

Config:
naxels@cc22647

I have not fully tested the changes as I already had a Queue and was playing music, so everything functioned as expected.

Hopefully you can work with this if you find it useful.

Thank you,
Patrick

@pwt
Copy link
Owner

pwt commented Jan 18, 2021

Thanks Patrick! I'll take a look later.

I've just added the following to SoCo-CLI to save a bit of typing. It'll be in the next version.

Using the $SPKR Environment Variable

To avoid typing the speaker name, or to parameterize the use of SoCo-CLI commands, it's possible to use the SPKR environment variable instead of supplying the speaker name (or IP address) on the command line.

Example: The following will set up all sonos commands to operate on the "Front Reception" speaker:

$ export SPKR="Front Reception"
$ sonos play
$ sonos wait_stop : volume 10

IP addresses also work, e.g.: $ export SPKR=192.168.0.50.

@naxels
Copy link
Author

naxels commented Jan 18, 2021

Cool!

That will definitely come in handy :)

@pwt
Copy link
Owner

pwt commented Jan 18, 2021

Thanks for your code examples. I've pushed a couple of simple commits that add the ability to list and play from the queue, and to list and play from favourites.

@naxels
Copy link
Author

naxels commented Jan 18, 2021

Thanks, after some trouble merging/rebasing the changes I decided to start over in a new branch with my customizations to make future merges from your code easier.

Based on your changes and adding soco-cli, I've added a quick seek forwards and backwards feature that hopefully you find helpful as well, see all changes here:
https://github.com/naxels/SonosKeyController/commits/custom_changes

The person I showed this script to today was impressed with the ease and speed I could control their Sonos device with just a button on the keyboard instead of the battery draining Sonos official app :)

@pwt
Copy link
Owner

pwt commented Jan 19, 2021

Thanks, after some trouble merging/rebasing the changes I decided to start over in a new branch with my customizations to make future merges from your code easier.

Yes, sorry about that!

Based on your changes and adding soco-cli, I've added a quick seek forwards and backwards feature that hopefully you find helpful as well, see all changes here:
https://github.com/naxels/SonosKeyController/commits/custom_changes

Looks good. It's a little slow to invoke soco-cli once per command, but it's also very convenient for the time being because SoCo-CLI adds lots of simplifying value on top of the SoCo library. I'll think about how to add something more akin to an API.

The person I showed this script to today was impressed with the ease and speed I could control their Sonos device with just a button on the keyboard instead of the battery draining Sonos official app :)

It can be convenient, I agree.

Inspired by this discussion, I'm playing with adding a simple interactive mode to SoCo-CLI. Very early days, but if it looks promising, I may add the ability to define shortcuts in a separate file, which could then be invoked with something like !<shortcut>. Adding single keypress operation (no 'return' required) as in sonoskeycontroller is a little more problematic.

Draft docs at:

https://github.com/avantrec/soco-cli/blob/next_version/README.md#interactive-mode-experimental

@naxels
Copy link
Author

naxels commented Jan 19, 2021

Works perfectly on my end and looks very much like what I was thinking about before I found this project :)

Also like the idea of the shortcuts, now I'm getting used to single key presses to control my Sonos haha.

Had some ideas for the interactive mode:

  • add a help (shortcut h) or command (shortcut c and/or cmd) to print the commands you can use.
    • maybe > h playback to list all playback commands
    • > h group to list all grouping commands
    • > h queue to list all queueing commands

^ let me know if you like that idea, from the code I could see the actions are only specified with details in the README, however I am more than willing to help to translate this into the help/command idea if you have an idea for a framework to put this in.

  • have some key metrics/information that always display on top (like top/htop would show cpu/mem on top)

    • Sonos Speaker name and maybe Ip address for example
    • Even if doing it on top is not easily possible, maybe update the line text to this (with "Portable" as example):
      • Sonos Portable > and display Press 0 to exit in help / while entering Interactive mode
  • ability to switch Sonos Speaker in interactive mode with s, spkr or speaker command

    • example: > s "Portable" (or ip) to switch to that Speaker

If easier, we can also close this issue topic and continue a new one on soco-cli in order to keep the right context.

@pwt
Copy link
Owner

pwt commented Jan 19, 2021

Thanks for all the ideas!

If easier, we can also close this issue topic and continue a new one on soco-cli in order to keep the right context.

Sounds good. I've started a topic over at the SoCo-CLI discussions area at: avantrec/soco-cli#10. It links back to this issue, which I'll now close.

@pwt pwt closed this as completed Jan 19, 2021
@pwt
Copy link
Owner

pwt commented Jan 19, 2021

It's a little slow to invoke soco-cli once per command, but it's also very convenient for the time being because SoCo-CLI adds lots of simplifying value on top of the SoCo library. I'll think about how to add something more akin to an API.

I've now added an API layer to SoC-CLI, and I've made a quick first pass at converting SonosKeyController to use it. It's a lot more efficient than invoking via subprocess.

@pwt
Copy link
Owner

pwt commented Jan 19, 2021

Note that there's a small change in the api.run_command() interface coming in SoCo-CLI 0.3.1, which will require a small change in clients.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants