1111import sys
1212import zipfile
1313from collections import namedtuple
14- from typing import BinaryIO , Dict , Optional , Tuple , Union
14+ from typing import BinaryIO , Dict , List , Optional , Tuple , Union
1515
1616import semver
1717from tqdm .auto import tqdm
@@ -122,12 +122,12 @@ class BootloaderRequest:
122122
123123 def __init__ (
124124 self ,
125- command ,
126- name ,
127- request_format ,
128- data_format ,
129- request_reply = True ,
130- write_with_response = True ,
125+ command : BootloaderCommand ,
126+ name : str ,
127+ request_format : List [ str ] ,
128+ data_format : str ,
129+ request_reply : bool = True ,
130+ write_with_response : bool = True ,
131131 ):
132132 self .command = command
133133 self .ReplyClass = namedtuple (name , request_format )
@@ -137,17 +137,19 @@ def __init__(
137137 self .reply_len += 1
138138 self .write_with_response = write_with_response
139139
140- def make_request (self , payload = None ):
141- request = bytearray (( self .command ,) )
140+ def make_request (self , payload : Optional [ bytes ] = None ) -> bytearray :
141+ request = bytearray ([ self .command ] )
142142 if payload is not None :
143143 request += payload
144144 return request
145145
146- def parse_reply (self , reply ):
146+ def parse_reply (self , reply ) -> namedtuple :
147147 if reply [0 ] == self .command :
148148 return self .ReplyClass (* struct .unpack (self .data_format , reply [1 :]))
149149 else :
150- raise ValueError ("Unknown message: {0}" .format (reply ))
150+ raise ValueError (
151+ f"Expecting reply to { self .command .name } but received { BootloaderCommand (reply [0 ]).name } "
152+ )
151153
152154
153155class BootloaderConnection (BLERequestsConnection ):
0 commit comments