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

how to view current power status info #32

Open
leifliddy opened this issue Jun 8, 2020 · 4 comments
Open

how to view current power status info #32

leifliddy opened this issue Jun 8, 2020 · 4 comments

Comments

@leifliddy
Copy link

I'm trying find a way to verify whether the TV is turned on or off. Is there an function you can implement to return the current power status?

@supersaiyanmode
Copy link
Owner

I am not aware of any such API exposed by the TV. If there's one, it shouldn't be difficult for this library to provide one that is consistent with others.

That being said, I have used the status of discovery to deduce whether or not the TV is powered on. (Assuming the TV is listening when it is powered on)

@benjamin-rousseau-shift

Yep exactly what @supersaiyanmode said.
If you can't connect therefor it is down. You lose a little bit of time because it seems that there's quite a high timeout (I think 60 sec ?)

You can put the .connect() in a try statement. and do something if you stumble upon an exception.
What I personally do is :
Send a magic packet at the beginning whether I know if it's down or not because my function expect the TV to be up, and if it still can't connect it'll sleep 5 sec and resend a magic packet.

But really depends on what you're trying to achieve.

@Gustry
Copy link
Collaborator

Gustry commented Aug 24, 2021

Make a "ping" on the IP before using this python library.

@benjamin-rousseau-shift
Copy link

benjamin-rousseau-shift commented Feb 1, 2022

Just like @Gustry said you can just ping it.
I did not come back here for a long time but lemme share a little piece of code I have for this :

from pywebostv.connection import WebOSClient
from wakeonlan import send_magic_packet
from time import sleep
import os


def connect(ip, mac):
    while True:
        # We try to access the TV.
        try:
            response = os.system("ping -n 1 -w 500 " + ip)
            if response == 0:
                print('[INFO] Connecting to IP %s' % ip)
                client = WebOSClient(ip)
                client.connect()
                break
            else:
                print('[INFO] IP still not responding. Sending Magic Packet to mac %s' % mac)
                send_magic_packet(mac)
                sleep(1)
        # If it's not up we turn it on via magic packet wooooo :)
        except:
            print('[INFO] Magic Packet sent. Let\'s sleep for 5 sec.')
            sleep(5)

    return client

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

No branches or pull requests

4 participants