jcarbaugh / python-roku

Screw remotes. Control your Roku with Python.
https://pypi.python.org/pypi/roku
BSD 3-Clause "New" or "Revised" License
288 stars 94 forks source link

Add 'poweron' keypress support #52

Closed bwarden closed 4 years ago

bwarden commented 4 years ago

Power and PowerOff are supported here: https://github.com/jcarbaugh/python-roku/blob/54cb21eab3004671461c77116513032668f5ce0e/roku/core.py#L58-L60

Power is functionally a toggle operation. While the ECP doesn't mention PowerOn, it's accepted by at least some models, so it would be nice to add an explicit poweron method to ensure the Roku device is on, regardless of prior state.

Testing, demonstrating that Power, PowerOn, and PowerOff are all accepted with HTTP status 202, while phony PowerBad is rejected with 400:

$ curl -v -d '' http://192.168.101.59:8060/keypress/Power
*   Trying 192.168.101.59...
* Connected to 192.168.101.59 (192.168.101.59) port 8060 (#0)
> POST /keypress/Power HTTP/1.1
> Host: 192.168.101.59:8060
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 202 Accepted
< Server: Roku UPnP/1.0 MiniUPnPd/1.4
< Content-Length: 0
<
* Connection #0 to host 192.168.101.59 left intact
$ curl -v -d '' http://192.168.101.59:8060/keypress/PowerOn
*   Trying 192.168.101.59...
* Connected to 192.168.101.59 (192.168.101.59) port 8060 (#0)
> POST /keypress/PowerOn HTTP/1.1
> Host: 192.168.101.59:8060
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 202 Accepted
< Server: Roku UPnP/1.0 MiniUPnPd/1.4
< Content-Length: 0
<
* Connection #0 to host 192.168.101.59 left intact
$ curl -v -d '' http://192.168.101.59:8060/keypress/PowerOff
*   Trying 192.168.101.59...
* Connected to 192.168.101.59 (192.168.101.59) port 8060 (#0)
> POST /keypress/PowerOff HTTP/1.1
> Host: 192.168.101.59:8060
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 202 Accepted
< Server: Roku UPnP/1.0 MiniUPnPd/1.4
< Content-Length: 0
<
* Connection #0 to host 192.168.101.59 left intact
$ curl -v -d '' http://192.168.101.59:8060/keypress/PowerBad
*   Trying 192.168.101.59...
* Connected to 192.168.101.59 (192.168.101.59) port 8060 (#0)
> POST /keypress/PowerBad HTTP/1.1
> Host: 192.168.101.59:8060
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 400 Bad Request
< Server: Roku UPnP/1.0 MiniUPnPd/1.4
< Content-Length: 0
* HTTP error before end of send, stop sending
<
* Closing connection 0
$