Cleanup protobuf object construction (#715)

This commit is contained in:
J. Nick Koston 2023-11-25 10:18:04 -06:00 committed by GitHub
parent 1360dd136a
commit 4230871761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 18 deletions

View File

@ -797,11 +797,9 @@ class APIClient:
response: bool,
timeout: float = DEFAULT_BLE_TIMEOUT,
) -> None:
req = BluetoothGATTWriteRequest()
req.address = address
req.handle = handle
req.response = response
req.data = data
req = BluetoothGATTWriteRequest(
address=address, handle=handle, response=response, data=data
)
if not response:
self._get_connection().send_message(req)
@ -858,10 +856,9 @@ class APIClient:
timeout: float = DEFAULT_BLE_TIMEOUT,
wait_for_response: bool = True,
) -> None:
req = BluetoothGATTWriteDescriptorRequest()
req.address = address
req.handle = handle
req.data = data
req = BluetoothGATTWriteDescriptorRequest(
address=address, handle=handle, data=data
)
if not wait_for_response:
self._get_connection().send_message(req)

View File

@ -361,17 +361,15 @@ class APIConnection:
raise HandshakeAPIError(f"Handshake failed: {err}") from err
self._set_connection_state(ConnectionState.HANDSHAKE_COMPLETE)
def _make_hello_request(self) -> HelloRequest:
"""Make a HelloRequest."""
hello = HelloRequest()
hello.client_info = self._params.client_info
hello.api_version_major = 1
hello.api_version_minor = 9
return hello
async def _connect_hello_login(self, login: bool) -> None:
"""Step 4 in connect process: send hello and login and get api version."""
messages = [self._make_hello_request()]
messages = [
HelloRequest(
client_info=self._params.client_info,
api_version_major=1,
api_version_minor=9,
)
]
msg_types = [HelloResponse]
if login:
messages.append(self._make_connect_request())