timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

pretty_print_object #7

Closed claws closed 9 years ago

claws commented 9 years ago

This pull request adds some common object utilities (__str__ and __repr__) allowing the W1ThermSensor object to be nicely printed, providing a more meaningful output than the existing default.

For example, the output from this snippet:

s1 = W1ThermSensor()
print(s1)

will change from:

<w1thermsensor.W1ThermSensor object at 0xb6b26fd0>

to this:

W1ThermSensor(name='DS18B20', type=40(0x28), id='000003e9d591')
timofurrer commented 9 years ago

Cool! Thank you!

But some tests failed. I won't merge it until they all run successfully

:beers:

claws commented 9 years ago

Fixed the typo in the repr test. Not really sure why I had to fix the two get_temperature test methods that were failing due to sure comparing a float to an int and failing (e.g. 20 != 20.0). I didn't touch that code. From the commented out code in those functions it looks like you've had trouble in that area before. Anyway, tests are passing now.

timofurrer commented 9 years ago

Thank you! The problem with the already failed test cases is a new sure version which allows to compare floats with an epsilon.