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

Add in two new methods for iterable volume control. #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ To see a full list of available commands, use the *commands* property.
If you are following along on your home network and are connected to your Roku, you should see it doing stuff. *Cool!*


Iterable Functions
~~~~~~~~~~~~~~~~~~

If there is a command that could require multiple button presses with regular physical remote usage, it can be sent multiple times in one call.

The `volume_up`, `volume_down`, `channel_up`, `channel_down`, `backspace`, `up`, `down`, `left`, `right`, and `back` commands can all accept an integer parameter to run that command that amount of times.
::
>>> roku.volume_down(3)
>>> roku.volume_up(5)
>>> roku.down(4)

Apps
~~~~

Expand Down
7 changes: 7 additions & 0 deletions roku/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
'poweroff': 'PowerOff',
}

ITERABLE_COMMANDS = ('volume_up', 'volume_down', 'channel_up', 'channel_down', 'backspace', 'up', 'down', 'left', 'right', 'back')

SENSORS = ('acceleration', 'magnetic', 'orientation', 'rotation')

TOUCH_OPS = ('up', 'down', 'press', 'move', 'cancel')
Expand Down Expand Up @@ -169,6 +171,11 @@ def command(*args, **kwargs):
keys = ['%s.%s' % (name, axis) for axis in ('x', 'y', 'z')]
params = dict(zip(keys, args))
self.input(params)
elif name in ITERABLE_COMMANDS:
iterations = args[0] if len(args[0]) > 0 else 1
path = '/keypress/%s' % COMMANDS[name]
for _ in range(iterations):
self._post(path)
elif name == 'literal':
for char in args[0]:
path = '/keypress/%s_%s' % (COMMANDS[name], quote_plus(char))
Expand Down