Skip to content

Commit a5e2eba

Browse files
committed
update docs, removed cruft
1 parent a534427 commit a5e2eba

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

adafruit_shtc3.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
2626
2727
28-
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29-
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
28+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
29+
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
3030
"""
3131

3232
# imports
@@ -80,8 +80,9 @@
8080
class SHTC3:
8181
"""
8282
A driver for the SHTC3 temperature and humidity sensor.
83-
:param i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
84-
:param int address: (optional) The I2C address of the device.
83+
84+
:param ~busio.I2C i2c_bus: The `busio.I2C` object to use. This is the only required parameter.
85+
8586
"""
8687

8788
def __init__(self, i2c_bus):
@@ -90,7 +91,7 @@ def __init__(self, i2c_bus):
9091
self._buffer = bytearray(6)
9192
self.low_power = False
9293
self.reset()
93-
self.sleep = False
94+
self.sleeping = False
9495
if self._chip_id & 0x083F != _SHTC3_CHIP_ID:
9596
raise RuntimeError("Failed to find an ICM20X sensor - check your wiring!")
9697

@@ -124,12 +125,12 @@ def reset(self):
124125
time.sleep(0.001)
125126

126127
@property
127-
def sleep(self):
128+
def sleeping(self):
128129
"""Determines the sleep state of the sensor"""
129130
return self._cached_sleep
130131

131-
@sleep.setter
132-
def sleep(self, sleep_enabled):
132+
@sleeping.setter
133+
def sleeping(self, sleep_enabled):
133134
if sleep_enabled:
134135
self._write_command(_SHTC3_SLEEP)
135136
else:
@@ -150,19 +151,19 @@ def low_power(self, low_power_enabled):
150151

151152
@property
152153
def relative_humidity(self):
153-
"""Current relative humidity in % rH"""
154+
"""The current relative humidity in % rH"""
154155
return self.measurements[1]
155156

156157
@property
157158
def temperature(self):
158-
"""Current temperature in degrees celcius"""
159+
"""The current temperature in degrees celcius"""
159160
return self.measurements[0]
160161

161162
@property
162163
def measurements(self):
163164
"""both `temperature` and `relative_humidity`, read simultaneously"""
164165

165-
self.sleep = False
166+
self.sleeping = False
166167
temperature = None
167168
humidity = None
168169
# send correct command for the current power state
@@ -193,16 +194,16 @@ def measurements(self):
193194
# decode data into human values:
194195
# convert bytes into 16-bit signed integer
195196
# convert the LSB value to a human value according to the datasheet
196-
raw_temp = unpack_from(">h", temp_data)
197+
raw_temp = unpack_from(">h", temp_data)[0]
197198
raw_temp = ((4375 * raw_temp) >> 14) - 4500
198199
temperature = raw_temp / 100.0
199200

200201
# repeat above steps for humidity data
201-
raw_humidity = unpack_from(">h", humidity_data)
202+
raw_humidity = unpack_from(">h", humidity_data)[0]
202203
raw_humidity = (625 * raw_humidity) >> 12
203204
humidity = raw_humidity / 100.0
204205

205-
self.sleep = True
206+
self.sleeping = True
206207
return (temperature, humidity)
207208

208209
## CRC-8 formula from page 14 of SHTC3 datasheet
@@ -211,7 +212,6 @@ def measurements(self):
211212

212213
@staticmethod
213214
def _crc8(buffer):
214-
print("\t\tbuff", [hex(i) for i in buffer])
215215
crc = 0xFF
216216
for byte in buffer:
217217
crc ^= byte
@@ -220,5 +220,4 @@ def _crc8(buffer):
220220
crc = (crc << 1) ^ 0x31
221221
else:
222222
crc = crc << 1
223-
print("\t\tcrc:", hex(crc & 0xFF))
224223
return crc & 0xFF # return the bottom 8 bits

0 commit comments

Comments
 (0)