Asynchronous client library for LG WebOS TVs
Project description
AsyncWebOSTV
An asynchronous Python library for controlling LG WebOS TVs. This is an async port of the popular pywebostv library.
Features
- Asynchronous API for controlling LG WebOS TVs
- WebSocket-based communication
- Support for all major TV controls (media, system, input, applications, TV channels, sources, etc.)
- Network device discovery using Zeroconf (optional dependency)
- Secure SSL/TLS connections with certificate handling
- Modern Python async/await syntax
- Type hints for better IDE support
- Comprehensive test coverage
Requirements
- Python 3.7+
- aiohttp>=3.8.0
- websockets>=15.0.1
- aiofiles>=0.8.0
- typing_extensions>=4.0.0
- aiohttp-sse-client>=0.2.0
- aiohttp-socks>=0.7.0
- zeroconf>=0.36.0+ (Optional, for network discovery)
Installation
pip install asyncwebostv
Quick Start
import asyncio
from asyncwebostv.connection import WebOSClient
from asyncwebostv.controls import (
MediaControl, SystemControl, ApplicationControl, TvControl, InputControl, SourceControl
)
async def main():
# Create a WebOS client
client = WebOSClient("192.168.1.100") # Replace with your TV's IP
# Connect to TV
await client.connect()
# Register with the TV (if needed)
store = {} # Dictionary to receive the client key
async for status in client.register(store):
if status == WebOSClient.PROMPTED:
print("Please accept the connection on your TV")
elif status == WebOSClient.REGISTERED:
print(f"Registration successful, client key: {store.get('client_key')}")
# Use the client key for future sessions to avoid re-pairing
# client_key = store.get("client_key")
# Create control interfaces
media = MediaControl(client)
system = SystemControl(client)
# Control TV
await media.volume_up()
await system.notify("Hello from AsyncWebOSTV!")
# Close connection
await client.close()
asyncio.run(main())
Secure Connections
AsyncWebOSTV supports secure SSL/TLS connections to WebOS TVs. The library provides two classes for secure connections:
SecureWebOSClient
Low-level secure client with enhanced SSL certificate handling:
import asyncio
from asyncwebostv import SecureWebOSClient, extract_certificate
async def main():
# Extract and save certificate from TV
cert_file = "tv_cert.pem"
await extract_certificate("192.168.1.100", 3001, cert_file)
# Create secure client with certificate verification
client = SecureWebOSClient(
host="192.168.1.100",
port=3001,
secure=True,
cert_file=cert_file,
verify_ssl=True,
client_key="your-client-key" # Optional
)
# Connect and use as normal
await client.connect()
# Close connection
await client.close()
asyncio.run(main())
SecureWebOSTV
High-level secure client with SSL certificate handling:
import asyncio
from asyncwebostv import SecureWebOSTV
async def main():
# Create secure TV client
tv = SecureWebOSTV(
host="192.168.1.100",
port=3001,
cert_file="tv_cert.pem", # Optional
verify_ssl=True # Set to False to skip verification
)
# Extract and save certificate
# await tv.get_certificate("tv_cert.pem")
# Connect and register if needed
await tv.connect()
if not tv.client_key:
client_key = await tv.register()
# Now use the client property to access lower-level API
client = tv.client
# Close connection
await tv.close()
asyncio.run(main())
Certificate Utilities
The library includes utility functions for working with TV certificates:
from asyncwebostv import extract_certificate, verify_certificate
# Extract certificate from TV
cert_pem = await extract_certificate("192.168.1.100", 3001, "tv_cert.pem")
# Verify if a saved certificate matches the current one on the TV
matches = await verify_certificate("tv_cert.pem", "192.168.1.100", 3001)
Client Key Management
Unlike some other libraries, AsyncWebOSTV does not save client keys to disk by default. Instead, it returns the client key to the caller through a provided dictionary.
# During registration
store = {}
async for status in client.register(store):
pass
# After registration, the client key is in the store dictionary
client_key = store.get("client_key")
print(f"Your client key: {client_key}")
# Save it however you want (database, config file, etc.)
For subsequent connections, you can provide the client key directly:
client = WebOSClient("192.168.1.100", client_key="your-client-key")
This approach gives you more control over how client keys are stored and managed in your application.
Documentation
For detailed documentation, please visit our documentation page.
Development
- Clone the repository:
git clone https://github.com/yourusername/asyncwebostv.git
cd asyncwebostv
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
- Format code:
black .
isort .
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Original
pywebostvlibrary for inspiration - LG for their WebOS platform
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncwebostv-0.2.7.tar.gz.
File metadata
- Download URL: asyncwebostv-0.2.7.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96a9f2d9f562ffff0ae34e8db4c46f257c76ed4ba581a7229f04dd8de6cf0d15
|
|
| MD5 |
bc1fd87c5f97f787b53a6cb8838783c2
|
|
| BLAKE2b-256 |
12bb137db8b597e5b470b3df367285cdc3b796fb70f234bba5973c54914362cf
|
Provenance
The following attestation bundles were made for asyncwebostv-0.2.7.tar.gz:
Publisher:
release.yml on droman42/asyncwebostv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asyncwebostv-0.2.7.tar.gz -
Subject digest:
96a9f2d9f562ffff0ae34e8db4c46f257c76ed4ba581a7229f04dd8de6cf0d15 - Sigstore transparency entry: 233069061
- Sigstore integration time:
-
Permalink:
droman42/asyncwebostv@46affbd7cf0bfc4b99e762cd9daffadec202fc28 -
Branch / Tag:
refs/tags/v0.2.7 - Owner: https://github.com/droman42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46affbd7cf0bfc4b99e762cd9daffadec202fc28 -
Trigger Event:
push
-
Statement type:
File details
Details for the file asyncwebostv-0.2.7-py3-none-any.whl.
File metadata
- Download URL: asyncwebostv-0.2.7-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae3c58bf30c76829f59ae796efae3d9c0a8627d7c09ee94d43f145c6f6f8859d
|
|
| MD5 |
5323e1001e6f6e909c3029cc977bf6df
|
|
| BLAKE2b-256 |
1ce98b1bdbe6b211e98b2510bfa913809dd58f228a96293446f494c94bd2ba58
|
Provenance
The following attestation bundles were made for asyncwebostv-0.2.7-py3-none-any.whl:
Publisher:
release.yml on droman42/asyncwebostv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asyncwebostv-0.2.7-py3-none-any.whl -
Subject digest:
ae3c58bf30c76829f59ae796efae3d9c0a8627d7c09ee94d43f145c6f6f8859d - Sigstore transparency entry: 233069065
- Sigstore integration time:
-
Permalink:
droman42/asyncwebostv@46affbd7cf0bfc4b99e762cd9daffadec202fc28 -
Branch / Tag:
refs/tags/v0.2.7 - Owner: https://github.com/droman42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46affbd7cf0bfc4b99e762cd9daffadec202fc28 -
Trigger Event:
push
-
Statement type: