brendan-w / python-OBD

OBD-II serial module for reading engine data
GNU General Public License v2.0
1.02k stars 360 forks source link

Add __repr__ to OBDCommand #145

Closed LightSoar closed 5 years ago

LightSoar commented 5 years ago

Better representation of a container of OBDCommands.

Before

>>> obd.commands.base_commands()
[<obd.OBDCommand.OBDCommand object at 0x7f3945cb7160>, <obd.OBDCommand.OBDCommand object at 0x7f393835f3c8>, <obd.OBDCommand.OBDCommand object at 0x7f3938361d68>, <obd.OBDCommand.OBDCommand object at 0x7f393835f390>, <obd.OBDCommand.OBDCommand object at 0x7f3938349748>, <obd.OBDCommand.OBDCommand object at 0x7f3938349780>, <obd.OBDCommand.OBDCommand object at 0x7f39383497b8>]

After

>>> obd.commands.base_commands()
[OBDCommand(PIDS_A, b'0100'), OBDCommand(MIDS_A, b'0600'), OBDCommand(GET_DTC, b'03'), OBDCommand(CLEAR_DTC, b'04'), OBDCommand(GET_CURRENT_DTC, b'07'), OBDCommand(ELM_VERSION, b'ATI'), OBDCommand(ELM_VOLTAGE, b'ATRV')]

>>> print("\n".join(map(repr, obd.commands.base_commands())))
OBDCommand(PIDS_A, b'0100')
OBDCommand(MIDS_A, b'0600')
OBDCommand(GET_DTC, b'03')
OBDCommand(CLEAR_DTC, b'04')
OBDCommand(GET_CURRENT_DTC, b'07')
OBDCommand(ELM_VERSION, b'ATI')
OBDCommand(ELM_VOLTAGE, b'ATRV')