### Install PyWebOSTV Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Standard installation command for the library. ```bash $ pip install pywebostv ``` -------------------------------- ### Install PyWebOSTV on macOS Big Sur Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Installation steps for macOS users requiring OpenSSL dependencies. ```bash $ brew install openssl $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip3 install cryptography $ pip3 install pywebostv ``` -------------------------------- ### Control Applications Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md List installed applications and launch or close them by their identifiers. ```python app = ApplicationControl(client) apps = app.list_apps() # Returns a list of `Application` instances. # Let's launch YouTube! yt = [x for x in apps if "youtube" in x["title"].lower()][0] # Search for YouTube & launch it (Of course, don't # be this lazy. Check for errors). Also, Try # searching similarly for "amazon", "netflix" etc. launch_info = app.launch(yt) # Launches YouTube and shows the main page. launch_info = app.launch(yt, content_id="v=dQw4w9WgXcQ") # Or you could even launch a video directly! app.close(launch_info) # Close what we just launched. ``` -------------------------------- ### ApplicationControl - Launch and Manage Apps Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Manage installed applications by listing, launching with parameters, or monitoring the foreground app. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import ApplicationControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass app = ApplicationControl(client) # List all installed applications apps = app.list_apps() # Returns list of Application objects for application in apps[:5]: print(f"App: {application['title']}, ID: {application['id']}") # Find and launch YouTube youtube = next((x for x in apps if "youtube" in x["title"].lower()), None) if youtube: launch_info = app.launch(youtube) print(f"Launched: {launch_info}") # Launch YouTube with a specific video launch_info = app.launch(youtube, content_id="dQw4w9WgXcQ") # Close the app app.close(launch_info) # Find and launch Netflix netflix = next((x for x in apps if "netflix" in x["title"].lower()), None) if netflix: app.launch(netflix) # Get currently running foreground app current_app_id = app.get_current() # Returns app ID string print(f"Current app: {current_app_id}") # Get full app info for current app current_app = next((x for x in apps if x["id"] == current_app_id), None) if current_app: print(f"Foreground app: {current_app['title']}") print(f"Icon URL: {current_app['icon']}") # Subscribe to app changes def on_app_change(status, payload): if status: print(f"Foreground app changed to: {payload}") app.subscribe_get_current(on_app_change) ``` -------------------------------- ### Get Foreground App Information Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Retrieve the ID and icon URL of the currently active application on the TV. This is useful for identifying the foreground app. ```python app_id = app.get_current() # Returns the application ID (string) of the # foreground app. foreground_app = [x for x in apps if app_id == x["id"]][0] # Application app["id"] == app.data["id"]. icon_url = foreground_app["icon"] # This returns an HTTP URL hosted by the TV. ``` -------------------------------- ### Control TV Channels Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Manage TV channels by navigating up/down, accessing the channel list, and getting current channel information. You can also set a specific channel using its ID. ```python tv_control = TvControl(client) tv_control.channel_down() tv_control.channel_up() tv_control.channel_list() tv_control.get_current_channel() tv_control.get_current_program() # Returns the current channel and the EPG data tv_control.set_channel_with_id(channelId) # channelId can be found in channel_list(), get_current_channel() or get_current_program() ``` -------------------------------- ### Call TV APIs via Control Classes Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Demonstrates the pattern for initializing control classes and executing blocking API calls. ```python control = SomeControl(client) # Blocking call api_response = control.some_api() # Blocking call, with parameters (the table below lists API & arguments) api_response = control.some_other_api(arg1, arg2) # Blocking call can throw as error: try: control.good_api(bad_argument1) except ...: print("Something went wrong.") ``` -------------------------------- ### Establish WebSocket Connection and Register Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Establishes a WebSocket connection to the TV and handles the pairing and authentication process. Credentials are stored for future connections to avoid re-pairing. ```python from pywebostv.connection import WebOSClient # First run: empty store triggers pairing prompt on TV # Subsequent runs: restore store from your persistent storage store = {} # Load from file/database for subsequent runs client = WebOSClient("192.168.1.100", secure=True) client.connect() # Register with the TV (generator that yields status updates) for status in client.register(store): if status == WebOSClient.PROMPTED: print("Please accept the connection on your TV!") elif status == WebOSClient.REGISTERED: print("Registration successful!") # Store now contains: {'client_key': 'ACCESS_TOKEN_FROM_TV'} # Persist this for future connections to avoid re-pairing print(store) ``` ```python # Example: Save/load credentials to file import json def save_credentials(store, filepath="tv_credentials.json"): with open(filepath, "w") as f: json.dump(store, f) def load_credentials(filepath="tv_credentials.json"): try: with open(filepath, "r") as f: return json.load(f) except FileNotFoundError: return {} # Usage store = load_credentials() client.connect() for status in client.register(store): if status == WebOSClient.REGISTERED: save_credentials(store) ``` -------------------------------- ### Establish TV Connection and Registration Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Connects to a TV via discovery or IP, handles the registration process, and manages the authentication store. ```python from pywebostv.discovery import * # Because I'm lazy, don't do this. from pywebostv.connection import * from pywebostv.controls import * # 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 your_custom_storage_is_empty(): store = {} else: store = load_from_your_custom_storage() # 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("") # or for newer models: # client = WebOSClient("", secure=True) client = WebOSClient.discover()[0] # Use discover(secure=True) for newer models. 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'} persist_to_your_custom_storage(store) ``` -------------------------------- ### Manage External Inputs with SourceControl Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt List and switch between external input sources like HDMI and Component. Requires `SourceControl` from `pywebostv.controls`. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import SourceControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass source = SourceControl(client) # List all available input sources sources = source.list_sources() # Returns: [, , ...] for src in sources: print(f"Source: {src['label']}, ID: {src['id']}") # Switch to a specific input source hdmi1 = next((s for s in sources if "HDMI 1" in s["label"] and hdmi1 is not None), None) if hdmi1: source.set_source(hdmi1) # Switch to HDMI 2 hdmi2 = next((s for s in sources if "HDMI 2" in s["label"] and hdmi2 is not None), None) if hdmi2: source.set_source(hdmi2) ``` -------------------------------- ### Source Control Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Methods for listing and switching input sources. ```APIDOC ## GET /source/control ### Description Manages input sources for the television. ### Methods - `list_sources()`: Returns a list of InputSource instances - `set_source(source)`: Sets the active source using an InputSource instance ``` -------------------------------- ### Application Controls API Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Enables listing, launching, and closing applications on the TV. ```APIDOC ## Application Controls API ### Description Enables listing, launching, and closing applications on the TV. ### Methods #### `list_apps()` - **Description**: Get a list of all installed applications. - **Returns**: A list of `Application` instances. #### `launch(app_info: dict, content_id: str = None)` - **Description**: Launch an application. - **Parameters**: - **app_info** (dict) - Required - Information about the application to launch (e.g., from `list_apps()`). - **content_id** (str) - Optional - A specific content ID to launch within the application (e.g., a video ID). - **Returns**: Launch information, which can be used to close the application later. #### `close(launch_info: dict)` - **Description**: Close a previously launched application. - **Parameters**: - **launch_info** (dict) - Required - The launch information returned by the `launch()` method. - **Returns**: None ``` -------------------------------- ### Manage Input Sources Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md List available input sources on the TV and set a specific source. The `list_sources()` method returns a list of `InputSource` objects, and `set_source()` accepts one of these objects. ```python source_control = SourceControl(client) sources = source_control.list_sources() # Returns a list of InputSource instances. source_control.set_source(sources[0]) # .set_source(..) accepts an InputSource instance. # To get the current current source being used, please use the API that retrieves the foreground # app. ``` -------------------------------- ### Application Control Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Methods for retrieving the current foreground application and subscribing to changes. ```APIDOC ## GET /app/get_current ### Description Retrieves the application ID of the current foreground app. ### Method GET ### Subscription Supports subscription via `app.subscribe_get_current(callback)`. ``` -------------------------------- ### SystemControl - Notifications and Power Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Use SystemControl to send toast notifications, manage TV power states, and toggle screen energy-saving modes. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import SystemControl import requests client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass system = SystemControl(client) # Display a notification message on the TV system.notify("Hello from Python!") # Notification with custom icon icon_url = "https://example.com/icon.png" icon_data = requests.get(icon_url).content system.notify("Alert!", icon_bytes=icon_data, icon_ext="png") # Get TV system information info = system.info() # Returns: {'product_name': 'webOStv', 'model_name': 'OLED55C1', # 'sw_type': 'FIRMWARE', 'major_ver': '6', 'minor_ver': '0.0', ...} print(f"TV Model: {info.get('model_name')}") # Energy saving - turn screen off/on (audio continues) system.screen_off() # Turn off screen only system.screen_on() # Turn screen back on # Power off the TV completely (requires Wake-on-LAN to turn back on) system.power_off() ``` -------------------------------- ### Connect and Control Mouse Input Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Establish a connection for mouse and button controls, then perform actions like moving the mouse, clicking, and pressing directional or specific buttons. Remember to disconnect when finished. ```python inp.connect_input() inp.move(10, 10) # Moves mouse inp.click() # Click where the mouse pointer is. It sometimes also acts as the center "OK" # button on the remote. inp.ok() inp.up() inp.down() inp.left() inp.right() inp.home() inp.back() inp.dash() # The right side menu that appears with Live button inp.info() inp.num_1() # Number keys... inp.num_2() inp.num_3() inp.num_4() inp.num_5() inp.num_6() inp.num_7() inp.num_8() inp.num_9() inp.num_0() inp.asterisk() # Literally just an "*" inp.cc() # Closed captioning inp.exit() inp.red() # Colored buttons inp.green() inp.yellow() inp.blue() inp.menu() # the menu for adjusting settings for the television inp.mute() # The remaining commands are also available in either MediaControl or TvControl inp.volume_up() inp.volume_down() inp.channel_up() inp.channel_down() inp.play() inp.pause() inp.stop() inp.fastforward() inp.rewind() inp.disconnect_input() ``` -------------------------------- ### InputControl - Remote and Mouse Simulation Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Simulate remote control inputs, mouse movements, and keyboard typing. Requires a separate input socket connection. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import InputControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass inp = InputControl(client) # Keyboard input (requires on-screen keyboard to be visible) inp.type("Hello World!") # Type text inp.enter() # Press Enter/Return inp.delete(5) # Delete/backspace 5 characters # Connect to input socket for mouse/button commands inp.connect_input() try: # Mouse controls inp.move(100, 50) # Move mouse cursor by (dx, dy) pixels inp.click() # Click at current position # Navigation buttons (like TV remote) inp.up() inp.down() inp.left() inp.right() inp.ok() # OK/Enter/Select button inp.back() # Back button inp.home() # Home button inp.menu() # Menu button inp.exit() # Exit button inp.dash() # Dash menu (right side menu) inp.info() # Info button # Number pad inp.num_0() inp.num_1() inp.num_2() inp.num_3() inp.num_4() inp.num_5() inp.num_6() inp.num_7() inp.num_8() inp.num_9() inp.asterisk() # * button # Colored buttons inp.red() inp.green() inp.yellow() inp.blue() # Media/volume controls (also available in MediaControl) inp.play() inp.pause() inp.stop() inp.rewind() inp.fastforward() inp.mute() inp.volume_up() inp.volume_down() inp.channel_up() inp.channel_down() # Accessibility inp.cc() # Closed captions finally: inp.disconnect_input() # Always disconnect when done ``` -------------------------------- ### Input Control Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Methods for sending keyboard, mouse, and remote button commands to the TV. ```APIDOC ## POST /input/control ### Description Sends keyboard, mouse, and remote button inputs. Requires `connect_input()` before use and `disconnect_input()` after. ### Methods - `type(text)`: Sends keyboard input - `enter()`, `delete(n)`: Keyboard keys - `move(x, y)`, `click()`: Mouse controls - `ok()`, `up()`, `down()`, `left()`, `right()`, `home()`, `back()`, `info()`, `menu()`: Navigation and remote buttons - `num_0()`-`num_9()`, `red()`, `green()`, `yellow()`, `blue()`: Specific remote keys - `volume_up()`, `volume_down()`, `channel_up()`, `channel_down()`, `play()`, `pause()`, `stop()`: Media and TV controls ``` -------------------------------- ### Subscribe to Media Events Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Register callbacks to receive updates when volume or audio output sources change. ```python def on_volume_change(status, payload): if status: print(payload) else: print("Something went wrong.") media.subscribe_get_volume(on_volume_change) # on_volume_change(..) will now be called when the # volume/mute status etc changes. ``` ```python def on_audio_output_change(status, payload): if status: print(payload) else: print("Something went wrong.") media.subscribe_get_audio_output(on_audio_output_change) # on_audio_output_change(..) will now be called when the # output changes, for example connecting/disconneting a # bluetooth headphone device. ``` -------------------------------- ### Control TV Channels with TvControl Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Manage TV channel navigation, list channels, and retrieve current channel/program information. Requires `TvControl` from `pywebostv.controls`. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import TvControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass tv = TvControl(client) # Channel navigation tv.channel_up() tv.channel_down() # Get channel list channels = tv.channel_list() print(f"Found {len(channels.get('channelList', []))} channels") # Get current channel information current = tv.get_current_channel() print(f"Current channel: {current}") # Get current program with EPG data program = tv.get_current_program() print(f"Current program: {program}") # Set channel by ID (get channelId from channel_list or get_current_channel) channel_id = "3_1_21_0_0_1_0" # Example channel ID tv.set_channel_with_id(channel_id) # Subscribe to channel changes def on_channel_change(status, payload): if status: print(f"Channel changed: {payload}") tv.subscribe_get_current_channel(on_channel_change) ``` -------------------------------- ### Non-blocking API Calls Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Demonstrates how to make non-blocking API calls with callbacks for handling responses and errors. ```APIDOC ## Non-blocking API Calls ### Description Demonstrates how to make non-blocking API calls with callbacks for handling responses and errors. ### Usage ```python def my_function(status_of_call, payload): if status_of_call: # Successful response from TV. # payload is a dict or an object (see API details) print(payload) # Successful response from TV else: # payload is the error string. print("Error message: ", payload) # Example of making a non-blocking API call control.async_api(arg1, arg2, callback=my_function) ``` ### Subscription Management #### `control.subscribe_api(callback)` - **Description**: Subscribe to API events. The provided callback function will be invoked when an event occurs. - **Parameters**: - **callback** (function) - Required - The function to be called on event. #### `control.unsubscribe_api()` - **Description**: Unsubscribe from all API events. After this, you can resubscribe. - **Returns**: None ``` -------------------------------- ### Media Controls API Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Provides methods for controlling media playback, volume, and audio output sources. ```APIDOC ## Media Controls API ### Description Provides methods for controlling media playback, volume, and audio output sources. ### Methods #### `volume_up()` - **Description**: Increase the volume by 1 unit. - **Returns**: None #### `volume_down()` - **Description**: Decrease the volume by 1 unit. - **Returns**: None #### `get_volume()` - **Description**: Get the current volume status. - **Returns**: A dictionary containing volume information, e.g., `{'scenario': 'mastervolume_tv_speaker', 'volume': 9, 'muted': False}`. #### `set_volume(volume: int)` - **Description**: Set the TV volume. - **Parameters**: - **volume** (int) - Required - An integer from 1 to 100. - **Returns**: None #### `mute(status: bool)` - **Description**: Mute or unmute the TV. - **Parameters**: - **status** (bool) - Required - `True` to mute, `False` to unmute. - **Returns**: None #### `play()` - **Description**: Play media. - **Returns**: None #### `pause()` - **Description**: Pause media. - **Returns**: None #### `stop()` - **Description**: Stop media. - **Returns**: None #### `rewind()` - **Description**: Rewind media. - **Returns**: None #### `fast_forward()` - **Description**: Fast forward media. - **Returns**: None #### `get_audio_output()` - **Description**: Get the currently used audio output source. - **Returns**: An `AudioOutputSource` instance. #### `list_audio_output_sources()` - **Description**: List all available audio output sources. - **Returns**: A list of `AudioOutputSource` instances. #### `set_audio_output(source: AudioOutputSource)` - **Description**: Set the audio output source. - **Parameters**: - **source** (AudioOutputSource) - Required - The `AudioOutputSource` instance to set. - **Returns**: None ### Subscriptions #### `subscribe_get_volume(callback)` - **Description**: Subscribe to volume and mute status changes. - **Parameters**: - **callback** (function) - Required - A function that accepts `(status, payload)` arguments. `status` is a boolean indicating success, and `payload` contains the volume/mute information. #### `subscribe_get_audio_output(callback)` - **Description**: Subscribe to audio output changes. - **Parameters**: - **callback** (function) - Required - A function that accepts `(status, payload)` arguments. `status` is a boolean indicating success, and `payload` contains the audio output information. ``` -------------------------------- ### System Controls API Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Provides methods for interacting with the TV's system, such as notifications, power, and information retrieval. ```APIDOC ## System Controls API ### Description Provides methods for interacting with the TV's system, such as notifications, power, and information retrieval. ### Methods #### `notify(message: str, icon_bytes: bytes = None, icon_ext: str = None)` - **Description**: Display a notification message on the TV. - **Parameters**: - **message** (str) - Required - The notification message text. - **icon_bytes** (bytes) - Optional - The icon to display, provided as bytes. - **icon_ext** (str) - Optional - The file extension of the icon (e.g., 'png'). - **Returns**: None #### `power_off()` - **Description**: Turn off the TV. - **Returns**: None #### `info()` - **Description**: Retrieve system information about the TV. - **Returns**: A dictionary containing system details like `product_name`, `model_name`, `major_ver`, `minor_ver`, etc. #### `screen_off()` - **Description**: Turn off the TV screen (Energy Saving mode). - **Returns**: None #### `screen_on()` - **Description**: Turn on the TV screen. - **Returns**: None ``` -------------------------------- ### Send Keyboard Input Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Send keyboard input to the TV. This requires the on-screen keyboard to be visible. Use `inp.enter()` for the return key and `inp.delete(n)` to backspace. ```python inp = InputControl(client) inp.type("This sends keyboard input!") # This sends keystrokes, but needs the keyboard to # be displayed on the screen. inp.enter() # Return key. inp.delete(10) # Backspace 10 chars ``` -------------------------------- ### Manage System Controls Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Perform system-level operations such as sending notifications, powering off, or toggling screen state. ```python system = SystemControl(client) system.notify("This is a notification message!", # Show a notification message on the TV. icon_bytes=data, # optional: the icon to be displayed, # e.g.: requests.get(url).content icon_ext="png") # optional: specify icon type if icon is specified above system.power_off() # Turns off the TV. There is no way to turn it # back on programmically unless you use # something like Wake-on-LAN. system.info() # Returns a dict with keys such as product_name, # model_name, # major_ver, minor_ver etc. system.screen_off() # Energy Saving: Turns off the screen. system.screen_on() # Energy Saving: Turns the screen back on. ``` -------------------------------- ### Discover LG WebOS TVs on Network Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Automatically discovers LG WebOS TVs on the local network using SSDP. Supports both standard and secure connections. ```python from pywebostv.discovery import discover from pywebostv.connection import WebOSClient # Auto-discover TVs on the network clients = WebOSClient.discover() # Returns list of WebOSClient instances print(f"Found {len(clients)} TV(s)") # For newer TV models requiring secure connections clients = WebOSClient.discover(secure=True) # Or connect directly if you know the IP address client = WebOSClient("192.168.1.100") # Standard connection client = WebOSClient("192.168.1.100", secure=True) # Secure connection for newer models ``` -------------------------------- ### Control Media Playback and Volume Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Manage media playback states and audio output settings using the MediaControl class. ```python media = MediaControl(client) media.volume_up() # Increase the volume by 1 unit. Doesn't return anything media.volume_down() # Decrease the volume by 1 unit. Doesn't return anything media.get_volume() # Get volume status. Returns something like: # {'scenario': 'mastervolume_tv_speaker', 'volume': 9, 'muted': False} media.set_volume() # The argument is an integer from 1 to 100. Doesn't return anything. media.mute(status) # status=True mutes the TV. status=Fale unmutes it. media.play() media.pause() media.stop() media.rewind() media.fast_forward() cur_media_output_source = media.get_audio_output() # Returns the currently used audio output source as AudioOutputSource instance. audio_outputs = media.list_audio_output_sources() # Returns a list of AudioOutputSource instances. media.set_audio_output(audio_outputs[0]) # .set_audio_output(..) accepts an AudioOutputSource instance. ``` -------------------------------- ### Subscribe to Foreground App Changes Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Subscribe to changes in the foreground application. A callback function will be invoked when the current app changes. ```python app.subscribe_get_current(callback) ``` -------------------------------- ### Non-Blocking API Calls with Callbacks Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Perform asynchronous operations using callbacks for non-blocking behavior. Supports custom timeouts for blocking calls. Requires `MediaControl` and `ApplicationControl` from `pywebostv.controls`. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import MediaControl, ApplicationControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass media = MediaControl(client) app = ApplicationControl(client) # Callback function receives (status, payload) def handle_response(status, payload): if status: print(f"Success: {payload}") else: print(f"Error: {payload}") # Non-blocking volume query media.get_volume(block=False, callback=handle_response) # Non-blocking app list app.list_apps(block=False, callback=handle_response) # Fire-and-forget (no callback, no blocking) media.volume_up(block=False) # Blocking call with custom timeout (default is 60 seconds) volume = media.get_volume(block=True, timeout=10) ``` -------------------------------- ### Control Media Playback and Volume Source: https://context7.com/supersaiyanmode/pywebostv/llms.txt Manages TV volume, mute state, audio output sources, and media playback controls like play, pause, and stop. Supports subscribing to volume change events. ```python from pywebostv.connection import WebOSClient from pywebostv.controls import MediaControl client = WebOSClient("192.168.1.100", secure=True) client.connect() for status in client.register(store): pass media = MediaControl(client) # Volume controls media.volume_up() # Increase volume by 1 media.volume_down() # Decrease volume by 1 media.set_volume(25) # Set volume to specific level (0-100) # Get current volume status volume_info = media.get_volume() # Returns: {'scenario': 'mastervolume_tv_speaker', 'volume': 25, 'muted': False} print(f"Current volume: {volume_info['volume']}, Muted: {volume_info['muted']}") # Mute controls media.mute(True) # Mute media.mute(False) # Unmute # Playback controls (for media apps) media.play() media.pause() media.stop() media.rewind() media.fast_forward() # Audio output controls audio_outputs = media.list_audio_output_sources() # List available outputs # Returns: [, , ...] current_output = media.get_audio_output() # Get current audio output media.set_audio_output(audio_outputs[0]) # Set audio output # Subscribe to volume changes (non-blocking callback) def on_volume_change(status, payload): if status: print(f"Volume changed: {payload['volume']}, Muted: {payload['muted']}") else: print(f"Error: {payload}") media.subscribe_get_volume(on_volume_change) # ... later media.unsubscribe_get_volume() ``` -------------------------------- ### TV Control Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Methods for managing TV channels and retrieving program information. ```APIDOC ## GET /tv/control ### Description Provides methods to interact with TV channels and EPG data. ### Methods - `channel_down()` - `channel_up()` - `channel_list()` - `get_current_channel()` - `get_current_program()`: Returns current channel and EPG data - `set_channel_with_id(channelId)`: Sets channel by ID ``` -------------------------------- ### Handle Non-blocking API Calls Source: https://github.com/supersaiyanmode/pywebostv/blob/master/README.md Use a callback function to process asynchronous responses or errors from the TV. ```python def my_function(status_of_call, payload): if status_of_call: # Successful response from TV. # payload is a dict or an object (see API details) print(payload) # Successful response from TV else: # payload is the error string. print("Error message: ", payload) control.async_api(arg1, arg2, callback=my_function) # Subscription (if the API supports it, that is). control.subscribe_api(my_function). # Unsubscribe control.unsubscribe_api() # After this point, you can resubscribe. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.