From 9d5356118d9ae6e544c1197f9a39558f422c69e4 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Tue, 20 Nov 2018 11:22:31 +0700 Subject: [PATCH 1/6] Update sonic-platform-common submocule to fixed sfp dom issue --- .gitmodules | 2 +- src/sonic-platform-common | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index bb4eae528c72..413e71ddcd1c 100755 --- a/.gitmodules +++ b/.gitmodules @@ -49,7 +49,7 @@ url = https://github.com/Ingrasys-sonic/sonic-platform-modules-ingrasys [submodule "src/sonic-platform-common"] path = src/sonic-platform-common - url = https://github.com/Azure/sonic-platform-common + url = https://github.com/celestica-Inc/sonic-platform-common [submodule "src/sonic-platform-daemons"] path = src/sonic-platform-daemons url = https://github.com/Azure/sonic-platform-daemons diff --git a/src/sonic-platform-common b/src/sonic-platform-common index 76ae431e41dc..d03c24161b2f 160000 --- a/src/sonic-platform-common +++ b/src/sonic-platform-common @@ -1 +1 @@ -Subproject commit 76ae431e41dca1255f8056b590668c9ca187f031 +Subproject commit d03c24161b2f4c0c3c0023c81b99e68343e61410 From 8ac5156e640326512876a55cfcc8ae87c2406766 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Tue, 20 Nov 2018 11:47:52 +0700 Subject: [PATCH 2/6] Fix invalid number of psu issue --- device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py | 2 ++ .../alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py | 2 ++ .../alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py | 2 ++ platform/broadcom/sonic-platform-modules-cel | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py index 8906dc4bb116..aff5650beac7 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py @@ -43,6 +43,8 @@ def get_num_psus(self): # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() num_psus = len(self.psu_info_list) + for psu_dict in self.psu_info_list: + num_psus = num_psus - 1 if psu_dict.keys() == [] else num_psus except: return num_psus diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py index 8906dc4bb116..aff5650beac7 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py @@ -43,6 +43,8 @@ def get_num_psus(self): # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() num_psus = len(self.psu_info_list) + for psu_dict in self.psu_info_list: + num_psus = num_psus - 1 if psu_dict.keys() == [] else num_psus except: return num_psus diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py index 235ea3cfeaa1..55a10d1860d6 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py @@ -43,6 +43,8 @@ def get_num_psus(self): # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() num_psus = len(self.psu_info_list) + for psu_dict in self.psu_info_list: + num_psus = num_psus - 1 if psu_dict.keys() == [] else num_psus except: return num_psus diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 437489809fb1..9da1a34aba74 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 437489809fb12687f60489803d22cef929765aeb +Subproject commit 9da1a34aba748cb0cddd940f7b3f9f4a260f7df3 From 4560cf9d45816a7c47478f8a288f727f564161b2 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Wed, 21 Nov 2018 10:30:07 +0700 Subject: [PATCH 3/6] Update source packages follow sonic community --- src/thrift/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/thrift/Makefile b/src/thrift/Makefile index 786a10641e60..077b7fb308bd 100644 --- a/src/thrift/Makefile +++ b/src/thrift/Makefile @@ -10,12 +10,15 @@ DERIVED_TARGETS = libthrift-dev_$(THRIFT_VERSION_FULL)_amd64.deb \ python-thrift_$(THRIFT_VERSION_FULL)_amd64.deb \ thrift-compiler_$(THRIFT_VERSION_FULL)_amd64.deb +#THRIFT_LINK_PRE = http://http.debian.net/debian/pool/main/t/thrift +THRIFT_LINK_PRE = https://sonicstorage.blob.core.windows.net/packages/debian + $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : rm -rf thrift-$(THRIFT_VERSION) - wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_$(THRIFT_VERSION).orig.tar.gz - wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_$(THRIFT_VERSION_FULL).debian.tar.xz - wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_$(THRIFT_VERSION_FULL).dsc + wget -NO "thrift_$(THRIFT_VERSION).orig.tar.gz" "$(THRIFT_LINK_PRE)/thrift_$(THRIFT_VERSION).orig.tar.gz?sv=2015-04-05&sr=b&sig=wM3B01UnZQYYr7ZGXmCvRn6MMeS5hn5Oa5G5%2Btub53g%3D&se=2028-11-11T02%3A20%3A36Z&sp=r" + wget -NO "thrift_$(THRIFT_VERSION_FULL).debian.tar.xz" "$(THRIFT_LINK_PRE)/thrift_$(THRIFT_VERSION_FULL).debian.tar.xz?sv=2015-04-05&sr=b&sig=76bx%2BN8uxYbuI%2BEq8uK%2B8cTKTzVmjtjsQ9weejWNINk%3D&se=2028-11-11T02%3A19%3A30Z&sp=r" + wget -NO "thrift_$(THRIFT_VERSION_FULL).dsc" "$(THRIFT_LINK_PRE)/thrift_$(THRIFT_VERSION_FULL).dsc?sv=2015-04-05&sr=b&sig=Vpk1eJ97I5aWrtjAYS8w8AKyLXcJKFGIVFOOBGR3a5I%3D&se=2028-11-11T02%3A20%3A20Z&sp=r" dpkg-source -x thrift_$(THRIFT_VERSION_FULL).dsc pushd thrift-$(THRIFT_VERSION) From 1664ec9bf153670bbd17fb94b35741b543600fad Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 22 Nov 2018 14:34:42 +0700 Subject: [PATCH 4/6] Update minigraph xml parser to avoid exception --- src/sonic-config-engine/minigraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index a8140408e97f..1e9733246f18 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -431,7 +431,7 @@ def parse_xml(filename, platform=None, port_config_file=None): results = {} results['DEVICE_METADATA'] = {'localhost': { 'bgp_asn': bgp_asn, - 'deployment_id': deployment_id, + 'deployment_id': str(deployment_id), 'hostname': hostname, 'hwsku': hwsku, 'type': current_device['type'] From c9907cf796d9ba9db88ce4cee5b1bd9e6d196477 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 22 Nov 2018 14:52:09 +0700 Subject: [PATCH 5/6] update platform submodule cel --- platform/broadcom/sonic-platform-modules-cel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 9da1a34aba74..81d4911fcd2a 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 9da1a34aba748cb0cddd940f7b3f9f4a260f7df3 +Subproject commit 81d4911fcd2a3bbe24949092458ae6ad4d226b89 From d43d204b8804fb2b5628570cb5f4225a335da97f Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 22 Nov 2018 15:26:38 +0700 Subject: [PATCH 6/6] Clean sensorutil code and fix kW issue --- .../plugins/sensorutil.py | 67 ++++++++++--------- .../plugins/sensorutil.py | 67 ++++++++++--------- .../plugins/sensorutil.py | 67 ++++++++++--------- 3 files changed, 108 insertions(+), 93 deletions(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py index 45eae30a146a..8eca1d93af11 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py @@ -2,6 +2,7 @@ import requests + class SensorUtil(): """Platform-specific SensorUtil class""" @@ -9,7 +10,6 @@ def __init__(self): self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors" self.sensor_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.sensor_info_list is None: @@ -18,30 +18,28 @@ def request_data(self): self.sensor_info_list = sensor_json.get('Information') return self.sensor_info_list - def input_type_selector(self, unit): # Set input type. return { - "C" : "temperature", - "V" : "voltage", - "RPM" : "fan_speed", - "A" : "current", - "W" : "power" - }.get(unit, unit) - - - def get_num_sensors(self): + "C": "temperature", + "V": "voltage", + "RPM": "fan_speed", + "A": "current", + "W": "power" + }.get(unit, unit) + + def get_num_sensors(self): """ Get the number of sensors :return: int num_sensors """ - + num_sensors = 0 try: # Request and validate sensor's information self.sensor_info_list = self.request_data() - - # Get number of sensors. + + # Get number of sensors. num_sensors = len(self.sensor_info_list) except: print "Error: Unable to access sensor information" @@ -49,8 +47,7 @@ def get_num_sensors(self): return num_sensors - - def get_sensor_input_num(self, index): + def get_sensor_input_num(self, index): """ Get the number of the input items of the specified sensor :return: int input_num @@ -67,9 +64,8 @@ def get_sensor_input_num(self, index): except: print "Error: Unable to access sensor information" return 0 - - return input_num + return input_num def get_sensor_name(self, index): """ @@ -92,7 +88,6 @@ def get_sensor_name(self, index): return sensor_name - def get_sensor_input_name(self, sensor_index, input_index): """ Get the input item name of the specified input item of the @@ -118,7 +113,6 @@ def get_sensor_input_name(self, sensor_index, input_index): return sensor_input_name - def get_sensor_input_type(self, sensor_index, input_index): """ Get the item type of the specified input item of the specified sensor index, @@ -146,7 +140,6 @@ def get_sensor_input_type(self, sensor_index, input_index): return sensor_input_type - def get_sensor_input_value(self, sensor_index, input_index): """ Get the current value of the input item, the unit is "V" or "C" @@ -167,14 +160,14 @@ def get_sensor_input_value(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - sensor_input_value = float(sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_input_value = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 except: print "Error: Unable to access sensor information" return 0 return sensor_input_value - def get_sensor_input_low_threshold(self, sensor_index, input_index): """ Get the low threshold of the value, @@ -196,16 +189,21 @@ def get_sensor_input_low_threshold(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'min' in s or 'low' in s] - sensor_input_low_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 - + indices = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + l_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_low_threshold = l_thres * \ + 1000 if str(unit[0]).lower() == 'k' else l_thres except: print "Error: Unable to access sensor information" return 0 return sensor_input_low_threshold - def get_sensor_input_high_threshold(self, sensor_index, input_index): """ Get the high threshold of the value, @@ -223,15 +221,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): del sensor_data["name"] del sensor_data["Adapter"] - # Get sensor's input high threshold. + # Get sensor's input high threshold. sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'max' in s or 'high' in s] - sensor_input_high_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + indices = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + h_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_high_threshold = h_thres * \ + 1000 if str(unit[0]).lower() == 'k' else h_thres except: print "Error: Unable to access sensor information" return 0 - return sensor_input_high_threshold \ No newline at end of file + return sensor_input_high_threshold diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py index 45eae30a146a..8eca1d93af11 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py @@ -2,6 +2,7 @@ import requests + class SensorUtil(): """Platform-specific SensorUtil class""" @@ -9,7 +10,6 @@ def __init__(self): self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors" self.sensor_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.sensor_info_list is None: @@ -18,30 +18,28 @@ def request_data(self): self.sensor_info_list = sensor_json.get('Information') return self.sensor_info_list - def input_type_selector(self, unit): # Set input type. return { - "C" : "temperature", - "V" : "voltage", - "RPM" : "fan_speed", - "A" : "current", - "W" : "power" - }.get(unit, unit) - - - def get_num_sensors(self): + "C": "temperature", + "V": "voltage", + "RPM": "fan_speed", + "A": "current", + "W": "power" + }.get(unit, unit) + + def get_num_sensors(self): """ Get the number of sensors :return: int num_sensors """ - + num_sensors = 0 try: # Request and validate sensor's information self.sensor_info_list = self.request_data() - - # Get number of sensors. + + # Get number of sensors. num_sensors = len(self.sensor_info_list) except: print "Error: Unable to access sensor information" @@ -49,8 +47,7 @@ def get_num_sensors(self): return num_sensors - - def get_sensor_input_num(self, index): + def get_sensor_input_num(self, index): """ Get the number of the input items of the specified sensor :return: int input_num @@ -67,9 +64,8 @@ def get_sensor_input_num(self, index): except: print "Error: Unable to access sensor information" return 0 - - return input_num + return input_num def get_sensor_name(self, index): """ @@ -92,7 +88,6 @@ def get_sensor_name(self, index): return sensor_name - def get_sensor_input_name(self, sensor_index, input_index): """ Get the input item name of the specified input item of the @@ -118,7 +113,6 @@ def get_sensor_input_name(self, sensor_index, input_index): return sensor_input_name - def get_sensor_input_type(self, sensor_index, input_index): """ Get the item type of the specified input item of the specified sensor index, @@ -146,7 +140,6 @@ def get_sensor_input_type(self, sensor_index, input_index): return sensor_input_type - def get_sensor_input_value(self, sensor_index, input_index): """ Get the current value of the input item, the unit is "V" or "C" @@ -167,14 +160,14 @@ def get_sensor_input_value(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - sensor_input_value = float(sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_input_value = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 except: print "Error: Unable to access sensor information" return 0 return sensor_input_value - def get_sensor_input_low_threshold(self, sensor_index, input_index): """ Get the low threshold of the value, @@ -196,16 +189,21 @@ def get_sensor_input_low_threshold(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'min' in s or 'low' in s] - sensor_input_low_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 - + indices = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + l_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_low_threshold = l_thres * \ + 1000 if str(unit[0]).lower() == 'k' else l_thres except: print "Error: Unable to access sensor information" return 0 return sensor_input_low_threshold - def get_sensor_input_high_threshold(self, sensor_index, input_index): """ Get the high threshold of the value, @@ -223,15 +221,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): del sensor_data["name"] del sensor_data["Adapter"] - # Get sensor's input high threshold. + # Get sensor's input high threshold. sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'max' in s or 'high' in s] - sensor_input_high_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + indices = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + h_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_high_threshold = h_thres * \ + 1000 if str(unit[0]).lower() == 'k' else h_thres except: print "Error: Unable to access sensor information" return 0 - return sensor_input_high_threshold \ No newline at end of file + return sensor_input_high_threshold diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py index 45eae30a146a..8eca1d93af11 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py @@ -2,6 +2,7 @@ import requests + class SensorUtil(): """Platform-specific SensorUtil class""" @@ -9,7 +10,6 @@ def __init__(self): self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors" self.sensor_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.sensor_info_list is None: @@ -18,30 +18,28 @@ def request_data(self): self.sensor_info_list = sensor_json.get('Information') return self.sensor_info_list - def input_type_selector(self, unit): # Set input type. return { - "C" : "temperature", - "V" : "voltage", - "RPM" : "fan_speed", - "A" : "current", - "W" : "power" - }.get(unit, unit) - - - def get_num_sensors(self): + "C": "temperature", + "V": "voltage", + "RPM": "fan_speed", + "A": "current", + "W": "power" + }.get(unit, unit) + + def get_num_sensors(self): """ Get the number of sensors :return: int num_sensors """ - + num_sensors = 0 try: # Request and validate sensor's information self.sensor_info_list = self.request_data() - - # Get number of sensors. + + # Get number of sensors. num_sensors = len(self.sensor_info_list) except: print "Error: Unable to access sensor information" @@ -49,8 +47,7 @@ def get_num_sensors(self): return num_sensors - - def get_sensor_input_num(self, index): + def get_sensor_input_num(self, index): """ Get the number of the input items of the specified sensor :return: int input_num @@ -67,9 +64,8 @@ def get_sensor_input_num(self, index): except: print "Error: Unable to access sensor information" return 0 - - return input_num + return input_num def get_sensor_name(self, index): """ @@ -92,7 +88,6 @@ def get_sensor_name(self, index): return sensor_name - def get_sensor_input_name(self, sensor_index, input_index): """ Get the input item name of the specified input item of the @@ -118,7 +113,6 @@ def get_sensor_input_name(self, sensor_index, input_index): return sensor_input_name - def get_sensor_input_type(self, sensor_index, input_index): """ Get the item type of the specified input item of the specified sensor index, @@ -146,7 +140,6 @@ def get_sensor_input_type(self, sensor_index, input_index): return sensor_input_type - def get_sensor_input_value(self, sensor_index, input_index): """ Get the current value of the input item, the unit is "V" or "C" @@ -167,14 +160,14 @@ def get_sensor_input_value(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - sensor_input_value = float(sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_input_value = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 except: print "Error: Unable to access sensor information" return 0 return sensor_input_value - def get_sensor_input_low_threshold(self, sensor_index, input_index): """ Get the low threshold of the value, @@ -196,16 +189,21 @@ def get_sensor_input_low_threshold(self, sensor_index, input_index): sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'min' in s or 'low' in s] - sensor_input_low_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 - + indices = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + l_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_low_threshold = l_thres * \ + 1000 if str(unit[0]).lower() == 'k' else l_thres except: print "Error: Unable to access sensor information" return 0 return sensor_input_low_threshold - def get_sensor_input_high_threshold(self, sensor_index, input_index): """ Get the high threshold of the value, @@ -223,15 +221,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): del sensor_data["name"] del sensor_data["Adapter"] - # Get sensor's input high threshold. + # Get sensor's input high threshold. sensor_data_key = sensor_data.keys() sensor_input_raw = sensor_data.get(sensor_data_key[input_index-1]) sensor_data_str = sensor_input_raw.split() - indices = [i for i, s in enumerate(sensor_data_str) if 'max' in s or 'high' in s] - sensor_input_high_threshold = float(sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + indices = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + h_thres = float( + sensor_data_str[indices[0] + 2]) if len(indices) != 0 else 0 + unit = sensor_data_str[indices[0] + + 3] if len(indices) != 0 else None + if unit is not None and len(unit) > 1: + sensor_input_high_threshold = h_thres * \ + 1000 if str(unit[0]).lower() == 'k' else h_thres except: print "Error: Unable to access sensor information" return 0 - return sensor_input_high_threshold \ No newline at end of file + return sensor_input_high_threshold