androidtvremote2 0.0.13__tar.gz → 0.0.15__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.
- {androidtvremote2-0.0.13/src/androidtvremote2.egg-info → androidtvremote2-0.0.15}/PKG-INFO +18 -16
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/README.md +13 -14
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/pyproject.toml +2 -2
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/androidtv_remote.py +18 -18
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/base.py +2 -2
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/certificate_generator.py +3 -3
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/const.py +1 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/pairing.py +12 -11
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/polo_pb2.py +28 -27
- androidtvremote2-0.0.15/src/androidtvremote2/polo_pb2.pyi +287 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/remote.py +12 -10
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/remotemessage_pb2.py +54 -53
- androidtvremote2-0.0.15/src/androidtvremote2/remotemessage_pb2.pyi +2253 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15/src/androidtvremote2.egg-info}/PKG-INFO +18 -16
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2.egg-info/SOURCES.txt +2 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/demo.py +19 -19
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/tests/test_androidtv_remote.py +1 -1
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/LICENSE +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/setup.cfg +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/__init__.py +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/exceptions.py +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2.egg-info/dependency_links.txt +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2.egg-info/requires.txt +0 -0
- {androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2.egg-info/top_level.txt +0 -0
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: androidtvremote2
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.15
|
|
4
4
|
Summary: A Python library for interacting with Android TV using the Android TV Remote protocol v2
|
|
5
5
|
Author-email: tronikos <tronikos@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/tronikos/androidtvremote2
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/tronikos/androidtvremote2/issues
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiofiles>=0.8
|
|
13
|
+
Requires-Dist: cryptography>=3
|
|
14
|
+
Requires-Dist: protobuf>=4.21
|
|
12
15
|
|
|
13
16
|
# androidtvremote2
|
|
14
17
|
|
|
15
18
|
A Python library for interacting with Android TV using the Android TV Remote protocol v2. This is the same protocol the Google TV mobile app is using. It doesn't require ADB or enabling developer tools on the Android TV device. It only requires the [Android TV Remote Service](https://play.google.com/store/apps/details?id=com.google.android.tv.remote.service) that comes pre-installed on most Android TV devices.
|
|
16
19
|
|
|
17
20
|
For a list of the most common commands you can send to the Android TV see: [TvKeys](https://github.com/tronikos/androidtvremote2/blob/main/TvKeys.txt).
|
|
18
|
-
For a full list see [here](https://github.com/tronikos/androidtvremote2/blob/
|
|
19
|
-
In addition to commands you can send URLs to open apps registered to handle them.
|
|
21
|
+
For a full list see [here](https://github.com/tronikos/androidtvremote2/blob/b4c49ac03043b1b9c40c2f2960e466d5a3b8bd67/src/androidtvremote2/remotemessage.proto#L90).
|
|
22
|
+
In addition to commands you can send URLs to open apps registered to handle them. See [this guide](https://community.home-assistant.io/t/android-tv-remote-app-links-deep-linking-guide/567921) for how to find deep links for apps.
|
|
20
23
|
|
|
21
24
|
## Credits
|
|
22
25
|
|
|
@@ -44,18 +47,17 @@ python -m pip install --upgrade pip
|
|
|
44
47
|
python -m pip install .
|
|
45
48
|
|
|
46
49
|
# Generate *_pb2.py from *.proto
|
|
47
|
-
python -m pip install grpcio-tools
|
|
48
|
-
python -m grpc_tools.protoc src/androidtvremote2/*.proto --python_out=src/androidtvremote2 -Isrc/androidtvremote2
|
|
49
|
-
|
|
50
|
-
# Run
|
|
51
|
-
python -m pip install
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
python -m pip install flake8 ruff
|
|
57
|
-
flake8 .
|
|
58
|
-
ruff .
|
|
50
|
+
python -m pip install grpcio-tools mypy-protobuf
|
|
51
|
+
python -m grpc_tools.protoc src/androidtvremote2/*.proto --python_out=src/androidtvremote2 --mypy_out=src/androidtvremote2 -Isrc/androidtvremote2
|
|
52
|
+
|
|
53
|
+
# Run pre-commit
|
|
54
|
+
python -m pip install pre-commit
|
|
55
|
+
pre-commit install
|
|
56
|
+
pre-commit run --all-files
|
|
57
|
+
|
|
58
|
+
# Alternative: run formatter, lint, and type checking
|
|
59
|
+
python -m pip install isort black flake8 ruff mypy
|
|
60
|
+
isort . ; black . ; flake8 . ; ruff . --fix ; mypy --install-types .
|
|
59
61
|
|
|
60
62
|
# Run tests
|
|
61
63
|
python -m pip install pytest
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
A Python library for interacting with Android TV using the Android TV Remote protocol v2. This is the same protocol the Google TV mobile app is using. It doesn't require ADB or enabling developer tools on the Android TV device. It only requires the [Android TV Remote Service](https://play.google.com/store/apps/details?id=com.google.android.tv.remote.service) that comes pre-installed on most Android TV devices.
|
|
4
4
|
|
|
5
5
|
For a list of the most common commands you can send to the Android TV see: [TvKeys](https://github.com/tronikos/androidtvremote2/blob/main/TvKeys.txt).
|
|
6
|
-
For a full list see [here](https://github.com/tronikos/androidtvremote2/blob/
|
|
7
|
-
In addition to commands you can send URLs to open apps registered to handle them.
|
|
6
|
+
For a full list see [here](https://github.com/tronikos/androidtvremote2/blob/b4c49ac03043b1b9c40c2f2960e466d5a3b8bd67/src/androidtvremote2/remotemessage.proto#L90).
|
|
7
|
+
In addition to commands you can send URLs to open apps registered to handle them. See [this guide](https://community.home-assistant.io/t/android-tv-remote-app-links-deep-linking-guide/567921) for how to find deep links for apps.
|
|
8
8
|
|
|
9
9
|
## Credits
|
|
10
10
|
|
|
@@ -32,18 +32,17 @@ python -m pip install --upgrade pip
|
|
|
32
32
|
python -m pip install .
|
|
33
33
|
|
|
34
34
|
# Generate *_pb2.py from *.proto
|
|
35
|
-
python -m pip install grpcio-tools
|
|
36
|
-
python -m grpc_tools.protoc src/androidtvremote2/*.proto --python_out=src/androidtvremote2 -Isrc/androidtvremote2
|
|
37
|
-
|
|
38
|
-
# Run
|
|
39
|
-
python -m pip install
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
python -m pip install flake8 ruff
|
|
45
|
-
flake8 .
|
|
46
|
-
ruff .
|
|
35
|
+
python -m pip install grpcio-tools mypy-protobuf
|
|
36
|
+
python -m grpc_tools.protoc src/androidtvremote2/*.proto --python_out=src/androidtvremote2 --mypy_out=src/androidtvremote2 -Isrc/androidtvremote2
|
|
37
|
+
|
|
38
|
+
# Run pre-commit
|
|
39
|
+
python -m pip install pre-commit
|
|
40
|
+
pre-commit install
|
|
41
|
+
pre-commit run --all-files
|
|
42
|
+
|
|
43
|
+
# Alternative: run formatter, lint, and type checking
|
|
44
|
+
python -m pip install isort black flake8 ruff mypy
|
|
45
|
+
isort . ; black . ; flake8 . ; ruff . --fix ; mypy --install-types .
|
|
47
46
|
|
|
48
47
|
# Run tests
|
|
49
48
|
python -m pip install pytest
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "androidtvremote2"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.15"
|
|
4
4
|
license = {text = "Apache-2.0"}
|
|
5
5
|
authors = [
|
|
6
6
|
{ name="tronikos", email="tronikos@gmail.com" },
|
|
7
7
|
]
|
|
8
8
|
description = "A Python library for interacting with Android TV using the Android TV Remote protocol v2"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
11
|
dependencies = [
|
|
12
12
|
"aiofiles>=0.8",
|
|
13
13
|
"cryptography>=3",
|
{androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/androidtv_remote.py
RENAMED
|
@@ -52,7 +52,7 @@ class AndroidTVRemote:
|
|
|
52
52
|
self._pair_port = pair_port
|
|
53
53
|
self._loop = loop or asyncio.get_running_loop()
|
|
54
54
|
self._enable_ime = enable_ime
|
|
55
|
-
self._transport = None
|
|
55
|
+
self._transport: asyncio.Transport | None = None
|
|
56
56
|
self._remote_message_protocol: RemoteProtocol | None = None
|
|
57
57
|
self._pairing_message_protocol: PairingProtocol | None = None
|
|
58
58
|
self._reconnect_task: asyncio.Task | None = None
|
|
@@ -62,19 +62,19 @@ class AndroidTVRemote:
|
|
|
62
62
|
self._volume_info_updated_callbacks: list[Callable] = []
|
|
63
63
|
self._is_available_updated_callbacks: list[Callable] = []
|
|
64
64
|
|
|
65
|
-
def is_on_updated(is_on: bool):
|
|
65
|
+
def is_on_updated(is_on: bool) -> None:
|
|
66
66
|
for callback in self._is_on_updated_callbacks:
|
|
67
67
|
callback(is_on)
|
|
68
68
|
|
|
69
|
-
def current_app_updated(current_app: str):
|
|
69
|
+
def current_app_updated(current_app: str) -> None:
|
|
70
70
|
for callback in self._current_app_updated_callbacks:
|
|
71
71
|
callback(current_app)
|
|
72
72
|
|
|
73
|
-
def volume_info_updated(volume_info: dict[str, str | bool]):
|
|
73
|
+
def volume_info_updated(volume_info: dict[str, str | bool]) -> None:
|
|
74
74
|
for callback in self._volume_info_updated_callbacks:
|
|
75
75
|
callback(volume_info)
|
|
76
76
|
|
|
77
|
-
def is_available_updated(is_available: bool):
|
|
77
|
+
def is_available_updated(is_available: bool) -> None:
|
|
78
78
|
for callback in self._is_available_updated_callbacks:
|
|
79
79
|
callback(is_available)
|
|
80
80
|
|
|
@@ -105,7 +105,7 @@ class AndroidTVRemote:
|
|
|
105
105
|
return self._remote_message_protocol.device_info
|
|
106
106
|
|
|
107
107
|
@property
|
|
108
|
-
def volume_info(self) -> dict[str, str | bool] | None:
|
|
108
|
+
def volume_info(self) -> dict[str, str | bool | int] | None:
|
|
109
109
|
"""Volume info (level, max, muted)."""
|
|
110
110
|
if not self._remote_message_protocol:
|
|
111
111
|
return None
|
|
@@ -169,7 +169,7 @@ class AndroidTVRemote:
|
|
|
169
169
|
await out.write(key_pem.decode("utf-8"))
|
|
170
170
|
return True
|
|
171
171
|
|
|
172
|
-
def _create_ssl_context(self):
|
|
172
|
+
def _create_ssl_context(self) -> ssl.SSLContext:
|
|
173
173
|
if self._ssl_context:
|
|
174
174
|
return self._ssl_context
|
|
175
175
|
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
@@ -184,7 +184,7 @@ class AndroidTVRemote:
|
|
|
184
184
|
self._ssl_context = ssl_context
|
|
185
185
|
return self._ssl_context
|
|
186
186
|
|
|
187
|
-
async def async_connect(self):
|
|
187
|
+
async def async_connect(self) -> None:
|
|
188
188
|
"""Connect to an Android TV.
|
|
189
189
|
|
|
190
190
|
:raises CannotConnect: if couldn't connect, e.g. invalid IP address.
|
|
@@ -254,7 +254,7 @@ class AndroidTVRemote:
|
|
|
254
254
|
await self.async_connect()
|
|
255
255
|
self._on_is_available_updated(True)
|
|
256
256
|
break
|
|
257
|
-
except CannotConnect as exc:
|
|
257
|
+
except (CannotConnect, ConnectionClosed) as exc:
|
|
258
258
|
delay_seconds = min(2 * delay_seconds, 30)
|
|
259
259
|
LOGGER.debug(
|
|
260
260
|
"Couldn't reconnect to %s. Will retry in %s seconds. Error: %s",
|
|
@@ -316,16 +316,16 @@ class AndroidTVRemote:
|
|
|
316
316
|
# Nexus Player example:
|
|
317
317
|
# dnQualifier=fugu/fugu/Nexus Player/CN=atvremote/XX:XX:XX:XX:XX:XX
|
|
318
318
|
common_name = server_cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
|
|
319
|
-
|
|
319
|
+
common_name_str = str(common_name[0].value) if common_name else ""
|
|
320
320
|
dn_qualifier = server_cert.subject.get_attributes_for_oid(x509.OID_DN_QUALIFIER)
|
|
321
|
-
|
|
322
|
-
common_name_parts =
|
|
323
|
-
dn_qualifier_parts =
|
|
324
|
-
name = dn_qualifier_parts[-1] if
|
|
321
|
+
dn_qualifier_str = str(dn_qualifier[0].value) if dn_qualifier else ""
|
|
322
|
+
common_name_parts = common_name_str.split("/")
|
|
323
|
+
dn_qualifier_parts = dn_qualifier_str.split("/")
|
|
324
|
+
name = dn_qualifier_parts[-1] if dn_qualifier_str else common_name_parts[-2]
|
|
325
325
|
mac = common_name_parts[-1]
|
|
326
326
|
return name, mac
|
|
327
327
|
|
|
328
|
-
async def async_start_pairing(self):
|
|
328
|
+
async def async_start_pairing(self) -> None:
|
|
329
329
|
"""Start the pairing process.
|
|
330
330
|
|
|
331
331
|
:raises CannotConnect: if couldn't connect, e.g. invalid IP address.
|
|
@@ -356,7 +356,7 @@ class AndroidTVRemote:
|
|
|
356
356
|
raise CannotConnect from exc
|
|
357
357
|
await self._pairing_message_protocol.async_start_pairing()
|
|
358
358
|
|
|
359
|
-
async def async_finish_pairing(self, pairing_code: str):
|
|
359
|
+
async def async_finish_pairing(self, pairing_code: str) -> None:
|
|
360
360
|
"""Finish the pairing process.
|
|
361
361
|
|
|
362
362
|
:param pairing_code: pairing code shown on the Android TV.
|
|
@@ -371,7 +371,7 @@ class AndroidTVRemote:
|
|
|
371
371
|
|
|
372
372
|
def send_key_command(
|
|
373
373
|
self, key_code: int | str, direction: int | str = RemoteDirection.SHORT
|
|
374
|
-
):
|
|
374
|
+
) -> None:
|
|
375
375
|
"""Send a key press to Android TV.
|
|
376
376
|
|
|
377
377
|
This does not block; it buffers the data and arranges for it to be sent out asynchronously.
|
|
@@ -387,7 +387,7 @@ class AndroidTVRemote:
|
|
|
387
387
|
raise ConnectionClosed("Called send_key_command after disconnect")
|
|
388
388
|
self._remote_message_protocol.send_key_command(key_code, direction)
|
|
389
389
|
|
|
390
|
-
def send_launch_app_command(self, app_link: str):
|
|
390
|
+
def send_launch_app_command(self, app_link: str) -> None:
|
|
391
391
|
"""Launch an app on Android TV.
|
|
392
392
|
|
|
393
393
|
This does not block; it buffers the data and arranges for it to be sent out asynchronously.
|
|
@@ -6,8 +6,8 @@ import asyncio
|
|
|
6
6
|
from typing import cast
|
|
7
7
|
|
|
8
8
|
from google.protobuf import text_format
|
|
9
|
-
from google.protobuf.internal.decoder import _DecodeVarint
|
|
10
|
-
from google.protobuf.internal.encoder import _EncodeVarint
|
|
9
|
+
from google.protobuf.internal.decoder import _DecodeVarint # type: ignore[attr-defined]
|
|
10
|
+
from google.protobuf.internal.encoder import _EncodeVarint # type: ignore[attr-defined]
|
|
11
11
|
from google.protobuf.message import Message
|
|
12
12
|
|
|
13
13
|
from .const import LOGGER
|
{androidtvremote2-0.0.13 → androidtvremote2-0.0.15}/src/androidtvremote2/certificate_generator.py
RENAMED
|
@@ -15,7 +15,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
15
15
|
from cryptography.x509.oid import NameOID
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def generate_selfsigned_cert(hostname: str):
|
|
18
|
+
def generate_selfsigned_cert(hostname: str) -> tuple[bytes, bytes]:
|
|
19
19
|
"""Generate self signed certificate for a hostname.
|
|
20
20
|
|
|
21
21
|
:return: self signed certificate and public key in PEM format
|
|
@@ -28,7 +28,7 @@ def generate_selfsigned_cert(hostname: str):
|
|
|
28
28
|
name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, hostname)])
|
|
29
29
|
alt_names = [x509.DNSName(hostname)]
|
|
30
30
|
san = x509.SubjectAlternativeName(alt_names)
|
|
31
|
-
|
|
31
|
+
basic_constraints = x509.BasicConstraints(ca=True, path_length=0)
|
|
32
32
|
now = datetime.utcnow()
|
|
33
33
|
cert = (
|
|
34
34
|
x509.CertificateBuilder()
|
|
@@ -38,7 +38,7 @@ def generate_selfsigned_cert(hostname: str):
|
|
|
38
38
|
.serial_number(1000)
|
|
39
39
|
.not_valid_before(now)
|
|
40
40
|
.not_valid_after(now + timedelta(days=10 * 365))
|
|
41
|
-
.add_extension(
|
|
41
|
+
.add_extension(basic_constraints, False)
|
|
42
42
|
.add_extension(san, False)
|
|
43
43
|
.sign(key, hashes.SHA256(), default_backend())
|
|
44
44
|
)
|
|
@@ -21,7 +21,7 @@ from .exceptions import ConnectionClosed, InvalidAuth
|
|
|
21
21
|
from .polo_pb2 import Options, OuterMessage
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def _create_message():
|
|
24
|
+
def _create_message() -> OuterMessage:
|
|
25
25
|
"""Create an OuterMessage with default values."""
|
|
26
26
|
msg = OuterMessage()
|
|
27
27
|
msg.protocol_version = 2
|
|
@@ -29,10 +29,10 @@ def _create_message():
|
|
|
29
29
|
return msg
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def _get_modulus_and_exponent(cert):
|
|
32
|
+
def _get_modulus_and_exponent(cert: x509.Certificate) -> tuple[int, int]:
|
|
33
33
|
"""Extract modulus and exponent from a certificate."""
|
|
34
|
-
public_numbers = cert.public_key().public_numbers()
|
|
35
|
-
return public_numbers.n, public_numbers.e
|
|
34
|
+
public_numbers = cert.public_key().public_numbers() # type: ignore[union-attr]
|
|
35
|
+
return public_numbers.n, public_numbers.e # type: ignore[union-attr]
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class PairingProtocol(ProtobufProtocol):
|
|
@@ -65,7 +65,7 @@ class PairingProtocol(ProtobufProtocol):
|
|
|
65
65
|
self._on_pairing_started: asyncio.Future | None = None
|
|
66
66
|
self._on_pairing_finished: asyncio.Future | None = None
|
|
67
67
|
|
|
68
|
-
async def async_start_pairing(self):
|
|
68
|
+
async def async_start_pairing(self) -> None:
|
|
69
69
|
"""Start the pairing process.
|
|
70
70
|
|
|
71
71
|
:raises ConnectionClosed: if connection was lost.
|
|
@@ -81,7 +81,7 @@ class PairingProtocol(ProtobufProtocol):
|
|
|
81
81
|
finally:
|
|
82
82
|
self._on_pairing_started = None
|
|
83
83
|
|
|
84
|
-
async def async_finish_pairing(self, pairing_code: str):
|
|
84
|
+
async def async_finish_pairing(self, pairing_code: str) -> None:
|
|
85
85
|
"""Finish the pairing process.
|
|
86
86
|
|
|
87
87
|
:param pairing_code: pairing code shown on the Android TV.
|
|
@@ -130,7 +130,7 @@ class PairingProtocol(ProtobufProtocol):
|
|
|
130
130
|
finally:
|
|
131
131
|
self._on_pairing_finished = None
|
|
132
132
|
|
|
133
|
-
async def _async_wait_for_future_or_con_lost(self, future: asyncio.Future):
|
|
133
|
+
async def _async_wait_for_future_or_con_lost(self, future: asyncio.Future) -> None:
|
|
134
134
|
"""Wait for future to finish or connection to be lost."""
|
|
135
135
|
await asyncio.wait(
|
|
136
136
|
(self.on_con_lost, future), return_when=asyncio.FIRST_COMPLETED
|
|
@@ -142,13 +142,13 @@ class PairingProtocol(ProtobufProtocol):
|
|
|
142
142
|
return
|
|
143
143
|
self._raise_if_not_connected()
|
|
144
144
|
|
|
145
|
-
def _raise_if_not_connected(self):
|
|
145
|
+
def _raise_if_not_connected(self) -> None:
|
|
146
146
|
"""Raise ConnectionClosed if not connected."""
|
|
147
147
|
if self.transport is None or self.transport.is_closing():
|
|
148
148
|
LOGGER.debug("Connection has been lost, cannot pair")
|
|
149
149
|
raise ConnectionClosed("Connection has been lost")
|
|
150
150
|
|
|
151
|
-
def _handle_message(self, raw_msg: bytes):
|
|
151
|
+
def _handle_message(self, raw_msg: bytes) -> None:
|
|
152
152
|
"""Handle a message from the server."""
|
|
153
153
|
msg = OuterMessage()
|
|
154
154
|
try:
|
|
@@ -202,10 +202,11 @@ class PairingProtocol(ProtobufProtocol):
|
|
|
202
202
|
|
|
203
203
|
self._send_message(new_msg)
|
|
204
204
|
|
|
205
|
-
def _handle_error(self, exception):
|
|
205
|
+
def _handle_error(self, exception: Exception) -> None:
|
|
206
206
|
"""Handle errors during _handle_message."""
|
|
207
207
|
if self._on_pairing_started and not self._on_pairing_started.done():
|
|
208
208
|
self._on_pairing_started.set_exception(exception)
|
|
209
209
|
if self._on_pairing_finished and not self._on_pairing_finished.done():
|
|
210
210
|
self._on_pairing_finished.set_exception(exception)
|
|
211
|
-
self.transport
|
|
211
|
+
if self.transport:
|
|
212
|
+
self.transport.close()
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
3
|
# source: polo.proto
|
|
4
4
|
"""Generated protocol buffer code."""
|
|
5
|
-
from google.protobuf.internal import builder as _builder
|
|
6
5
|
from google.protobuf import descriptor as _descriptor
|
|
7
6
|
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
8
7
|
from google.protobuf import symbol_database as _symbol_database
|
|
8
|
+
from google.protobuf.internal import builder as _builder
|
|
9
9
|
# @@protoc_insertion_point(imports)
|
|
10
10
|
|
|
11
11
|
_sym_db = _symbol_database.Default()
|
|
@@ -15,34 +15,35 @@ _sym_db = _symbol_database.Default()
|
|
|
15
15
|
|
|
16
16
|
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\npolo.proto\x12\x12polo.wire.protobuf\"\xd1\x04\n\x0cOuterMessage\x12\x1b\n\x10protocol_version\x18\x01 \x02(\r:\x01\x31\x12\x37\n\x06status\x18\x02 \x02(\x0e\x32\'.polo.wire.protobuf.OuterMessage.Status\x12;\n\x0fpairing_request\x18\n \x01(\x0b\x32\".polo.wire.protobuf.PairingRequest\x12\x42\n\x13pairing_request_ack\x18\x0b \x01(\x0b\x32%.polo.wire.protobuf.PairingRequestAck\x12,\n\x07options\x18\x14 \x01(\x0b\x32\x1b.polo.wire.protobuf.Options\x12\x38\n\rconfiguration\x18\x1e \x01(\x0b\x32!.polo.wire.protobuf.Configuration\x12?\n\x11\x63onfiguration_ack\x18\x1f \x01(\x0b\x32$.polo.wire.protobuf.ConfigurationAck\x12*\n\x06secret\x18( \x01(\x0b\x32\x1a.polo.wire.protobuf.Secret\x12\x31\n\nsecret_ack\x18) \x01(\x0b\x32\x1d.polo.wire.protobuf.SecretAck\"b\n\x06Status\x12\x0e\n\tSTATUS_OK\x10\xc8\x01\x12\x11\n\x0cSTATUS_ERROR\x10\x90\x03\x12\x1d\n\x18STATUS_BAD_CONFIGURATION\x10\x91\x03\x12\x16\n\x11STATUS_BAD_SECRET\x10\x92\x03\";\n\x0ePairingRequest\x12\x14\n\x0cservice_name\x18\x01 \x02(\t\x12\x13\n\x0b\x63lient_name\x18\x02 \x01(\t\"(\n\x11PairingRequestAck\x12\x13\n\x0bserver_name\x18\x01 \x01(\t\"\x99\x04\n\x07Options\x12=\n\x0finput_encodings\x18\x01 \x03(\x0b\x32$.polo.wire.protobuf.Options.Encoding\x12>\n\x10output_encodings\x18\x02 \x03(\x0b\x32$.polo.wire.protobuf.Options.Encoding\x12<\n\x0epreferred_role\x18\x03 \x01(\x0e\x32$.polo.wire.protobuf.Options.RoleType\x1a\x82\x02\n\x08\x45ncoding\x12?\n\x04type\x18\x01 \x02(\x0e\x32\x31.polo.wire.protobuf.Options.Encoding.EncodingType\x12\x15\n\rsymbol_length\x18\x02 \x02(\r\"\x9d\x01\n\x0c\x45ncodingType\x12\x19\n\x15\x45NCODING_TYPE_UNKNOWN\x10\x00\x12\x1e\n\x1a\x45NCODING_TYPE_ALPHANUMERIC\x10\x01\x12\x19\n\x15\x45NCODING_TYPE_NUMERIC\x10\x02\x12\x1d\n\x19\x45NCODING_TYPE_HEXADECIMAL\x10\x03\x12\x18\n\x14\x45NCODING_TYPE_QRCODE\x10\x04\"L\n\x08RoleType\x12\x15\n\x11ROLE_TYPE_UNKNOWN\x10\x00\x12\x13\n\x0fROLE_TYPE_INPUT\x10\x01\x12\x14\n\x10ROLE_TYPE_OUTPUT\x10\x02\"\x82\x01\n\rConfiguration\x12\x36\n\x08\x65ncoding\x18\x01 \x02(\x0b\x32$.polo.wire.protobuf.Options.Encoding\x12\x39\n\x0b\x63lient_role\x18\x02 \x02(\x0e\x32$.polo.wire.protobuf.Options.RoleType\"\x12\n\x10\x43onfigurationAck\"\x18\n\x06Secret\x12\x0e\n\x06secret\x18\x01 \x02(\x0c\"\x1b\n\tSecretAck\x12\x0e\n\x06secret\x18\x01 \x02(\x0c\x42,\n\x1d\x63om.google.polo.wire.protobufB\tPoloProtoH\x03')
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
_builder.
|
|
18
|
+
_globals = globals()
|
|
19
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
20
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'polo_pb2', _globals)
|
|
20
21
|
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
21
22
|
|
|
22
23
|
DESCRIPTOR._options = None
|
|
23
24
|
DESCRIPTOR._serialized_options = b'\n\035com.google.polo.wire.protobufB\tPoloProtoH\003'
|
|
24
|
-
_OUTERMESSAGE._serialized_start=35
|
|
25
|
-
_OUTERMESSAGE._serialized_end=628
|
|
26
|
-
_OUTERMESSAGE_STATUS._serialized_start=530
|
|
27
|
-
_OUTERMESSAGE_STATUS._serialized_end=628
|
|
28
|
-
_PAIRINGREQUEST._serialized_start=630
|
|
29
|
-
_PAIRINGREQUEST._serialized_end=689
|
|
30
|
-
_PAIRINGREQUESTACK._serialized_start=691
|
|
31
|
-
_PAIRINGREQUESTACK._serialized_end=731
|
|
32
|
-
_OPTIONS._serialized_start=734
|
|
33
|
-
_OPTIONS._serialized_end=1271
|
|
34
|
-
_OPTIONS_ENCODING._serialized_start=935
|
|
35
|
-
_OPTIONS_ENCODING._serialized_end=1193
|
|
36
|
-
_OPTIONS_ENCODING_ENCODINGTYPE._serialized_start=1036
|
|
37
|
-
_OPTIONS_ENCODING_ENCODINGTYPE._serialized_end=1193
|
|
38
|
-
_OPTIONS_ROLETYPE._serialized_start=1195
|
|
39
|
-
_OPTIONS_ROLETYPE._serialized_end=1271
|
|
40
|
-
_CONFIGURATION._serialized_start=1274
|
|
41
|
-
_CONFIGURATION._serialized_end=1404
|
|
42
|
-
_CONFIGURATIONACK._serialized_start=1406
|
|
43
|
-
_CONFIGURATIONACK._serialized_end=1424
|
|
44
|
-
_SECRET._serialized_start=1426
|
|
45
|
-
_SECRET._serialized_end=1450
|
|
46
|
-
_SECRETACK._serialized_start=1452
|
|
47
|
-
_SECRETACK._serialized_end=1479
|
|
25
|
+
_globals['_OUTERMESSAGE']._serialized_start=35
|
|
26
|
+
_globals['_OUTERMESSAGE']._serialized_end=628
|
|
27
|
+
_globals['_OUTERMESSAGE_STATUS']._serialized_start=530
|
|
28
|
+
_globals['_OUTERMESSAGE_STATUS']._serialized_end=628
|
|
29
|
+
_globals['_PAIRINGREQUEST']._serialized_start=630
|
|
30
|
+
_globals['_PAIRINGREQUEST']._serialized_end=689
|
|
31
|
+
_globals['_PAIRINGREQUESTACK']._serialized_start=691
|
|
32
|
+
_globals['_PAIRINGREQUESTACK']._serialized_end=731
|
|
33
|
+
_globals['_OPTIONS']._serialized_start=734
|
|
34
|
+
_globals['_OPTIONS']._serialized_end=1271
|
|
35
|
+
_globals['_OPTIONS_ENCODING']._serialized_start=935
|
|
36
|
+
_globals['_OPTIONS_ENCODING']._serialized_end=1193
|
|
37
|
+
_globals['_OPTIONS_ENCODING_ENCODINGTYPE']._serialized_start=1036
|
|
38
|
+
_globals['_OPTIONS_ENCODING_ENCODINGTYPE']._serialized_end=1193
|
|
39
|
+
_globals['_OPTIONS_ROLETYPE']._serialized_start=1195
|
|
40
|
+
_globals['_OPTIONS_ROLETYPE']._serialized_end=1271
|
|
41
|
+
_globals['_CONFIGURATION']._serialized_start=1274
|
|
42
|
+
_globals['_CONFIGURATION']._serialized_end=1404
|
|
43
|
+
_globals['_CONFIGURATIONACK']._serialized_start=1406
|
|
44
|
+
_globals['_CONFIGURATIONACK']._serialized_end=1424
|
|
45
|
+
_globals['_SECRET']._serialized_start=1426
|
|
46
|
+
_globals['_SECRET']._serialized_end=1450
|
|
47
|
+
_globals['_SECRETACK']._serialized_start=1452
|
|
48
|
+
_globals['_SECRETACK']._serialized_end=1479
|
|
48
49
|
# @@protoc_insertion_point(module_scope)
|