@@ -77,21 +77,6 @@ def _crc16(data):
77
77
return crc
78
78
79
79
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
-
95
80
class AM2320 :
96
81
"""A driver for the AM2320 temperature and humidity sensor.
97
82
@@ -109,7 +94,7 @@ def __init__(self, i2c_bus, address=AM2320_DEFAULT_ADDR):
109
94
except ValueError :
110
95
pass
111
96
time .sleep (0.25 )
112
- raise AM2320DeviceNotFound ("AM2320 not found" )
97
+ raise ValueError ("AM2320 not found" )
113
98
114
99
def _read_register (self , register , length ):
115
100
with self ._i2c as i2c :
@@ -130,12 +115,12 @@ def _read_register(self, register, length):
130
115
# print("$%02X => %s" % (register, [hex(i) for i in result]))
131
116
# Check preamble indicates correct readings
132
117
if result [0 ] != 0x3 or result [1 ] != length :
133
- raise AM2320ReadError ("I2C read failure" )
118
+ raise RuntimeError ("I2C read failure" )
134
119
# Check CRC on all but last 2 bytes
135
120
crc1 = struct .unpack ("<H" , bytes (result [- 2 :]))[0 ]
136
121
crc2 = _crc16 (result [0 :- 2 ])
137
122
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 ))
139
124
return result [2 :- 2 ]
140
125
141
126
@property
0 commit comments