Skip to content

Commit c4a8678

Browse files
committed
sht: ruff check and format updates
1 parent 2e9ff68 commit c4a8678

File tree

1 file changed

+17
-18
lines changed
  • micropython/drivers/sensor/sht

1 file changed

+17
-18
lines changed

micropython/drivers/sensor/sht/sht.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# t_raw, t_val, h_raw, h_val, isvalid = sensor.get_measure_results()
1414
# if isvalid is not None:
1515
# break
16-
# print(f'{t_raw}, {t_val} °C, {h_raw}, {h_val} %RH, isvalid')
16+
# print(f"{t_raw}, {t_val} °C, {h_raw}, {h_val} %RH, {isvalid}")
1717
# @endcode
1818
#
1919

@@ -22,9 +22,8 @@
2222

2323

2424
class SHT:
25-
26-
SHT3x = (0x30)
27-
SHT4x = (0x40)
25+
SHT3x = 0x30
26+
SHT4x = 0x40
2827

2928
# Init SHT
3029
# @param i2c I2C interface
@@ -69,22 +68,22 @@ def detect_sht_type(self):
6968
sht = 0xFF
7069
# try reading status of SHT3x
7170
try:
72-
self.i2c.writeto(self.i2c_addr, b'\xF3\x2D', False)
71+
self.i2c.writeto(self.i2c_addr, b"\xf3\x2d", False)
7372
time.sleep(0.01)
7473
response = self.i2c.readfrom(self.i2c_addr, 3)
75-
if self._check_crc(response[0:2],response[2]):
74+
if self._check_crc(response[0:2], response[2]):
7675
sht = self.SHT3x
77-
except OSError as error :
76+
except OSError:
7877
pass
7978
if sht == 0xFF:
8079
# try reading serial number of SHT4x
8180
try:
82-
self.i2c.writeto(self.i2c_addr, b'\x89', False)
81+
self.i2c.writeto(self.i2c_addr, b"\x89", False)
8382
time.sleep(0.01)
8483
response = self.i2c.readfrom(self.i2c_addr, 6)
85-
if self._check_crc(response[3:5],response[5]):
84+
if self._check_crc(response[3:5], response[5]):
8685
sht = self.SHT4x
87-
except OSError as error :
86+
except OSError:
8887
pass
8988
return sht
9089

@@ -93,30 +92,30 @@ def detect_sht_type(self):
9392
# @return None
9493
def start_measure(self, precision):
9594
if self.sht == self.SHT3x:
96-
p_byte = [b'\x16',b'\x0B',b'\x00']
97-
self.i2c.writeto(self.i2c_addr, b'\x24' + p_byte[precision], False)
95+
p_byte = [b"\x16", b"\x0b", b"\x00"]
96+
self.i2c.writeto(self.i2c_addr, b"\x24" + p_byte[precision], False)
9897
if self.sht == self.SHT4x:
99-
cmd = [b'\xE0',b'\xF6',b'\xFD']
98+
cmd = [b"\xe0", b"\xf6", b"\xfd"]
10099
self.i2c.writeto(self.i2c_addr, cmd[precision], False)
101100

102101
# Get the measurement values
103102
# @details
104103
# As long as no values available all return parameter are None.
105104
# If values not equal None are returned the measurement has been completed
106105
# and needs to be restarted again for a new measurement.
107-
# @return temperature[raw], temperature[°C], humidity[raw], humidity[%RH]
106+
# @return temperature[raw], temperature[°C], humidity[raw], humidity[%RH], valid
108107
def get_measure_results(self):
109108
try:
110109
response = self.i2c.readfrom(self.i2c_addr, 6)
111110
t_bytes = response[0:2]
112111
t_raw = int.from_bytes(t_bytes, "big")
113112
t_val = (175 * t_raw) / 0xFFFF - 45
114-
isvalid = self._check_crc(t_bytes,response[2])
113+
isvalid = self._check_crc(t_bytes, response[2])
115114
h_bytes = response[3:5]
116115
h_raw = int.from_bytes(h_bytes, "big")
117116
h_val = (100 * h_raw) / 0xFFFF
118-
isvalid &= self._check_crc(h_bytes,response[5])
119-
return t_raw, round(t_val,2), h_raw, round(h_val,2), bool(isvalid)
120-
except OSError as error :
117+
isvalid &= self._check_crc(h_bytes, response[5])
118+
return t_raw, round(t_val, 2), h_raw, round(h_val, 2), bool(isvalid)
119+
except OSError:
121120
# OSError: [Errno 5] EIO as long as measurement has not completed
122121
return None, None, None, None, None

0 commit comments

Comments
 (0)