using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NucuCar.Sensors.Abstractions; using NucuCar.Sensors.Grpc; using NucuCarSensorsProto; namespace NucuCar.Sensors.Modules.PMS5003 { public class Pms5003GrpcService : Pms5003SensorGrpcService.Pms5003SensorGrpcServiceBase { private readonly ILogger _logger; private readonly IOptions _options; private readonly ISensor _pms5003Sensor; public Pms5003GrpcService(ILogger logger, ISensor pms5003Sensor, IOptions options) { _pms5003Sensor = pms5003Sensor; _logger = logger; _options = options; } public override async Task GetMeasurement(Empty request, ServerCallContext context) { _logger?.LogDebug($"Calling {nameof(GetMeasurement)}."); if (_options.Value.Grpc) { return await Task.FromResult(_pms5003Sensor.Object.GetMeasurement()); } return await Task.FromResult(Responses.GrpcIsDisabledResponse); } } }