From 5dca1ab0f37d1c68256db393934b331fd1ea646f Mon Sep 17 00:00:00 2001 From: JackSun Date: Thu, 23 Jun 2022 15:14:21 +0800 Subject: [PATCH] update: tempreature and humidity check and get --- code/tracker_collector.py | 13 +++++++------ code/tracker_devicecheck.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/code/tracker_collector.py b/code/tracker_collector.py index 45ae634..9080326 100644 --- a/code/tracker_collector.py +++ b/code/tracker_collector.py @@ -305,12 +305,13 @@ class Collector(Singleton): def __get_temp_humidity(self): data = {} - on_res = self.__temp_humidity_sensor.on() - if on_res: - temperature, humidity = self.__temp_humidity_sensor.read() - data["temperature"] = temperature - data["humidity"] = humidity - self.__temp_humidity_sensor.off() + if self.__temp_humidity_sensor is not None: + on_res = self.__temp_humidity_sensor.on() + if on_res: + temperature, humidity = self.__temp_humidity_sensor.read() + data["temperature"] = temperature + data["humidity"] = humidity + self.__temp_humidity_sensor.off() return data def add_module(self, module): diff --git a/code/tracker_devicecheck.py b/code/tracker_devicecheck.py index b1b3bc0..1eb8dee 100644 --- a/code/tracker_devicecheck.py +++ b/code/tracker_devicecheck.py @@ -90,11 +90,14 @@ class DeviceCheck(object): def temp(self): # return True if OK res = False - if self.__temp_humidity.on(): - temperature, humidity = self.__temp_humidity.read() - if temperature is not None and humidity is not None: - res = True - self.__temp_humidity.off() + if self.__temp_humidity is None: + res = None + else: + if self.__temp_humidity.on(): + temperature, humidity = self.__temp_humidity.read() + if temperature is not None and humidity is not None: + res = True + self.__temp_humidity.off() return res def light(self):