HA-agnostic Sony BRAVIA Connect ControlDeviceService client
Project description
pybravia-connect
HA-agnostic Python client for Sony BRAVIA Connect local gRPC
(ControlDeviceService).
This is a protocol library, not a Home Assistant integration. Integrations that speak BRAVIA Connect (for example bravia-quad-homeassistant and bravia-tv-grpc-homeassistant) can depend on this package once cut over.
Protocol code was extracted from those integrations (MIT). Thanks to @steamEngineer and @braviafanboy.
Status
0.1.0a8 — connect/handshake, StartNotifyStates, GetCapabilities,
get_capabilities_json, session_snapshot, get_states,
ExecCommandWithAuth (fresh GetSessionRandom per write), and nonce-gated TV
read_application_list / read_resource (AES-GCM; needs session_key +
[crypto]). Public root also re-exports OAuth/Seeds helpers (including sync
complete_oauth_flow / load_credentials / write_credentials), capability
helpers, and TV constants used by HA consumers.
See CHANGELOG.md for release history.
Install
pip install pybravia-connect==0.1.0a8
For local development:
pip install -e ".[dev]"
pre-commit install # optional local hooks; CI is the source of truth
For TV app-list and icon reads (AES-GCM decrypt):
pip install "pybravia-connect[crypto]"
Public API (sketch)
from pybravia_connect import (
APPLICATION_LIST_PATH,
BraviaConnectClient,
DEFAULT_THEATRE_PORT,
ZEROCONF_TYPE,
async_complete_oauth_flow,
async_credentials_from_oauth,
async_exchange_oauth_redirect,
async_get_device_states,
async_get_devices,
async_list_oauth_devices,
async_refresh_access_token,
complete_oauth_flow,
discover_grpc_port,
enum_values_from_capability,
get_device_states,
get_devices,
get_session_keys,
image_content_type,
int_range_from_capability,
is_int_capability,
load_credentials,
refresh_access_token,
refresh_credentials,
select_device,
start_oauth_login,
write_credentials,
)
client.get_capabilities_json() # parsed GetCapabilities JSON (or None)
client.session_snapshot() # connected + handshake flags for debug
Sync gRPC client (run in an executor from asyncio). Async credentials use
aiohttp.ClientSession. Sync Seeds helpers (complete_oauth_flow,
refresh_credentials, get_devices, …) are for scripts; prefer the
async_* variants from HA.
CLI session keys
OAuth login and write a credentials JSON for local gRPC (never commit the output):
python tools/get_session_keys.py --login --open -o /tmp/session_keys.json
Also supports --code, --token, --refresh -i …, and --from-har (Chrome
HAR + --code-verifier).
Live smoke
export BRAVIA_HOST=192.168.x.x
export BRAVIA_PORT=55051 # Theatre default; TVs may need discovery
export BRAVIA_CREDENTIALS=/path/to/keys.json
python tools/live_smoke.py
Validated on HT-A9M2: connect/handshake, GetCapabilities, StartNotifyStates,
get_states, and volume writes via exec_command while powered on. Volume/mute
writes are no-ops when the control unit is off — live smoke wakes power first.
Stop any Home Assistant bravia_quad session on the same device before smoke
(dual key_id sessions flake).
Regenerating protobuf stubs
python -m grpc_tools.protoc -Isrc/pybravia_connect/proto \
--python_out=src/pybravia_connect/proto \
--grpc_python_out=src/pybravia_connect/proto \
src/pybravia_connect/proto/bravia_control.proto
Then re-apply two manual patches:
- Make the
pb2_grpcimport relative:from . import bravia_control_pb2. - Register the descriptor in a private pool, not the global
Default()one (_pool = DescriptorPool()/DESCRIPTOR = _pool.AddSerializedFile(...)). This avoids symbol collisions when co-installed with integrations that still vendor their own stubs.
Development
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
ruff check . && ruff format --check .
mypy
pytest -q
python -m build && twine check dist/*
Releasing
- Bump
__version__insrc/pybravia_connect/__init__.py(single source of truth). - Move
[Unreleased]notes into a newCHANGELOG.mdsection for that version. - Commit, push to
main, then tag and push:git tag vX.Y.ZaN git push origin vX.Y.ZaN
- The Publish workflow builds, checks that the tag matches the wheel version, uploads to PyPI via Trusted Publishing, and creates a GitHub Release from the changelog section.
- Bump the pin in consumer integrations (for example
bravia-quad-homeassistantcustom_components/bravia_quad/manifest.jsonand lockfile) in a separate change.
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 pybravia_connect-0.1.0a8.tar.gz.
File metadata
- Download URL: pybravia_connect-0.1.0a8.tar.gz
- Upload date:
- Size: 43.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e41b29227e40c22c45a78692811b9ee62bb6a31226895ebaf170dd9116257ac
|
|
| MD5 |
53608c230514f8dd0ab9e60f61a25768
|
|
| BLAKE2b-256 |
f4993e5db5a7cf1814db37525fe3649eeecb9aa7eb2518f5d0cedc86494c31c2
|
Provenance
The following attestation bundles were made for pybravia_connect-0.1.0a8.tar.gz:
Publisher:
publish.yml on steamEngineer/pybravia-connect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybravia_connect-0.1.0a8.tar.gz -
Subject digest:
8e41b29227e40c22c45a78692811b9ee62bb6a31226895ebaf170dd9116257ac - Sigstore transparency entry: 2254753895
- Sigstore integration time:
-
Permalink:
steamEngineer/pybravia-connect@9f2777d9f0f2755f2564c234937397d8be1c840f -
Branch / Tag:
refs/tags/v0.1.0a8 - Owner: https://github.com/steamEngineer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9f2777d9f0f2755f2564c234937397d8be1c840f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pybravia_connect-0.1.0a8-py3-none-any.whl.
File metadata
- Download URL: pybravia_connect-0.1.0a8-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16dff3d4923e65f01c802858b143ee93325e0a7a0d3dbe2e099e3d8a9d6b18bf
|
|
| MD5 |
e93506583ca03553f52a0dbeb3ae9cee
|
|
| BLAKE2b-256 |
11ad9e6cb8f10707f45ffe1c1bd3302cf303e95676945ef361e1738b9d1ccc63
|
Provenance
The following attestation bundles were made for pybravia_connect-0.1.0a8-py3-none-any.whl:
Publisher:
publish.yml on steamEngineer/pybravia-connect
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybravia_connect-0.1.0a8-py3-none-any.whl -
Subject digest:
16dff3d4923e65f01c802858b143ee93325e0a7a0d3dbe2e099e3d8a9d6b18bf - Sigstore transparency entry: 2254753952
- Sigstore integration time:
-
Permalink:
steamEngineer/pybravia-connect@9f2777d9f0f2755f2564c234937397d8be1c840f -
Branch / Tag:
refs/tags/v0.1.0a8 - Owner: https://github.com/steamEngineer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9f2777d9f0f2755f2564c234937397d8be1c840f -
Trigger Event:
push
-
Statement type: