|
16 | 16 | pip install roku |
17 | 17 | ``` |
18 | 18 |
|
| 19 | +To use the async client, install with the `async` extra: |
| 20 | + |
| 21 | +``` |
| 22 | +uv add "roku[async]" |
| 23 | +``` |
| 24 | + |
| 25 | +To use the CLI, install with the `cli` extra: |
| 26 | + |
| 27 | +``` |
| 28 | +uv add "roku[cli]" |
| 29 | +``` |
| 30 | + |
19 | 31 | ## Usage |
20 | 32 |
|
21 | 33 | ### The Basics |
@@ -123,6 +135,85 @@ What if I now want to watch *The Informant!*? Again, with the search open and wa |
123 | 135 |
|
124 | 136 | This will iterate over each character, sending it individually to the Roku. |
125 | 137 |
|
| 138 | +## Async |
| 139 | + |
| 140 | +An async client is available for use with `asyncio`. The `AsyncRoku` class provides the same functionality as the synchronous `Roku` class, but with async methods. |
| 141 | + |
| 142 | +```python |
| 143 | +>>> import asyncio |
| 144 | +>>> from roku._async import AsyncRoku |
| 145 | +``` |
| 146 | + |
| 147 | +Create an instance and use it as an async context manager: |
| 148 | + |
| 149 | +```python |
| 150 | +>>> async def main(): |
| 151 | +... async with AsyncRoku('192.168.10.163') as roku: |
| 152 | +... await roku.home() |
| 153 | +... await roku.right() |
| 154 | +... await roku.select() |
| 155 | +... |
| 156 | +>>> asyncio.run(main()) |
| 157 | +``` |
| 158 | + |
| 159 | +Properties like `apps`, `active_app`, and `device_info` are replaced with async methods: |
| 160 | + |
| 161 | +```python |
| 162 | +>>> async def main(): |
| 163 | +... async with AsyncRoku('192.168.10.163') as roku: |
| 164 | +... apps = await roku.get_apps() |
| 165 | +... current = await roku.get_active_app() |
| 166 | +... info = await roku.get_device_info() |
| 167 | +... |
| 168 | +>>> asyncio.run(main()) |
| 169 | +``` |
| 170 | + |
| 171 | +Discovery works as an async class method: |
| 172 | + |
| 173 | +```python |
| 174 | +>>> async def main(): |
| 175 | +... rokus = await AsyncRoku.discover() |
| 176 | +... for roku in rokus: |
| 177 | +... async with roku: |
| 178 | +... info = await roku.get_device_info() |
| 179 | +... print(info.user_device_name) |
| 180 | +... |
| 181 | +>>> asyncio.run(main()) |
| 182 | +``` |
| 183 | + |
| 184 | +## CLI |
| 185 | + |
| 186 | +A command-line interface is available for device discovery. Install with the `cli` extra and use the `roku` command: |
| 187 | + |
| 188 | +``` |
| 189 | +$ roku discover |
| 190 | +192.168.10.163:8060 |
| 191 | +``` |
| 192 | + |
| 193 | +Use `-i` / `--inspect` to display device details: |
| 194 | + |
| 195 | +``` |
| 196 | +$ roku discover -i |
| 197 | +192.168.10.163:8060 |
| 198 | + Name: Living Room Roku |
| 199 | + Model: Roku Ultra (4800X) |
| 200 | + Type: Box |
| 201 | + Software: 11.5.0.4312 |
| 202 | + Serial: YH009N854321 |
| 203 | +``` |
| 204 | + |
| 205 | +You can adjust the discovery `--timeout` and `--retries`: |
| 206 | + |
| 207 | +``` |
| 208 | +$ roku discover --timeout 10 --retries 3 |
| 209 | +``` |
| 210 | + |
| 211 | +The CLI also supports the async client with the `--async` flag: |
| 212 | + |
| 213 | +``` |
| 214 | +$ roku --async discover |
| 215 | +``` |
| 216 | + |
126 | 217 | ## Advanced Stuff |
127 | 218 |
|
128 | 219 | ### Discovery |
@@ -196,6 +287,4 @@ More information about input, touch, and sensors is available in the [Roku Exter |
196 | 287 | ## TODO |
197 | 288 |
|
198 | 289 | - Multitouch support. |
199 | | -- A Flask proxy server that can listen to requests and forward them to devices on the local network. Control multiple devices at once, eh? |
200 | | -- A server that mimics the Roku interface so you can make your own Roku-like stuff. |
201 | 290 | - A task runner that will take a set of commands and run them with delays that are appropriate for most devices. |
0 commit comments