@@ -319,7 +319,7 @@ def _send_command(self, cmd, params=None, *, param_len_16=False):
319319 ptr = 3
320320 for i , param in enumerate (params ):
321321 if self ._debug >= 2 :
322- print ("\t Sending param #%d is %d bytes long" % ( i , len ( param )) )
322+ print (f "\t Sending param #{ i } is { len ( param ) } bytes long" )
323323 if param_len_16 :
324324 self ._sendbuf [ptr ] = (len (param ) >> 8 ) & 0xFF
325325 ptr += 1
@@ -399,14 +399,14 @@ def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
399399 param_len <<= 8
400400 param_len |= self ._read_byte (spi )
401401 if self ._debug >= 2 :
402- print ("\t Parameter #%d length is %d" % ( num , param_len ) )
402+ print (f "\t Parameter #{ num } length is { param_len } " )
403403 response = bytearray (param_len )
404404 self ._read_bytes (spi , response )
405405 responses .append (response )
406406 self ._check_data (spi , _END_CMD )
407407
408408 if self ._debug >= 2 :
409- print ("Read %d: " % len (responses [0 ]), responses )
409+ print (f "Read { len (responses [0 ])} : " , responses )
410410 return responses
411411
412412 def _send_command_get_response (
@@ -776,7 +776,7 @@ def get_socket(self):
776776 if resp == 255 :
777777 raise OSError (23 ) # ENFILE - File table overflow
778778 if self ._debug :
779- print ("Allocated socket #%d" % resp )
779+ print (f "Allocated socket #{ resp } " )
780780 return resp
781781
782782 def socket_open (self , socket_num , dest , port , conn_mode = TCP_MODE ):
@@ -850,7 +850,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
850850 if conn_mode == self .UDP_MODE :
851851 # UDP verifies chunks on write, not bytes
852852 if sent != total_chunks :
853- raise ConnectionError ("Failed to write %d chunks (sent %d)" % ( total_chunks , sent ) )
853+ raise ConnectionError (f "Failed to write { total_chunks } chunks (sent { sent } )" )
854854 # UDP needs to finalize with this command, does the actual sending
855855 resp = self ._send_command_get_response (_SEND_UDP_DATA_CMD , self ._socknum_ll )
856856 if resp [0 ][0 ] != 1 :
@@ -859,7 +859,7 @@ def socket_write(self, socket_num, buffer, conn_mode=TCP_MODE):
859859
860860 if sent != len (buffer ):
861861 self .socket_close (socket_num )
862- raise ConnectionError ("Failed to send %d bytes (sent %d)" % ( len ( buffer ), sent ) )
862+ raise ConnectionError (f "Failed to send { len ( buffer ) } bytes (sent { sent } )" )
863863
864864 resp = self ._send_command_get_response (_DATA_SENT_TCP_CMD , self ._socknum_ll )
865865 if resp [0 ][0 ] != 1 :
@@ -873,15 +873,14 @@ def socket_available(self, socket_num):
873873 resp = self ._send_command_get_response (_AVAIL_DATA_TCP_CMD , self ._socknum_ll )
874874 reply = struct .unpack ("<H" , resp [0 ])[0 ]
875875 if self ._debug :
876- print ("ESPSocket: %d bytes available" % reply )
876+ print (f "ESPSocket: { reply } bytes available" )
877877 return reply
878878
879879 def socket_read (self , socket_num , size ):
880880 """Read up to 'size' bytes from the socket number. Returns a bytes"""
881881 if self ._debug :
882882 print (
883- "Reading %d bytes from ESP socket with status %d"
884- % (size , self .socket_status (socket_num ))
883+ f"Reading { size } bytes from ESP socket with status { self .socket_status (socket_num )} "
885884 )
886885 self ._socknum_ll [0 ][0 ] = socket_num
887886 resp = self ._send_command_get_response (
@@ -917,7 +916,7 @@ def socket_connect(self, socket_num, dest, port, conn_mode=TCP_MODE):
917916 def socket_close (self , socket_num ):
918917 """Close a socket using the ESP32's internal reference number"""
919918 if self ._debug :
920- print ("*** Closing socket #%d" % socket_num )
919+ print (f "*** Closing socket #{ socket_num } " )
921920 self ._socknum_ll [0 ][0 ] = socket_num
922921 try :
923922 self ._send_command_get_response (_STOP_CLIENT_TCP_CMD , self ._socknum_ll )
0 commit comments