Skip to content

Commit

Permalink
feat: use built-in temperature provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mu88 committed Jan 21, 2024
1 parent 723575f commit d1babb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions RaspiFanController/Logic/RaspiTemperatureProvider2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Iot.Device.CpuTemperature;

namespace RaspiFanController.Logic;

[ExcludeFromCodeCoverage]
public class RaspiTemperatureProvider2(ILogger<RaspiTemperatureProvider2> logger) : ITemperatureProvider
{
/// <inheritdoc />
public (double, string) GetTemperature()
{
var cpuTemperature = new CpuTemperature();
var temperatureObject = cpuTemperature.ReadTemperatures().First();
return !double.IsNaN(temperatureObject.Temperature.DegreesCelsius) ? (temperatureObject.Temperature.DegreesCelsius, "C") : (double.NaN, "#");
}

/// <inheritdoc />
public bool IsPlatformSupported()
{
var isPlatformSupported = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
logger.LogDebug("Is platform supported: {IsPlatformSupported}", isPlatformSupported);
return isPlatformSupported;
}
}
2 changes: 1 addition & 1 deletion RaspiFanController/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
else
{
builder.Services.AddSingleton<ITemperatureProvider, RaspiTemperatureProvider>();
builder.Services.AddSingleton<ITemperatureProvider, RaspiTemperatureProvider2>();
builder.Services.AddSingleton<IFanController, RaspiFanController.Logic.RaspiFanController>();
}

Expand Down

0 comments on commit d1babb8

Please sign in to comment.