Skip to content

Commit

Permalink
Use explict type checks for protobuf messages (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 28, 2023
1 parent 7c7bdfc commit d0aaf25
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions aioesphomeapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,18 @@ async def list_entities_services(
msg_types = LIST_ENTITIES_MSG_TYPES

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:
return isinstance(msg, ListEntitiesDoneResponse)
return type(msg) is ListEntitiesDoneResponse

resp = await self._get_connection().send_messages_await_response_complex(
(ListEntitiesRequest(),), do_append, do_stop, msg_types, 60
)
entities: list[EntityInfo] = []
services: list[UserService] = []
for msg in resp:
if isinstance(msg, ListEntitiesServicesResponse):
if type(msg) is ListEntitiesServicesResponse:
services.append(UserService.from_pb(msg))
continue
cls = response_types[type(msg)]
Expand Down Expand Up @@ -769,7 +769,7 @@ def do_stop(
services = []
for msg in resp:
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))
services.extend(BluetoothGATTServices.from_pb(msg).services)

Expand Down

0 comments on commit d0aaf25

Please sign in to comment.