Library to emulate the Roku API for Home Assistant and other automation tools. Discovery is tested with Logitech Harmony and Android remotes.
pip install emulated_rokuRequires Python 3.12+.
Subclass EmulatedRokuCommandHandler to handle key press / down / up events and app launches, then start the server:
import asyncio
import emulated_roku
class MyHandler(emulated_roku.EmulatedRokuCommandHandler):
def on_keypress(self, roku_usn, key):
print(f"Key pressed: {key}")
def launch(self, roku_usn, app_id):
print(f"Launch app: {app_id}")
async def main():
server = emulated_roku.EmulatedRokuServer(
MyHandler(),
"my-roku",
emulated_roku.get_local_ip(),
8060,
)
await server.start()
await asyncio.Event().wait()
asyncio.run(main())See example.py for a minimal runnable example.
The application list can be customized with a comma- or newline-separated string:
server = emulated_roku.EmulatedRokuServer(
handler, "my-roku", "192.168.1.10", 8060,
custom_apps="1:Netflix,2:YouTube,3:Plex",
)This produces:
<apps>
<app id="1" version="1.0.0">Netflix</app>
<app id="2" version="1.0.0">YouTube</app>
<app id="3" version="1.0.0">Plex</app>
</apps>python -m venv .venv
source .venv/bin/activate
pip install -e .[test]
pytest tests/ -v