Skip to content

Commit 596cc70

Browse files
Michał Kaczmarczykalistair23
authored andcommitted
obd: Fix some incorrect whitespace according to PEP8 rules
Signed-off-by: Alistair Francis <alistair@alistair23.me>
1 parent bd8e644 commit 596cc70

6 files changed

Lines changed: 146 additions & 162 deletions

File tree

obd/OBDCommand.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
logger = 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

obd/OBDResponse.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,36 @@
3131
########################################################################
3232

3333

34+
import logging
35+
import sys
3436
import time
35-
from .codes import *
3637

37-
import logging
38+
from .codes import *
3839

3940
logger = logging.getLogger(__name__)
4041

42+
if sys.version[0] < '3':
43+
string_types = (str, unicode)
44+
else:
45+
string_types = (str,)
4146

4247

43-
class OBDResponse():
48+
class OBDResponse:
4449
""" Standard response object for any OBDCommand """
4550

4651
def __init__(self, command=None, messages=None):
47-
self.command = command
52+
self.command = command
4853
self.messages = messages if messages else []
49-
self.value = None
50-
self.time = time.time()
54+
self.value = None
55+
self.time = time.time()
5156

5257
@property
5358
def unit(self):
5459
# for backwards compatibility
60+
from obd import Unit # local import to avoid cyclic-dependency
5561
if isinstance(self.value, Unit.Quantity):
5662
return str(self.value.u)
57-
elif self.value == None:
63+
elif self.value is None:
5864
return None
5965
else:
6066
return str(type(self.value))
@@ -66,25 +72,24 @@ def __str__(self):
6672
return str(self.value)
6773

6874

69-
7075
"""
7176
Special value types used in OBDResponses
7277
instantiated in decoders.py
7378
"""
7479

7580

76-
class Status():
81+
class Status:
7782
def __init__(self):
78-
self.MIL = False
79-
self.DTC_count = 0
83+
self.MIL = False
84+
self.DTC_count = 0
8085
self.ignition_type = ""
8186

8287
# make sure each test is available by name
8388
# until real data comes it. This also prevents things from
8489
# breaking when the user looks up a standard test that's null.
8590
null_test = StatusTest()
8691
for name in BASE_TESTS + SPARK_TESTS + COMPRESSION_TESTS:
87-
if name: # filter out None/reserved tests
92+
if name: # filter out None/reserved tests
8893
self.__dict__[name] = null_test
8994

9095

@@ -100,9 +105,9 @@ def __str__(self):
100105
return "Test %s: %s, %s" % (self.name, a, c)
101106

102107

103-
class Monitor():
108+
class Monitor:
104109
def __init__(self):
105-
self._tests = {} # tid : MonitorTest
110+
self._tests = {} # tid : MonitorTest
106111

107112
# make the standard TIDs available as null monitor tests
108113
# until real data comes it. This also prevents things from
@@ -125,7 +130,7 @@ def tests(self):
125130

126131
def __str__(self):
127132
if len(self.tests) > 0:
128-
return "\n".join([ str(t) for t in self.tests ])
133+
return "\n".join([str(t) for t in self.tests])
129134
else:
130135
return "No tests to report"
131136

@@ -135,14 +140,13 @@ def __len__(self):
135140
def __getitem__(self, key):
136141
if isinstance(key, int):
137142
return self._tests.get(key, MonitorTest())
138-
elif isinstance(key, str) or isinstance(key, unicode):
143+
elif isinstance(key, string_types):
139144
return self.__dict__.get(key, MonitorTest())
140145
else:
141146
logger.warning("Monitor test results can only be retrieved by TID value or property name")
142147

143148

144-
145-
class MonitorTest():
149+
class MonitorTest:
146150
def __init__(self):
147151
self.tid = None
148152
self.name = None

0 commit comments

Comments
 (0)