From fed191e40e9f58a5002ae12d368fd3f2544b9020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=BChr?= Date: Thu, 31 May 2018 08:21:14 +0000 Subject: [PATCH] use math.copysign for temp offset calculation --- library/bme680/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/bme680/__init__.py b/library/bme680/__init__.py index 865fe40..809128f 100644 --- a/library/bme680/__init__.py +++ b/library/bme680/__init__.py @@ -60,14 +60,12 @@ class BME680(BME680Data): """Set temperature offset in celsius If set, the temperature t_fine will be increased by given value in celsius. - :param value: Temperature offset in Celsius, eg. 4, -8 + :param value: Temperature offset in Celsius, eg. 4, -8, 1.25 """ if value == 0: self.offset_temp_in_t_fine = 0 elif value < 0: - self.offset_temp_in_t_fine = -int((((int(abs(value) * 100)) << 8) - 128) / 5) - else: - self.offset_temp_in_t_fine = int((((int(abs(value) * 100)) << 8) - 128) / 5) + self.offset_temp_in_t_fine = int(math.copysign((((int(abs(value) * 100)) << 8) - 128) / 5, value)) def set_humidity_oversample(self, value): """Set humidity oversampling