From 4230871761d3ebb74d6c0f3ca627f2b2ec8fa375 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Nov 2023 10:18:04 -0600 Subject: [PATCH] Cleanup protobuf object construction (#715) --- aioesphomeapi/client.py | 15 ++++++--------- aioesphomeapi/connection.py | 16 +++++++--------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/aioesphomeapi/client.py b/aioesphomeapi/client.py index 9d515c2..e3778bf 100644 --- a/aioesphomeapi/client.py +++ b/aioesphomeapi/client.py @@ -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) diff --git a/aioesphomeapi/connection.py b/aioesphomeapi/connection.py index d8be453..5937a79 100644 --- a/aioesphomeapi/connection.py +++ b/aioesphomeapi/connection.py @@ -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())