11import datetime
22import os
3- import glob
43import re
54import sys
65
@@ -227,7 +226,8 @@ def add_sensor(base_name, sensor_component):
227226 device_sensors [base_name ].append (sensor_component )
228227
229228 try :
230- hwmon_devices = glob .glob ("/sys/class/hwmon/hwmon*" )
229+ hwmon_entries = HOST .run (("ls" , "/sys/class/hwmon" ), default = "" ).split ()
230+ hwmon_devices = [os .path .join ("/sys/class/hwmon" , entry ) for entry in hwmon_entries if entry .startswith ("hwmon" )]
231231
232232 for hwmon_path in hwmon_devices :
233233 try :
@@ -266,7 +266,9 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
266266 return component
267267
268268 # Temperature sensors
269- for temp_file in glob .glob (os .path .join (hwmon_path , "temp*_input" )):
269+ temp_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
270+ temp_files = [os .path .join (hwmon_path , e ) for e in temp_entries if e .startswith ("temp" ) and e .endswith ("_input" )]
271+ for temp_file in temp_files :
270272 try :
271273 sensor_num = os .path .basename (temp_file ).split ('_' )[0 ].replace ('temp' , '' )
272274 value = int (HOST .read (temp_file ).strip ())
@@ -283,7 +285,9 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
283285 continue
284286
285287 # Fan sensors (RPM from tachometer)
286- for fan_file in glob .glob (os .path .join (hwmon_path , "fan*_input" )):
288+ fan_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
289+ fan_files = [os .path .join (hwmon_path , e ) for e in fan_entries if e .startswith ("fan" ) and e .endswith ("_input" )]
290+ for fan_file in fan_files :
287291 try :
288292 sensor_num = os .path .basename (fan_file ).split ('_' )[0 ].replace ('fan' , '' )
289293 value = int (HOST .read (fan_file ).strip ())
@@ -301,9 +305,11 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
301305
302306 # PWM fan sensors (duty cycle percentage)
303307 # Only add if no fan*_input exists for this device (avoid duplicates)
304- has_rpm_sensor = bool (glob . glob ( os . path . join ( hwmon_path , "fan*_input" )) )
308+ has_rpm_sensor = bool (fan_files )
305309 if not has_rpm_sensor :
306- for pwm_file in glob .glob (os .path .join (hwmon_path , "pwm[0-9]*" )):
310+ pwm_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
311+ pwm_files = [os .path .join (hwmon_path , e ) for e in pwm_entries if e .startswith ("pwm" ) and e [3 :].replace ('_' , '' ).isdigit () if len (e ) > 3 ]
312+ for pwm_file in pwm_files :
307313 # Skip pwm*_enable, pwm*_mode, etc. - only process pwm1, pwm2, etc.
308314 pwm_basename = os .path .basename (pwm_file )
309315 if not pwm_basename .replace ('pwm' , '' ).isdigit ():
@@ -330,7 +336,9 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
330336 continue
331337
332338 # Voltage sensors
333- for voltage_file in glob .glob (os .path .join (hwmon_path , "in*_input" )):
339+ voltage_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
340+ voltage_files = [os .path .join (hwmon_path , e ) for e in voltage_entries if e .startswith ("in" ) and e .endswith ("_input" )]
341+ for voltage_file in voltage_files :
334342 try :
335343 sensor_num = os .path .basename (voltage_file ).split ('_' )[0 ].replace ('in' , '' )
336344 value = int (HOST .read (voltage_file ).strip ())
@@ -348,7 +356,9 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
348356 continue
349357
350358 # Current sensors
351- for current_file in glob .glob (os .path .join (hwmon_path , "curr*_input" )):
359+ current_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
360+ current_files = [os .path .join (hwmon_path , e ) for e in current_entries if e .startswith ("curr" ) and e .endswith ("_input" )]
361+ for current_file in current_files :
352362 try :
353363 sensor_num = os .path .basename (current_file ).split ('_' )[0 ].replace ('curr' , '' )
354364 value = int (HOST .read (current_file ).strip ())
@@ -366,7 +376,9 @@ def create_sensor(sensor_name, value, value_type, value_scale, label=None):
366376 continue
367377
368378 # Power sensors
369- for power_file in glob .glob (os .path .join (hwmon_path , "power*_input" )):
379+ power_entries = HOST .run (("ls" , hwmon_path ), default = "" ).split ()
380+ power_files = [os .path .join (hwmon_path , e ) for e in power_entries if e .startswith ("power" ) and e .endswith ("_input" )]
381+ for power_file in power_files :
370382 try :
371383 sensor_num = os .path .basename (power_file ).split ('_' )[0 ].replace ('power' , '' )
372384 value = int (HOST .read (power_file ).strip ())
@@ -433,7 +445,8 @@ def thermal_sensor_components():
433445
434446 try :
435447 # Find all thermal zones
436- thermal_zones = glob .glob ("/sys/class/thermal/thermal_zone*" )
448+ thermal_entries = HOST .run (("ls" , "/sys/class/thermal" ), default = "" ).split ()
449+ thermal_zones = [os .path .join ("/sys/class/thermal" , entry ) for entry in thermal_entries if entry .startswith ("thermal_zone" )]
437450
438451 for zone_path in thermal_zones :
439452 try :
0 commit comments