using BOB.Singleton;
using Common.PubEvent;
using DeviceCommand.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BOB.Services
{
    public class LQ7500_DPollingRead : PollingRead
    {
        private LQ7500_D _LQ7500_D { get; set; }
        private IEventAggregator _eventAggregator { get; set; }
        public LQ7500_DPollingRead(IContainerProvider containerProvider) : base(containerProvider)
        {
            _eventAggregator = containerProvider.Resolve<IEventAggregator>();
            var _devices = containerProvider.Resolve<Devices>();
            DeviceName = "LQ7500_D";
            _LQ7500_D = _devices.DeviceDic["LQ7500_D"] as LQ7500_D;
        }
        public double 内部传感器温度 { get; set; } = double.NaN;
        public double 外部传感器温度 { get; set; } = double.NaN;
        public double 水流量 { get; set; } = double.NaN;

        public override async Task ReadDeviceDataAsync(CancellationToken ct = default)
        {
            内部传感器温度 = await _LQ7500_D.读取内部传感器温度();
            外部传感器温度 = await _LQ7500_D.读取外部传感器温度();
            水流量 = await _LQ7500_D.读取流量();
            var dataDic = new Dictionary<string, double>
                {
                    { "内部传感器温度", 内部传感器温度 },
                    { "外部传感器温度", 外部传感器温度 },
                    { "水流量", 水流量 }
                };
            _eventAggregator.GetEvent<CurveDataEvent>().Publish(("LQ7500_D", dataDic));
        }
    }
}
