Skip to content

Commit f498c46

Browse files
[platform] Modify default return values of some APIs in sfp.py
1 parent 0903660 commit f498c46

File tree

1 file changed

+55
-54
lines changed
  • platform/broadcom/sonic-platform-modules-quanta/ix7-32x/sonic_platform

1 file changed

+55
-54
lines changed

platform/broadcom/sonic-platform-modules-quanta/ix7-32x/sonic_platform/sfp.py

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,16 +1060,17 @@ def get_temperature(self):
10601060
"""
10611061
Retrieves the temperature of this SFP
10621062
Returns:
1063-
An integer number of current temperature in Celsius
1063+
A float representing the current temperature in Celsius
10641064
"""
1065+
default = 0.0
10651066
if not self.dom_supported:
1066-
return None
1067+
return default
10671068
if self.sfp_type == QSFP_TYPE:
10681069
offset = 0
10691070

10701071
sfpd_obj = sff8436Dom()
10711072
if sfpd_obj is None:
1072-
return None
1073+
return default
10731074

10741075
if self.dom_temp_supported:
10751076
dom_temperature_raw = self.__read_eeprom_specific_bytes(
@@ -1080,12 +1081,12 @@ def get_temperature(self):
10801081
dom_temperature_data['data']['Temperature']['value'])
10811082
return temp
10821083
else:
1083-
return None
1084+
return default
10841085
elif self.sfp_type == SFP_TYPE:
10851086
offset = 256
10861087
sfpd_obj = sff8472Dom()
10871088
if sfpd_obj is None:
1088-
return None
1089+
return default
10891090
sfpd_obj._calibration_type = 1
10901091

10911092
dom_temperature_raw = self.__read_eeprom_specific_bytes(
@@ -1096,24 +1097,25 @@ def get_temperature(self):
10961097
dom_temperature_data['data']['Temperature']['value'])
10971098
return temp
10981099
else:
1099-
return None
1100-
else:
1101-
return None
1100+
return default
1101+
1102+
return default
11021103

11031104
def get_voltage(self):
11041105
"""
11051106
Retrieves the supply voltage of this SFP
11061107
Returns:
1107-
An integer number of supply voltage in mV
1108+
A float representing the supply voltage in mV
11081109
"""
1110+
default = 0.0
11091111
if not self.dom_supported:
1110-
return None
1112+
return default
11111113
if self.sfp_type == QSFP_TYPE:
11121114
offset = 0
11131115

11141116
sfpd_obj = sff8436Dom()
11151117
if sfpd_obj is None:
1116-
return None
1118+
return default
11171119

11181120
if self.dom_volt_supported:
11191121
dom_voltage_raw = self.__read_eeprom_specific_bytes(
@@ -1124,13 +1126,13 @@ def get_voltage(self):
11241126
dom_voltage_data['data']['Vcc']['value'])
11251127
return voltage
11261128
else:
1127-
return None
1129+
return default
11281130
elif self.sfp_type == SFP_TYPE:
11291131
offset = 256
11301132

11311133
sfpd_obj = sff8472Dom()
11321134
if sfpd_obj is None:
1133-
return None
1135+
return default
11341136

11351137
sfpd_obj._calibration_type = self.calibration
11361138

@@ -1142,25 +1144,25 @@ def get_voltage(self):
11421144
dom_voltage_data['data']['Vcc']['value'])
11431145
return voltage
11441146
else:
1145-
return None
1146-
else:
1147-
return None
1147+
return default
1148+
1149+
return default
11481150

11491151
def get_tx_bias(self):
11501152
"""
1151-
Retrieves the TX bias current of this SFP
1153+
Retrieves the TX bias current of all SFP channels
11521154
Returns:
1153-
A list of four integer numbers, representing TX bias in mA
1154-
for channel 0 to channel 4.
1155-
Ex. ['110.09', '111.12', '108.21', '112.09']
1155+
A list of floats, representing TX bias in mA
1156+
for each available channel
1157+
E.g., for a tranceiver with four channels: ['110.09', '111.12', '108.21', '112.09']
11561158
"""
11571159
tx_bias_list = []
11581160
if self.sfp_type == QSFP_TYPE:
11591161
offset = 0
1160-
1162+
default = [0.0] * 4
11611163
sfpd_obj = sff8436Dom()
11621164
if sfpd_obj is None:
1163-
return None
1165+
return default
11641166

11651167
dom_channel_monitor_raw = self.__read_eeprom_specific_bytes(
11661168
(offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH)
@@ -1175,12 +1177,15 @@ def get_tx_bias(self):
11751177
dom_channel_monitor_data['data']['TX3Bias']['value']))
11761178
tx_bias_list.append(self._convert_string_to_num(
11771179
dom_channel_monitor_data['data']['TX4Bias']['value']))
1180+
else:
1181+
return default
1182+
11781183
elif self.sfp_type == SFP_TYPE:
11791184
offset = 256
1180-
1185+
default = [0.0]
11811186
sfpd_obj = sff8472Dom()
11821187
if sfpd_obj is None:
1183-
return None
1188+
return default
11841189
sfpd_obj._calibration_type = self.calibration
11851190

