WMIProvider/Sensor.cs
author paulwerelds
Sat, 16 Oct 2010 13:29:06 +0000
changeset 223 39f73ac8c2f4
child 224 be9534663a55
permissions -rw-r--r--
Added a WMI provider, documentation to follow.
     1 using System.Management.Instrumentation;
     2 using OpenHardwareMonitor.Hardware;
     3 
     4 namespace OpenHardwareMonitor.WMIProvider {
     5   [InstrumentationClass(InstrumentationType.Instance)]
     6   public class Sensor : IWmiClass {
     7 
     8     private ISensor _sensor;
     9 
    10     public string SensorType { get; private set; }
    11     public string Identifier { get; private set; }
    12     public string Parent { get; private set; }
    13     public string Name { get; private set; }
    14     public float Value { get; private set; }
    15     public float Min { get; private set; }
    16     public float Max { get; private set; }
    17     public int Index { get; private set; }
    18 
    19     public Sensor(ISensor sensor) {
    20       Name = sensor.Name;
    21       Index = sensor.Index;
    22 
    23       SensorType = sensor.SensorType.ToString();
    24       Identifier = sensor.Identifier.ToString();
    25       Parent = sensor.Hardware.Identifier.ToString();
    26 
    27       _sensor = sensor;
    28     }
    29     
    30     public void Update() {
    31       Value = (_sensor.Value != null) ? (float)_sensor.Value : 0;
    32 
    33       if (_sensor.Min != null)
    34         Min = (float)_sensor.Min;
    35 
    36       if (_sensor.Max != null)
    37         Max = (float)_sensor.Max;
    38     }
    39   }
    40 }