mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-21 22:02:34 +00:00
fix(agent): keep LHM helper alive after sensor failures (#2624)
Co-authored-by: hank <hank@henrygd.me>
This commit is contained in:
+18
-4
@@ -51,8 +51,7 @@ class Program
|
||||
var updated = false;
|
||||
foreach (var sensor in hardware.Sensors)
|
||||
{
|
||||
var validTemp = sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue;
|
||||
if (!validTemp ||
|
||||
if (sensor.SensorType != SensorType.Temperature ||
|
||||
sensor.Name.IndexOf("Distance", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
sensor.Name.IndexOf("Limit", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
sensor.Name.IndexOf("Critical", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
||||
@@ -64,10 +63,25 @@ class Program
|
||||
|
||||
if (!updated)
|
||||
{
|
||||
hardware.Update();
|
||||
try
|
||||
{
|
||||
hardware.Update();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Could not update {hardware.HardwareType} {hardware.Name}: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// Read the value once after Update(), which may reset it to null.
|
||||
var temperature = sensor.Value;
|
||||
if (!temperature.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var name = sensor.Name;
|
||||
// if sensor.Name starts with "Temperature" replace with hardware.Identifier but retain the rest of the name.
|
||||
// usually this is a number like Temperature 3
|
||||
@@ -77,7 +91,7 @@ class Program
|
||||
}
|
||||
|
||||
// invariant culture assures the value is parsable as a float
|
||||
var value = sensor.Value.Value.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
var value = temperature.Value.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
// write the name and value to the writer
|
||||
writer.WriteLine($"{name}|{value}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user