diff --git a/README.rst b/README.rst index 806ed3c..b52398f 100644 --- a/README.rst +++ b/README.rst @@ -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 ~~~~ diff --git a/roku/core.py b/roku/core.py index b171723..e7e285c 100644 --- a/roku/core.py +++ b/roku/core.py @@ -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') @@ -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))