3939logger = logging .getLogger (__name__ )
4040
4141
42- class OBDCommand () :
42+ class OBDCommand :
4343 def __init__ (self ,
4444 name ,
4545 desc ,
@@ -49,14 +49,14 @@ def __init__(self,
4949 ecu = ECU .ALL ,
5050 fast = False ,
5151 header = ECU_HEADER .ENGINE ):
52- self .name = name # human readable name (also used as key in commands dict)
53- self .desc = desc # human readable description
54- self .command = command # command string
55- self .bytes = _bytes # number of bytes expected in return
56- self .decode = decoder # decoding function
57- self .ecu = ecu # ECU ID from which this command expects messages from
58- self .fast = fast # can an extra digit be added to the end of the command? (to make the ELM return early)
59- self .header = header # ECU header used for the queries
52+ self .name = name # human readable name (also used as key in commands dict)
53+ self .desc = desc # human readable description
54+ self .command = command # command string
55+ self .bytes = _bytes # number of bytes expected in return
56+ self .decode = decoder # decoding function
57+ self .ecu = ecu # ECU ID from which this command expects messages from
58+ self .fast = fast # can an extra digit be added to the end of the command? (to make the ELM return early)
59+ self .header = header # ECU header used for the queries
6060
6161 def clone (self ):
6262 return OBDCommand (self .name ,
@@ -69,42 +69,37 @@ def clone(self):
6969
7070 @property
7171 def mode (self ):
72- if len (self .command ) >= 2 and \
73- isHex (self .command .decode ()):
72+ if len (self .command ) >= 2 and isHex (self .command .decode ()):
7473 return int (self .command [:2 ], 16 )
7574 else :
7675 return None
7776
7877 @property
7978 def pid (self ):
80- if len (self .command ) > 2 and \
81- isHex (self .command .decode ()):
79+ if len (self .command ) > 2 and isHex (self .command .decode ()):
8280 return int (self .command [2 :], 16 )
8381 else :
8482 return None
8583
86-
8784 def __call__ (self , messages ):
8885
8986 # filter for applicable messages (from the right ECU(s))
90- for_us = lambda m : (self .ecu & m .ecu ) > 0
91- messages = list (filter (for_us , messages ))
87+ messages = [m for m in messages if (self .ecu & m .ecu ) > 0 ]
9288
9389 # guarantee data size for the decoder
9490 for m in messages :
9591 self .__constrain_message_data (m )
9692
97- # create the response object with the raw data recieved
93+ # create the response object with the raw data received
9894 # and reference to original command
9995 r = OBDResponse (self , messages )
10096 if messages :
10197 r .value = self .decode (messages )
10298 else :
103- logger .info (str (self ) + " did not recieve any acceptable messages" )
99+ logger .info (str (self ) + " did not receive any acceptable messages" )
104100
105101 return r
106102
107-
108103 def __constrain_message_data (self , message ):
109104 """ pads or chops the data field to the size specified by this command """
110105 if self .bytes > 0 :
@@ -117,7 +112,6 @@ def __constrain_message_data(self, message):
117112 message .data += (b'\x00 ' * (self .bytes - len (message .data )))
118113 logger .debug ("Message was shorter than expected. Padded message: " + repr (message .data ))
119114
120-
121115 def __str__ (self ):
122116 return "%s: %s" % (self .command , self .desc )
123117
@@ -127,6 +121,6 @@ def __hash__(self):
127121
128122 def __eq__ (self , other ):
129123 if isinstance (other , OBDCommand ):
130- return ( self .command == other .command )
124+ return self .command == other .command
131125 else :
132126 return False
0 commit comments