mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-27 12:55:32 +01:00
Use explict type checks for protobuf messages (#774)
This commit is contained in:
parent
7c7bdfc585
commit
d0aaf25577
@ -392,10 +392,10 @@ class APIClient:
|
|||||||
msg_types = LIST_ENTITIES_MSG_TYPES
|
msg_types = LIST_ENTITIES_MSG_TYPES
|
||||||
|
|
||||||
def do_append(msg: message.Message) -> bool:
|
def do_append(msg: message.Message) -> bool:
|
||||||
return not isinstance(msg, ListEntitiesDoneResponse)
|
return type(msg) is not ListEntitiesDoneResponse
|
||||||
|
|
||||||
def do_stop(msg: message.Message) -> bool:
|
def do_stop(msg: message.Message) -> bool:
|
||||||
return isinstance(msg, ListEntitiesDoneResponse)
|
return type(msg) is ListEntitiesDoneResponse
|
||||||
|
|
||||||
resp = await self._get_connection().send_messages_await_response_complex(
|
resp = await self._get_connection().send_messages_await_response_complex(
|
||||||
(ListEntitiesRequest(),), do_append, do_stop, msg_types, 60
|
(ListEntitiesRequest(),), do_append, do_stop, msg_types, 60
|
||||||
@ -403,7 +403,7 @@ class APIClient:
|
|||||||
entities: list[EntityInfo] = []
|
entities: list[EntityInfo] = []
|
||||||
services: list[UserService] = []
|
services: list[UserService] = []
|
||||||
for msg in resp:
|
for msg in resp:
|
||||||
if isinstance(msg, ListEntitiesServicesResponse):
|
if type(msg) is ListEntitiesServicesResponse:
|
||||||
services.append(UserService.from_pb(msg))
|
services.append(UserService.from_pb(msg))
|
||||||
continue
|
continue
|
||||||
cls = response_types[type(msg)]
|
cls = response_types[type(msg)]
|
||||||
@ -769,7 +769,7 @@ class APIClient:
|
|||||||
services = []
|
services = []
|
||||||
for msg in resp:
|
for msg in resp:
|
||||||
self._raise_for_ble_connection_change(address, msg, msg_types)
|
self._raise_for_ble_connection_change(address, msg, msg_types)
|
||||||
if isinstance(msg, BluetoothGATTErrorResponse):
|
if type(msg) is BluetoothGATTErrorResponse:
|
||||||
raise BluetoothGATTAPIError(BluetoothGATTError.from_pb(msg))
|
raise BluetoothGATTAPIError(BluetoothGATTError.from_pb(msg))
|
||||||
services.extend(BluetoothGATTServices.from_pb(msg).services)
|
services.extend(BluetoothGATTServices.from_pb(msg).services)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user