Skip to content

Commit a11aca3

Browse files
committed
Merge pull request #25 from hirose31/fix/acpitemp
Also support new style acpi files: /sys/class/thermal/thermal_zone*/temp
2 parents 771f327 + 354fa57 commit a11aca3

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

lib/CloudForecast/Data/Acpitemperature.pm

+32-11
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,42 @@ fetcher {
2121
my $temp;
2222

2323
### find temperature file
24-
my @temp_files = glob '/proc/acpi/thermal_zone/*/temperature';
25-
if (! @temp_files) {
24+
my @temp_files;
25+
my @temp_files_proc = glob '/proc/acpi/thermal_zone/*/temperature';
26+
my @temp_files_sys = glob '/sys/class/thermal/thermal_zone*/temp';
27+
28+
if (@temp_files_proc) {
29+
@temp_files = @temp_files_proc;
30+
31+
if (scalar(@temp_files) > 1) {
32+
CloudForecast::Log->warn("more then one temp files found. decide to use first file.");
33+
}
34+
35+
$c->ledge_set('sysinfo', [ file => $temp_files[0] ]);
36+
37+
open my $tempf, '<', $temp_files[0] or die $!;
38+
my $line = <$tempf>; # <= "temperature: 57 C"
39+
close $tempf;
40+
($temp) = (split(/\s*:\s*/, $line))[1] =~ /([\d.]+)/;
41+
} elsif (@temp_files_sys) {
42+
@temp_files = @temp_files_sys;
43+
44+
if (scalar(@temp_files) > 1) {
45+
CloudForecast::Log->warn("more then one temp files found. decide to use first file.");
46+
}
47+
48+
$c->ledge_set('sysinfo', [ file => $temp_files[0] ]);
49+
50+
open my $tempf, '<', $temp_files[0] or die $!;
51+
my $line = <$tempf>; # <= "69000"
52+
close $tempf;
53+
($temp) = $line =~ /([\d.]+)/;
54+
$temp = $temp / 1000;
55+
} else {
2656
CloudForecast::Log->warn("cannot find temperature file.");
2757
return [undef];
28-
} elsif (scalar(@temp_files) > 1) {
29-
CloudForecast::Log->warn("more then one temp files found. decide to use first file.");
3058
}
3159

32-
$c->ledge_set('sysinfo', [ file => $temp_files[0] ]);
33-
34-
open my $tempf, '<', $temp_files[0] or die $!;
35-
my $line = <$tempf>; # <= "temperature: 57 C"
36-
close $tempf;
37-
($temp) = (split(/\s*:\s*/, $line))[1] =~ /([\d.]+)/;
38-
3960
return [$temp];
4061
};
4162

0 commit comments

Comments
 (0)