コード例 #1
0
        private async Task OnIsDue(HddTemperatureConfiguration configuration, CancellationToken cancellationToken)
        {
            var sensorReadings = await ReadFromHddTemp(cancellationToken);

            foreach (var item in configuration.Items.Where(t => t.Enable))
            {
                var path          = item.Path;
                var alias         = item.Alias;
                var sensorReading = sensorReadings.FirstOrDefault(t => t.device.Equals(path));
                if (sensorReading == default)
                {
                    // skip?
                    continue;
                }

                double temperatureRaw = sensorReading.temperatureCelsius;
                await Mediator.Publish(new OutboundMeasurement()
                {
                    Name = "hdd-temperature",
                    Item = new HddTemperatureMeasurement()
                    {
                        Timestamp   = DateTime.UtcNow,
                        Hostname    = System.Net.Dns.GetHostName(),
                        Hdd         = path,
                        Alias       = alias,
                        Temperature = temperatureRaw,
                    },
                }, cancellationToken);

                await Mediator.Publish(new SensorMeasurement()
                {
                    Sensor = $"hdd/{alias}/temperature/celsius",
                    Value  = $"{temperatureRaw:n1}",
                }, cancellationToken);

                await Mediator.Publish(new SensorMeasurement()
                {
                    Sensor = $"hdd/{alias}/temperature",
                    Value  = $"{temperatureRaw:n1}°C",
                }, cancellationToken);
            }

            MeasurementTimingService.ResetDue(configuration);
        }
コード例 #2
0
 public HddTemperature(IMediator mediator, HddTemperatureConfiguration configuration, IMeasurementTimingService measurementTimingService)
 {
     Mediator                 = mediator ?? throw new ArgumentNullException(nameof(mediator));
     Configuration            = configuration ?? throw new ArgumentNullException(nameof(configuration));
     MeasurementTimingService = measurementTimingService ?? throw new ArgumentNullException(nameof(measurementTimingService));
 }