Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TV controls channel down and up #9

Merged
merged 1 commit into from
Mar 13, 2018
Merged

add TV controls channel down and up #9

merged 1 commit into from
Mar 13, 2018

Conversation

Gustry
Copy link
Collaborator

@Gustry Gustry commented Mar 13, 2018

add TV controls channel down and up

I tried to add the channel number, but no luck for now. I'm not sure how to give a parameter in my request. I have another look later maybe.

@coveralls
Copy link

coveralls commented Mar 13, 2018

Coverage Status

Coverage increased (+0.2%) to 69.758% when pulling 8bb2e63 on Gustry:tv_control into 0099e7c on supersaiyanmode:master.

@supersaiyanmode
Copy link
Owner

Hi @Gustry can you please explain, what you mean by: "I'm not sure how to give a parameter in my request" ? May be with an example? Do you want to do: tv_control.set_channel(12) ?

@Gustry
Copy link
Collaborator Author

Gustry commented Mar 13, 2018

Yes exactly. But what I put in this PR is working. I didn't commit the set_channel(12).

@supersaiyanmode
Copy link
Owner

Ohh, please look at MediaControl(..).set_volume(..):

"set_volume": {
    "uri": "ssap://audio/setVolume",
    "args": [int],
    "payload": {"volume": arguments(0)}
},

Think of "payload" field as a template, which gets substituted by arguments. In the above code, argument(0) retrieves the first argument (=int_val1)that was passed when set_volume(int_val1) was called. After substitution the object is sent the the URI in the outer object.

In other words:

"custom_function": {
    "uri": "ssap://some/uri",
    "args": [int, str],
    "payload": {
        "field1": "blah",
        "field2": [argument(0), argument[1]],
        "field3": argument(1)
    }
},

upon invocation like: obj.custom_function(3, "hello") will produce a payload of {"field1": "blah", "field2": [3, "hello"], "field3": "hello"}.

@supersaiyanmode supersaiyanmode merged commit dc5b13d into supersaiyanmode:master Mar 13, 2018
@supersaiyanmode
Copy link
Owner

Thanks @Gustry for this PR! 👍

@Gustry Gustry deleted the tv_control branch March 13, 2018 22:10
@dagavi
Copy link
Contributor

dagavi commented Dec 14, 2019

In the project referenced in the REAME we can see this: https://github.com/klattimer/LGWebOSRemote/blob/master/LGTV/remote.py#L207

They have:

    def inputChannelUp(self, callback=None):
        self.__send_command("request", "ssap://tv/channelUp", None, callback)

    def inputChannelDown(self, callback=None):
        self.__send_command("request", "ssap://tv/channelDown", None, callback)

    def setTVChannel(self, channel, callback=None):
        self.__send_command("request", "ssap://tv/openChannel", {"channelId": channel}, callback)

    def getTVChannel(self, callback=None):
        self.__send_command("request", "ssap://tv/getCurrentChannel", None, callback, "channels")

This merge implements channelUp and Down, so I supose that add setChannel, getChannel and getChannelList will be, with your explanition:

COMMANDS = {
    "channel_down": {"uri": "ssap://tv/channelDown"},
    "channel_up": {"uri": "ssap://tv/channelUp"},
    "set_channel": {
        "uri": "ssap://tv/openChannel",
        "args": [int],
        "payload": {
            "channelId": argument(0)
        }
    },
    # Based on get_volume
    "get_current_channel": {
        "uri": "ssap://tv/getCurrentChannel",
        "validation": standard_validation,
        "subscription": True
    },
    "channel_list": {"uri": "ssap://tv/getChannelList"}
 }

And then I will have available:

tv_control = TvControl(client)

tv_control.set_channel(10)

currentChannelOutput = tv_control.get_current_channel()
# I supose that currentChannelOutput  will be the response from the TV

tv_control.subscribe_get_volume(some_handler)

channelListOutput = tv_control.get_channel_list()

PD: Add comment #9 (comment) to the README or as a comment in the code. Is very useful to understand how this works and how you can use and extend.


Edit: I tried and its almost working!

class TvControl(WebOSControlBase):
    COMMANDS = {
        "channel_down": {"uri": "ssap://tv/channelDown"},
        "channel_up": {"uri": "ssap://tv/channelUp"},
        "set_channel_with_number": {
            "uri": "ssap://tv/openChannel",
            "args": [int],
            "payload": {
                "channelNumber": arguments(0)
            }
        },
        "set_channel_with_id": {
            "uri": "ssap://tv/openChannel",
            "args": [str],
            "payload": {
                "channelId": arguments(0)
            }
        },
        "get_current_channel": {
            "uri": "ssap://tv/getCurrentChannel",
            "validation": standard_validation,
            "subscription": True
        },
        "channel_list": {"uri": "ssap://tv/getChannelList"}
     }

The problem is that "with_number" it's not working (and is the more natural: set channel 12). It throws and error (at least in my TV). More people have the same problem:
merdok/homebridge-webos-tv#88 (comment)

And I tested with channel ID (from channel_list) and it works. So you can perform an initial channel_list an index by number and then call set_channel_with_id(channel_number_to_id[12])

@supersaiyanmode
Copy link
Owner

Hi @dagavi, thanks so much! The new APIs around TV Channels sound good to me. Would you be open to creating a PR with only those commands that work (in other words minus the channel number)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants