Skip to content

Commit 88413be

Browse files
authored
Merge pull request #16 from jerryneedell/jerryn_revert_pr_9
revert PR_9
2 parents 3a0867e + 26fcc72 commit 88413be

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

adafruit_am2320.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ def _crc16(data):
7777
return crc
7878

7979

80-
class AM2320Exception(Exception):
81-
"""Base class for exceptions."""
82-
83-
84-
class AM2320DeviceNotFound(AM2320Exception, ValueError):
85-
"""Indicates that a device couldn't be found."""
86-
87-
88-
class AM2320ReadError(AM2320Exception, RuntimeError):
89-
"""indicates that valid data could not be read from the sensor.
90-
91-
This may be due to a regular I2C read failure, or due to a checksum
92-
mismatch."""
93-
94-
9580
class AM2320:
9681
"""A driver for the AM2320 temperature and humidity sensor.
9782
@@ -109,7 +94,7 @@ def __init__(self, i2c_bus, address=AM2320_DEFAULT_ADDR):
10994
except ValueError:
11095
pass
11196
time.sleep(0.25)
112-
raise AM2320DeviceNotFound("AM2320 not found")
97+
raise ValueError("AM2320 not found")
11398

11499
def _read_register(self, register, length):
115100
with self._i2c as i2c:
@@ -130,12 +115,12 @@ def _read_register(self, register, length):
130115
# print("$%02X => %s" % (register, [hex(i) for i in result]))
131116
# Check preamble indicates correct readings
132117
if result[0] != 0x3 or result[1] != length:
133-
raise AM2320ReadError("I2C read failure")
118+
raise RuntimeError("I2C read failure")
134119
# Check CRC on all but last 2 bytes
135120
crc1 = struct.unpack("<H", bytes(result[-2:]))[0]
136121
crc2 = _crc16(result[0:-2])
137122
if crc1 != crc2:
138-
raise AM2320ReadError("CRC failure 0x%04X vs 0x%04X" % (crc1, crc2))
123+
raise RuntimeError("CRC failure 0x%04X vs 0x%04X" % (crc1, crc2))
139124
return result[2:-2]
140125

141126
@property

0 commit comments

Comments
 (0)