Skip to content

Commit fed191e

Browse files
committed
use math.copysign for temp offset calculation
1 parent 8cb0dea commit fed191e

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

library/bme680/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ def set_temp_offset(self, value):
6060
"""Set temperature offset in celsius
6161
6262
If set, the temperature t_fine will be increased by given value in celsius.
63-
:param value: Temperature offset in Celsius, eg. 4, -8
63+
:param value: Temperature offset in Celsius, eg. 4, -8, 1.25
6464
"""
6565
if value == 0:
6666
self.offset_temp_in_t_fine = 0
6767
elif value < 0:
68-
self.offset_temp_in_t_fine = -int((((int(abs(value) * 100)) << 8) - 128) / 5)
69-
else:
70-
self.offset_temp_in_t_fine = int((((int(abs(value) * 100)) << 8) - 128) / 5)
68+
self.offset_temp_in_t_fine = int(math.copysign((((int(abs(value) * 100)) << 8) - 128) / 5, value))
7169

7270
def set_humidity_oversample(self, value):
7371
"""Set humidity oversampling

0 commit comments

Comments
 (0)