11861191
if self.dom_supported:
@@ -1192,30 +1197,28 @@ def get_tx_bias(self):
11921197
tx_bias_list.append(self._convert_string_to_num(
11931198
dom_channel_monitor_data['data']['TXBias']['value']))
11941199
else:
1195-
return None
1200+
return default
11961201
else:
1197-
return None
1198-
else:
1199-
return None
1202+
return default
12001203

12011204
return tx_bias_list
12021205

12031206
def get_rx_power(self):
12041207
"""
1205-
Retrieves the received optical power for this SFP
1208+
Retrieves the TX bias current of all SFP channels
12061209
Returns:
1207-
A list of four integer numbers, representing received optical
1208-
power in mW for channel 0 to channel 4.
1209-
Ex. ['1.77', '1.71', '1.68', '1.70']
1210+
A list of floats, representing TX bias in mA
1211+
for each available channel
1212+
E.g., for a tranceiver with four channels: ['110.09', '111.12', '108.21', '112.09']
12101213
"""
12111214
rx_power_list = []
12121215

12131216
if self.sfp_type == QSFP_TYPE:
12141217
offset = 0
1215-
1218+
default = [0.0] * 4
12161219
sfpd_obj = sff8436Dom()
12171220
if sfpd_obj is None:
1218-
return None
1221+
return default
12191222

12201223
if self.dom_rx_power_supported:
12211224
dom_channel_monitor_raw = self.__read_eeprom_specific_bytes(
@@ -1232,15 +1235,15 @@ def get_rx_power(self):
12321235
rx_power_list.append(self._convert_string_to_num(
12331236
dom_channel_monitor_data['data']['RX4Power']['value']))
12341237
else:
1235-
return None
1238+
return default
12361239
else:
1237-
return None
1240+
return default
12381241
elif self.sfp_type == SFP_TYPE:
12391242
offset = 256
1240-
1243+
default = [0.0]
12411244
sfpd_obj = sff8472Dom()
12421245
if sfpd_obj is None:
1243-
return None
1246+
return default
12441247

12451248
if self.dom_supported:
12461249
sfpd_obj._calibration_type = self.calibration
@@ -1253,30 +1256,29 @@ def get_rx_power(self):
12531256
rx_power_list.append(self._convert_string_to_num(
12541257
dom_channel_monitor_data['data']['RXPower']['value']))
12551258
else:
1256-
return None
1259+
return default
12571260
else:
1258-
return None
1259-
else:
1260-
return None
1261+
return default
12611262

12621263
return rx_power_list
12631264

12641265
def get_tx_power(self):
12651266
"""
1266-
Retrieves the TX power of this SFP
1267+
Retrieves the TX power of all SFP channels
12671268
Returns:
1268-
A list of four integer numbers, representing TX power in mW
1269-
for channel 0 to channel 4.
1270-
Ex. ['1.86', '1.86', '1.86', '1.86']
1269+
A list of floats, representing TX power in mW
1270+
for each available channel
1271+
E.g., for a tranceiver with four channels: ['1.86', '1.86', '1.86', '1.86']
12711272
"""
12721273
tx_power_list = []
12731274

12741275
if self.sfp_type == QSFP_TYPE:
12751276
offset = 0
1277+
default = [0.0] * 4
12761278

12771279
sfpd_obj = sff8436Dom()
12781280
if sfpd_obj is None:
1279-
return None
1281+
return default
12801282

12811283
if self.dom_tx_power_supported:
12821284
dom_channel_monitor_raw = self.__read_eeprom_specific_bytes(
@@ -1293,14 +1295,15 @@ def get_tx_power(self):
12931295
tx_power_list.append(self._convert_string_to_num(
12941296
dom_channel_monitor_data['data']['TX4Power']['value']))
12951297
else:
1296-
return None
1298+
return default
12971299
else:
1298-
return None
1300+
return default
12991301
elif self.sfp_type == SFP_TYPE:
13001302
offset = 256
1303+
default = [0.0]
13011304
sfpd_obj = sff8472Dom()
13021305
if sfpd_obj is None:
1303-
return None
1306+
return default
13041307

13051308
if self.dom_supported:
13061309
sfpd_obj._calibration_type = self.calibration
@@ -1313,11 +1316,9 @@ def get_tx_power(self):
13131316
tx_power_list.append(self._convert_string_to_num(
13141317
dom_channel_monitor_data['data']['TXPower']['value']))
13151318
else:
1316-
return None
1319+
return default
13171320
else:
1318-
return None
1319-
else:
1320-
return None
1321+
return default
13211322

13221323
return tx_power_list
13231324

0 commit comments

Comments
 (0)