pybravia-connect 0.1.0a3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. pybravia_connect-0.1.0a3/.github/workflows/ci.yml +27 -0
  2. pybravia_connect-0.1.0a3/.github/workflows/publish.yml +30 -0
  3. pybravia_connect-0.1.0a3/.gitignore +15 -0
  4. pybravia_connect-0.1.0a3/LICENSE +21 -0
  5. pybravia_connect-0.1.0a3/PKG-INFO +115 -0
  6. pybravia_connect-0.1.0a3/README.md +96 -0
  7. pybravia_connect-0.1.0a3/pyproject.toml +49 -0
  8. pybravia_connect-0.1.0a3/src/pybravia_connect/__init__.py +70 -0
  9. pybravia_connect-0.1.0a3/src/pybravia_connect/client.py +492 -0
  10. pybravia_connect-0.1.0a3/src/pybravia_connect/credentials.py +586 -0
  11. pybravia_connect-0.1.0a3/src/pybravia_connect/discovery.py +91 -0
  12. pybravia_connect-0.1.0a3/src/pybravia_connect/exceptions.py +38 -0
  13. pybravia_connect-0.1.0a3/src/pybravia_connect/proto/__init__.py +1 -0
  14. pybravia_connect-0.1.0a3/src/pybravia_connect/proto/bravia_control.proto +46 -0
  15. pybravia_connect-0.1.0a3/src/pybravia_connect/proto/bravia_control_pb2.py +51 -0
  16. pybravia_connect-0.1.0a3/src/pybravia_connect/proto/bravia_control_pb2_grpc.py +183 -0
  17. pybravia_connect-0.1.0a3/src/pybravia_connect/py.typed +0 -0
  18. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/__init__.py +1 -0
  19. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/application_list.py +133 -0
  20. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/capabilities.py +269 -0
  21. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/codec.py +104 -0
  22. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/exec_command.py +177 -0
  23. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/get_nonce.py +30 -0
  24. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/get_states_auth.py +92 -0
  25. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/get_states_request.py +135 -0
  26. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/get_states_response.py +145 -0
  27. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/notify.py +122 -0
  28. pybravia_connect-0.1.0a3/src/pybravia_connect/wire/resources.py +85 -0
  29. pybravia_connect-0.1.0a3/tests/pb_helpers.py +22 -0
  30. pybravia_connect-0.1.0a3/tests/test_application_list.py +77 -0
  31. pybravia_connect-0.1.0a3/tests/test_capabilities.py +61 -0
  32. pybravia_connect-0.1.0a3/tests/test_credentials.py +119 -0
  33. pybravia_connect-0.1.0a3/tests/test_discovery.py +62 -0
  34. pybravia_connect-0.1.0a3/tests/test_exec_command.py +66 -0
  35. pybravia_connect-0.1.0a3/tests/test_exec_serialize.py +44 -0
  36. pybravia_connect-0.1.0a3/tests/test_get_states_client.py +46 -0
  37. pybravia_connect-0.1.0a3/tests/test_get_states_response.py +49 -0
  38. pybravia_connect-0.1.0a3/tests/test_get_states_tokens.py +62 -0
  39. pybravia_connect-0.1.0a3/tests/test_notify_decode.py +64 -0
  40. pybravia_connect-0.1.0a3/tests/test_resources.py +59 -0
  41. pybravia_connect-0.1.0a3/tests/test_smoke.py +12 -0
  42. pybravia_connect-0.1.0a3/tools/live_smoke.py +138 -0
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ check:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: "3.13"
16
+
17
+ - name: Install package and dev tools
18
+ run: pip install -e ".[dev]"
19
+
20
+ - name: Ruff lint
21
+ run: ruff check .
22
+
23
+ - name: Ruff format
24
+ run: ruff format --check .
25
+
26
+ - name: Tests
27
+ run: pytest -q
@@ -0,0 +1,30 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ environment: pypi
13
+ permissions:
14
+ id-token: write
15
+ contents: read
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.13"
22
+
23
+ - name: Install build tools
24
+ run: pip install build
25
+
26
+ - name: Build package
27
+ run: python -m build
28
+
29
+ - name: Publish to PyPI
30
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,15 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ .eggs/
7
+ dist/
8
+ build/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+ .mypy_cache/
14
+ .tox/
15
+ *.egg
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 steamEngineer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: pybravia-connect
3
+ Version: 0.1.0a3
4
+ Summary: HA-agnostic Sony BRAVIA Connect ControlDeviceService client
5
+ Author: steamEngineer
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: aiohttp>=3.9
10
+ Requires-Dist: grpcio>=1.76.0
11
+ Requires-Dist: protobuf<7,>=5
12
+ Provides-Extra: crypto
13
+ Requires-Dist: cryptography>=42; extra == 'crypto'
14
+ Provides-Extra: dev
15
+ Requires-Dist: cryptography>=42; extra == 'dev'
16
+ Requires-Dist: pytest>=8.0; extra == 'dev'
17
+ Requires-Dist: ruff>=0.9; extra == 'dev'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pybravia-connect
21
+
22
+ HA-agnostic Python client for Sony BRAVIA Connect local gRPC
23
+ (`ControlDeviceService`).
24
+
25
+ This is a **protocol library**, not a Home Assistant integration. Integrations
26
+ that speak BRAVIA Connect (for example
27
+ [bravia-quad-homeassistant](https://github.com/steamEngineer/bravia-quad-homeassistant)
28
+ and
29
+ [bravia-tv-grpc-homeassistant](https://github.com/braviafanboy/bravia-tv-grpc-homeassistant))
30
+ can depend on this package once cut over.
31
+
32
+ Protocol code was extracted from those integrations (MIT). Thanks to
33
+ @steamEngineer and @braviafanboy.
34
+
35
+ ## Status
36
+
37
+ `0.1.0a3` — connect/handshake, `StartNotifyStates`, `GetCapabilities`,
38
+ `get_states`, `ExecCommandWithAuth` (fresh `GetSessionRandom` per write), and
39
+ nonce-gated TV `read_application_list` / `read_resource` (AES-GCM; needs
40
+ `session_key` + `[crypto]`).
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install pybravia-connect==0.1.0a3
46
+ ```
47
+
48
+ For local development:
49
+
50
+ ```bash
51
+ pip install -e ".[dev]"
52
+ ```
53
+
54
+ For TV app-list and icon reads (AES-GCM decrypt):
55
+
56
+ ```bash
57
+ pip install "pybravia-connect[crypto]"
58
+ ```
59
+
60
+ ## Public API (sketch)
61
+
62
+ ```python
63
+ from pybravia_connect import (
64
+ BraviaConnectClient,
65
+ DEFAULT_THEATRE_PORT,
66
+ async_complete_oauth_flow,
67
+ start_oauth_login,
68
+ select_device,
69
+ discover_grpc_port,
70
+ )
71
+ ```
72
+
73
+ Sync gRPC client (run in an executor from asyncio). Async credentials use
74
+ `aiohttp.ClientSession`.
75
+
76
+ ## Live smoke
77
+
78
+ ```bash
79
+ export BRAVIA_HOST=192.168.x.x
80
+ export BRAVIA_PORT=55051 # Theatre default; TVs may need discovery
81
+ export BRAVIA_CREDENTIALS=/path/to/keys.json
82
+ python tools/live_smoke.py
83
+ ```
84
+
85
+ Validated on HT-A9M2: connect/handshake, GetCapabilities, StartNotifyStates,
86
+ `get_states`, and volume writes via `exec_command` while powered on. Volume/mute
87
+ writes are no-ops when the control unit is off — live smoke wakes `power` first.
88
+ Stop any Home Assistant `bravia_quad` session on the same device before smoke
89
+ (dual `key_id` sessions flake).
90
+
91
+ ## Regenerating protobuf stubs
92
+
93
+ ```bash
94
+ python -m grpc_tools.protoc -Isrc/pybravia_connect/proto \
95
+ --python_out=src/pybravia_connect/proto \
96
+ --grpc_python_out=src/pybravia_connect/proto \
97
+ src/pybravia_connect/proto/bravia_control.proto
98
+ ```
99
+
100
+ Then re-apply two manual patches:
101
+
102
+ 1. Make the `pb2_grpc` import relative: `from . import bravia_control_pb2`.
103
+ 2. Register the descriptor in a **private** pool, not the global `Default()` one
104
+ (`_pool = DescriptorPool()` / `DESCRIPTOR = _pool.AddSerializedFile(...)`).
105
+ This avoids symbol collisions when co-installed with integrations that still
106
+ vendor their own stubs.
107
+
108
+ ## Development
109
+
110
+ ```bash
111
+ python3 -m venv .venv && source .venv/bin/activate
112
+ pip install -e ".[dev]"
113
+ ruff check . && ruff format --check .
114
+ pytest -q
115
+ ```
@@ -0,0 +1,96 @@
1
+ # pybravia-connect
2
+
3
+ HA-agnostic Python client for Sony BRAVIA Connect local gRPC
4
+ (`ControlDeviceService`).
5
+
6
+ This is a **protocol library**, not a Home Assistant integration. Integrations
7
+ that speak BRAVIA Connect (for example
8
+ [bravia-quad-homeassistant](https://github.com/steamEngineer/bravia-quad-homeassistant)
9
+ and
10
+ [bravia-tv-grpc-homeassistant](https://github.com/braviafanboy/bravia-tv-grpc-homeassistant))
11
+ can depend on this package once cut over.
12
+
13
+ Protocol code was extracted from those integrations (MIT). Thanks to
14
+ @steamEngineer and @braviafanboy.
15
+
16
+ ## Status
17
+
18
+ `0.1.0a3` — connect/handshake, `StartNotifyStates`, `GetCapabilities`,
19
+ `get_states`, `ExecCommandWithAuth` (fresh `GetSessionRandom` per write), and
20
+ nonce-gated TV `read_application_list` / `read_resource` (AES-GCM; needs
21
+ `session_key` + `[crypto]`).
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install pybravia-connect==0.1.0a3
27
+ ```
28
+
29
+ For local development:
30
+
31
+ ```bash
32
+ pip install -e ".[dev]"
33
+ ```
34
+
35
+ For TV app-list and icon reads (AES-GCM decrypt):
36
+
37
+ ```bash
38
+ pip install "pybravia-connect[crypto]"
39
+ ```
40
+
41
+ ## Public API (sketch)
42
+
43
+ ```python
44
+ from pybravia_connect import (
45
+ BraviaConnectClient,
46
+ DEFAULT_THEATRE_PORT,
47
+ async_complete_oauth_flow,
48
+ start_oauth_login,
49
+ select_device,
50
+ discover_grpc_port,
51
+ )
52
+ ```
53
+
54
+ Sync gRPC client (run in an executor from asyncio). Async credentials use
55
+ `aiohttp.ClientSession`.
56
+
57
+ ## Live smoke
58
+
59
+ ```bash
60
+ export BRAVIA_HOST=192.168.x.x
61
+ export BRAVIA_PORT=55051 # Theatre default; TVs may need discovery
62
+ export BRAVIA_CREDENTIALS=/path/to/keys.json
63
+ python tools/live_smoke.py
64
+ ```
65
+
66
+ Validated on HT-A9M2: connect/handshake, GetCapabilities, StartNotifyStates,
67
+ `get_states`, and volume writes via `exec_command` while powered on. Volume/mute
68
+ writes are no-ops when the control unit is off — live smoke wakes `power` first.
69
+ Stop any Home Assistant `bravia_quad` session on the same device before smoke
70
+ (dual `key_id` sessions flake).
71
+
72
+ ## Regenerating protobuf stubs
73
+
74
+ ```bash
75
+ python -m grpc_tools.protoc -Isrc/pybravia_connect/proto \
76
+ --python_out=src/pybravia_connect/proto \
77
+ --grpc_python_out=src/pybravia_connect/proto \
78
+ src/pybravia_connect/proto/bravia_control.proto
79
+ ```
80
+
81
+ Then re-apply two manual patches:
82
+
83
+ 1. Make the `pb2_grpc` import relative: `from . import bravia_control_pb2`.
84
+ 2. Register the descriptor in a **private** pool, not the global `Default()` one
85
+ (`_pool = DescriptorPool()` / `DESCRIPTOR = _pool.AddSerializedFile(...)`).
86
+ This avoids symbol collisions when co-installed with integrations that still
87
+ vendor their own stubs.
88
+
89
+ ## Development
90
+
91
+ ```bash
92
+ python3 -m venv .venv && source .venv/bin/activate
93
+ pip install -e ".[dev]"
94
+ ruff check . && ruff format --check .
95
+ pytest -q
96
+ ```
@@ -0,0 +1,49 @@
1
+ [project]
2
+ name = "pybravia-connect"
3
+ version = "0.1.0a3"
4
+ description = "HA-agnostic Sony BRAVIA Connect ControlDeviceService client"
5
+ readme = "README.md"
6
+ license = { text = "MIT" }
7
+ requires-python = ">=3.12"
8
+ authors = [{ name = "steamEngineer" }]
9
+ dependencies = [
10
+ "grpcio>=1.76.0",
11
+ "protobuf>=5,<7",
12
+ "aiohttp>=3.9",
13
+ ]
14
+
15
+ [project.optional-dependencies]
16
+ crypto = ["cryptography>=42"]
17
+ dev = [
18
+ "pytest>=8.0",
19
+ "ruff>=0.9",
20
+ "cryptography>=42",
21
+ ]
22
+
23
+ [build-system]
24
+ requires = ["hatchling"]
25
+ build-backend = "hatchling.build"
26
+
27
+ [tool.hatch.build.targets.wheel]
28
+ packages = ["src/pybravia_connect"]
29
+
30
+ [tool.ruff]
31
+ target-version = "py312"
32
+ line-length = 88
33
+ extend-exclude = [
34
+ "src/pybravia_connect/proto/bravia_control_pb2.py",
35
+ "src/pybravia_connect/proto/bravia_control_pb2_grpc.py",
36
+ ]
37
+
38
+ [tool.ruff.lint]
39
+ select = ["E", "F", "W", "I", "UP", "B", "C4", "SIM"]
40
+
41
+ [tool.ruff.lint.isort]
42
+ force-sort-within-sections = true
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ pythonpath = ["src", "tests"]
47
+ markers = [
48
+ "live: live device smoke tests (deselect with '-m \"not live\"')",
49
+ ]
@@ -0,0 +1,70 @@
1
+ """Sony BRAVIA Connect local gRPC protocol client (HA-agnostic)."""
2
+
3
+ from .client import BraviaConnectClient
4
+ from .credentials import (
5
+ async_complete_oauth_flow,
6
+ async_refresh_credentials,
7
+ build_authorization_url,
8
+ build_credentials_bundle,
9
+ credentials_to_json,
10
+ device_hardware_info,
11
+ generate_pkce_pair,
12
+ keys_need_refresh,
13
+ parse_authorization_code,
14
+ parse_credentials_json,
15
+ parse_oauth_redirect_state,
16
+ select_device,
17
+ select_speaker_device,
18
+ select_tv_device,
19
+ start_oauth_login,
20
+ )
21
+ from .discovery import (
22
+ DEFAULT_THEATRE_PORT,
23
+ discover_grpc_port,
24
+ is_control_device_service,
25
+ scan_open_ports,
26
+ )
27
+ from .exceptions import (
28
+ AuthError,
29
+ BraviaConnectError,
30
+ ConnectionError,
31
+ CredentialsError,
32
+ CredentialsRefreshError,
33
+ DeviceSelectError,
34
+ OAuthError,
35
+ )
36
+ from .wire.capabilities import CapabilityMeta
37
+
38
+ __version__ = "0.1.0a3"
39
+
40
+ __all__ = [
41
+ "DEFAULT_THEATRE_PORT",
42
+ "AuthError",
43
+ "BraviaConnectClient",
44
+ "BraviaConnectError",
45
+ "CapabilityMeta",
46
+ "ConnectionError",
47
+ "CredentialsError",
48
+ "CredentialsRefreshError",
49
+ "DeviceSelectError",
50
+ "OAuthError",
51
+ "__version__",
52
+ "async_complete_oauth_flow",
53
+ "async_refresh_credentials",
54
+ "build_authorization_url",
55
+ "build_credentials_bundle",
56
+ "credentials_to_json",
57
+ "device_hardware_info",
58
+ "discover_grpc_port",
59
+ "generate_pkce_pair",
60
+ "is_control_device_service",
61
+ "keys_need_refresh",
62
+ "parse_authorization_code",
63
+ "parse_credentials_json",
64
+ "parse_oauth_redirect_state",
65
+ "scan_open_ports",
66
+ "select_device",
67
+ "select_speaker_device",
68
+ "select_tv_device",
69
+ "start_oauth_login",
70
+ ]