Skip to main content

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.0a4 — connect/handshake, StartNotifyStates, GetCapabilities, get_states, ExecCommandWithAuth (fresh GetSessionRandom per write), and nonce-gated TV read_application_list / read_resource (AES-GCM; needs session_key + [crypto]).

See CHANGELOG.md for release history.

Install

pip install pybravia-connect==0.1.0a4

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 (
    BraviaConnectClient,
    DEFAULT_THEATRE_PORT,
    async_complete_oauth_flow,
    start_oauth_login,
    select_device,
    discover_grpc_port,
)

Sync gRPC client (run in an executor from asyncio). Async credentials use aiohttp.ClientSession.

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:

  1. Make the pb2_grpc import relative: from . import bravia_control_pb2.
  2. 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

  1. Bump __version__ in src/pybravia_connect/__init__.py (single source of truth).
  2. Move [Unreleased] notes into a new CHANGELOG.md section for that version.
  3. Commit, push to main, then tag and push:
    git tag vX.Y.ZaN
    git push origin vX.Y.ZaN
    
  4. 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.
  5. Bump the pin in consumer integrations (for example bravia-quad-homeassistant custom_components/bravia_quad/manifest.json and lockfile) in a separate change.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybravia_connect-0.1.0a4.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybravia_connect-0.1.0a4-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file pybravia_connect-0.1.0a4.tar.gz.

File metadata

  • Download URL: pybravia_connect-0.1.0a4.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pybravia_connect-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 b59081e74b4c1f11c486f74e259545ae7f3a735f5c1821be3199cc62e86e2ee6
MD5 941d74ae072159efd4c83ddca75b4d7c
BLAKE2b-256 bc58335f9ea9d1ca07c1363c39ac6a5616866e0c53643cf7bcfbdb0785379918

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybravia_connect-0.1.0a4.tar.gz:

Publisher: publish.yml on steamEngineer/pybravia-connect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybravia_connect-0.1.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for pybravia_connect-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 bc56960c51eac8cd48960cf2bdd991e5e7bccf229690d70f6a994b4d4280c504
MD5 119111e44c2e4f8e86259a9cbbaf6b0d
BLAKE2b-256 5a046bde2fed63b98af0491b751ef1b512fd13232dcdcd948b726e253e95490d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybravia_connect-0.1.0a4-py3-none-any.whl:

Publisher: publish.yml on steamEngineer/pybravia-connect

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page