From 8d934507a197d0ae15bbb32506c21be038be3d31 Mon Sep 17 00:00:00 2001 From: Andreas Hrubak Date: Thu, 10 Oct 2024 11:23:33 +0200 Subject: [PATCH] structure thermal devices --- client/meter/thermal | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/client/meter/thermal b/client/meter/thermal index f45029c..cbf2b17 100755 --- a/client/meter/thermal +++ b/client/meter/thermal @@ -2,18 +2,31 @@ require "common.pl"; +sub devname_to_hashref +{ + my $dev = shift; + my $parent_hash_ref = shift; + if(my ($devclass, $devnum) = $dev =~ /^(.+?)(\d+)$/) + { + return \%{$parent_hash_ref->{$devclass}->{$devnum}}; + } + return \%{$parent_hash_ref->{$dev}}; +} + for my $path (glob "/sys/class/thermal/cooling_device*/cur_state") { my ($dev) = (split /\//, $path)[4]; - $Thermal{$dev}->{'cur'} = file_get_int($path); + my $ref = devname_to_hashref($dev, \%Thermal); + $ref->{'cur'} = file_get_int($path); $path =~ s/cur_/max_/; - $Thermal{$dev}->{'max'} = file_get_int($path); + $ref->{'max'} = file_get_int($path); } for my $path (glob "/sys/class/thermal/thermal_zone*/temp") { my ($dev) = (split /\//, $path)[4]; - $Thermal{$dev}->{'temp'} = file_get_int($path) / 1000; + my $ref = devname_to_hashref($dev, \%Thermal); + $ref->{'temp'} = file_get_int($path) / 1000; } svlhk_dump(\%Thermal); -- 2.11.4.GIT