timmson / node-lgtv-api

Node.js API for the remote control of LG SmartTV (2012+)
MIT License
26 stars 8 forks source link

TV_CMD_CHANGE_CHANNEL (can you give an example) #4

Closed chearmstrong closed 7 years ago

chearmstrong commented 7 years ago

Hi,

I'm able to successfully get back the channel list using the queryData method and the TV_INFO_CHANNEL_LIST param.

However, I want to change the channel, based on an item (channel) in the list, but I'm not having any luck.

Are you able to provide an example of how to do this please? Should I be using the processCommand method? If so, what are the params?

Thanks in advance.

Ché

timmson commented 7 years ago

Hi, @chearmstrong Thanks for your question. I'll try this feature in next 1-2 days and come back to you with complete example. I actually use "takeScreenshot" to control what channel i really have on my TV.

chearmstrong commented 7 years ago

That would be great, thanks. I'll continue to experiment too. I'm also wanting to see if it's possible to open a specific app too, but no luck on that either.

timmson commented 7 years ago

I've checked the source. It was an error in README. Further you can see the valid example (ver 0.8.5):

tvApi.authenticate(function (err, sessionKey) {
        if (err) {
            console.error(err);
        } else {
            tvApi.queryData(tvApi.TV_INFO_CHANNEL_LIST, function (err, data) {
                if (err) {
                    console.error(err);
                } else {
                    console.log(data);
                }
            });
        }
    }
);

Changing the current channel:

tvApi.authenticate(function (err, sessionKey) {
        if (err) {
            console.error(err);
        } else {
            tvApi.processCommand(tvApi.TV_CMD_NUMBER_4, [], function (err, data) {
                if (err) {
                    console.error(err);
                } else {
                    console.log(data);
                }
            });
        }
    }
);

@chearmstrong, thx for your request! May i close the issue?

chearmstrong commented 7 years ago

Hi mate, thanks for this.

How would you suggest working with a channel with double digits? For example, channel 28? Am I right in thinking that TV_CMD_NUMBER_4 (for example) is just the same as pressing number for on the key pad.

Would I need to do TV_CMD_NUMBER_2 then TV_CMD_NUMBER_8 for channel 28.

So the TV_CMD_CHANGE_CHANNEL command isn't used?

I did try TV_CMD_NUMBER_2 then TV_CMD_NUMBER_8 but it didn't work as expected - not sure if I'm missing something.

Thanks again.

timmson commented 7 years ago

Ok, i've got it:) Like this? (ver. 0.8.7)

tvApi.authenticate(function (err, sessionKey) {
        if (err) {
            console.error(err);
        } else {
            tvApi.queryData(tvApi.TV_INFO_CHANNEL_LIST, function (err, data) {
                if (err) {
                    console.error(err);
                } else {
                    tvApi.processCommand(tvApi.TV_CMD_CHANGE_CHANNEL, data[5], function (err, data) {
                        if (err) {
                            console.error(err);
                        } else {
                            console.log(data);
                        }
                    });
                }
            });
        }
    }
);
chearmstrong commented 7 years ago

Hi mate, yes I worked out the issue but I can see you did too and fixed it now. Good job. :)