update: tempreature and humidity check and get

This commit is contained in:
JackSun 2022-06-23 15:14:21 +08:00
parent 873d898ade
commit 5dca1ab0f3
2 changed files with 15 additions and 11 deletions

View File

@ -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):

View File

@ -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):