mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-23 12:15:13 +01:00
Avoid one dict lookup when processing packets (#431)
This commit is contained in:
parent
9a35b717c2
commit
6b32b7c5a3
@ -651,11 +651,11 @@ class APIConnection:
|
|||||||
|
|
||||||
def _process_packet(self, msg_type_proto: int, data: bytes) -> None:
|
def _process_packet(self, msg_type_proto: int, data: bytes) -> None:
|
||||||
"""Process a packet from the socket."""
|
"""Process a packet from the socket."""
|
||||||
if msg_type_proto not in MESSAGE_TYPE_TO_PROTO:
|
if not (class_ := MESSAGE_TYPE_TO_PROTO.get(msg_type_proto)):
|
||||||
_LOGGER.debug("%s: Skipping message type %s", self.log_name, msg_type_proto)
|
_LOGGER.debug("%s: Skipping message type %s", self.log_name, msg_type_proto)
|
||||||
return
|
return
|
||||||
|
|
||||||
msg = MESSAGE_TYPE_TO_PROTO[msg_type_proto]()
|
msg = class_()
|
||||||
try:
|
try:
|
||||||
# MergeFromString instead of ParseFromString since
|
# MergeFromString instead of ParseFromString since
|
||||||
# ParseFromString will clear the message first and
|
# ParseFromString will clear the message first and
|
||||||
|
Loading…
Reference in New Issue
Block a user