Ape / samsungctl

Remote control Samsung televisions via a TCP/IP connection
MIT License
712 stars 189 forks source link

Adds more keys. #95

Closed kdschlosser closed 12 months ago

kdschlosser commented 5 years ago

Adds more remote keys. support for different keys depends on the TV. I also extended the interactive mode to include discrete inputs the mappings are as follows.

F1 - TV Source
F2 - HDMI Source
F3 - DVI Source
F4 - DVR Source
F5 - Digital TV Source
F6 - Analog TV Source
F7 - FM Radio Source
F9 HDMI - 1 Source
F10 HDMI - 2 Source
F11 HDMI - 3 Source
F12 HDMI - 4 Source
CTRL+F1 - AV 1 Source
CTRL+F2 - AV 2 Source
CTRL+F3 - AV 3 Source
CTRL+F5 - S Video 1 Source
CTRL+F6 - S Video 2 Source
CTRL+F7 - S Video 3 Source
CTRL+F9 - Component 1 Source
CTRL+F10 - Component 2 Source

I added the command line arg --key-help to the argument parser. I supplied a default value to the positional key arguments. This is done so that if --key-help is used and no positional arguments are passed it will print off a full list of available keys. if keys are passed it will print off a help for that key

basically the key help for a single key is to show the description of that key. because there are keys that do not map out to what they actually do. In the event someone forgets what a specific key command is for.

Because I am running on Windows I added support for config file saving and loading. as this threw an error when i ran the script. I also did a little reorganization of the config file loading. this way done when i was trying to track down the problem mentioned above. I also added __future__.print_function for python 2 compatibility when printing the help for the keys. The printing of the keys gets done before a config file gets loaded. this is so that in the event the user has not set up a config file yet the --key-help will still run.

I also added .idea to gitignore .idea is to exclude the project files from pycharm

vogler commented 4 years ago

Tested this on my KS8090. In Ape:master the following works

pipenv run python -m samsungctl --host 192.168.178.24 --method websocket KEY_HDMI

whereas in this branch it does not, but somehow works when sent from interactive mode. KEY_HDMI1 does not work at all (single command or interactive).

vogler commented 4 years ago

Ok, changing _key_interval in remote_websocket.py from 0.5 to 1.0 solved the problem (alternatively, put a sleep before close to not slow down successive keys too much). Apparently my TV is not that fast and __exit__ closed the connection before it was done sending. Is there no option such that connection.send blocks until it's done? I assumed --timeout 1 means block max. 1s, but it seems like send is just fire-and-forget. Relying on time.sleep is pretty fragile.

It looks like my TV just doesn't accept KEY_HDMI1. I also found no key to change back to TV apart from KEY_CHUP/CHDOWN. It would be nice to have a table of which models accept which keys or an option to filter --key-help by what the connected TV accepts.

I'm now using the following workaround to reliably change to HDMI1 no matter which source is active:

pipenv run python -m samsungctl -vv --host 192.168.178.24 --method websocket KEY_SOURCE KEY_DOWN KEY_RIGHT KEY_RIGHT KEY_ENTER