Skip to content

Instantly share code, notes, and snippets.

@alekssamos
Created December 12, 2021 15:10
Show Gist options
  • Save alekssamos/4151be4b0077cf733a575a7f8157d2ac to your computer and use it in GitHub Desktop.
Save alekssamos/4151be4b0077cf733a575a7f8157d2ac to your computer and use it in GitHub Desktop.
lg tv webos toggle audio guide for blind
import os, os.path
import pickle
import time
from pywebostv.discovery import * # Because I'm lazy, don't do this.
from pywebostv.connection import *
from pywebostv.controls import *
filename = os.path.join(os.path.expanduser("~"), "lgtvst.pickle")
# 1. For the first run, pass in an empty dictionary object. Empty store leads to an Authentication prompt on TV.
# 2. Go through the registration process. `store` gets populated in the process.
# 3. Persist the `store` state to disk.
# 4. For later runs, read your storage and restore the value of `store`.
if not os.path.isfile(filename):
store = {}
else:
with open(filename, "rb") as file: store = pickle.load(file)
# Scans the current network to discover TV. Avoid [0] in real code. If you already know the IP,
# you could skip the slow scan and # instead simply say:
client = WebOSClient("172.20.10.12")
# client = WebOSClient.discover()[0]
client.connect()
for status in client.register(store):
if status == WebOSClient.PROMPTED:
print("Please accept the connect on the TV!")
elif status == WebOSClient.REGISTERED:
print("Registration successful!")
# Keep the 'store' object because it contains now the access token
# and use it next time you want to register on the TV.
print(store) # {'client_key': 'ACCESS_TOKEN_FROM_TV'}
with open(filename, "wb") as file: pickle.dump(store, file)
inp = InputControl(client)
inp.connect_input()
inp.back(block=True)
time.sleep(1)
inp.home(block=True)
time.sleep(1)
inp.menu(block=True) # the menu for adjusting settings for the television
time.sleep(2)
for _ in range(0, 4):
inp.down(block=True) # all settings
time.sleep(2)
inp.ok(block=True)
time.sleep(4)
for _ in range(0, 2):
inp.down(block=True) # accessability
time.sleep(2)
inp.right(block=True) # expand submenu
time.sleep(2)
inp.ok(block=True) # audio guide
time.sleep(2)
inp.up(block=True) # turn off switch on, check box
time.sleep(3)
inp.ok(block=True) # audio guide
time.sleep(1)
inp.disconnect_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment