示例#1
0
        public IOwDevice GetRawDevice(string deviceId)
        {
            _logger.LogDebug("Trying to retrieve device {0}...", deviceId);

            var device = _deviceFactory.GetDevice(deviceId);

            // only in case the device is a basic device, we can directly return it
            // special devices types constructed by 3rd party extensions need special
            // treatment!
            if (!(device is BasicOwDevice))
            {
                device = GetRawDevices().SingleOrDefault(d => d.DeviceId == deviceId);
            }

            return(device);
        }
        /// <summary>
        /// Figures out if an EEPROM chip (type 23) contains data which point towards a Wiregate MultiSensor
        /// and - if so - appends the appropriate device to the list of devices
        /// </summary>
        /// <param name="devices"></param>
        /// <returns></returns>
        public IEnumerable <IOwDevice> Process(IEnumerable <IOwDevice> devices)
        {
            var eeproms = devices.Where(dev => dev is EepromDevice);
            var tmp     = devices.ToList();

            _logger.LogInformation("Identified eeproms: {0}", eeproms.Select(ep => ep.DeviceId));

            foreach (var memChip in eeproms)
            {
                var eepromContent = memChip.ReadDeviceValues().Single().Value.ToString();

                string humSensorId = null, tempSensorId = null;
                try
                {
                    (humSensorId, tempSensorId) = GetMultiSensorDeviceIds(eepromContent);

                    _logger.LogInformation("Extracted humidity sensor id {0} and temperature sensor id {1} for multisensor {2}", humSensorId, tempSensorId, memChip.DeviceId);
                }
                catch (ArgumentException ae)
                {
                    _logger.LogInformation("Eeprom {0} did not contain MultiSensor data - omitting it: {1}", memChip.DeviceId, ae.Message);
                }

                var wiregateMultiSensor = _deviceFactory.GetDevice($"WGMS-{string.Concat(humSensorId, tempSensorId)}") as MultiSensor;

                try
                {
                    var humSensor = devices.Single(dev => dev.DeviceId.Equals(humSensorId, StringComparison.InvariantCultureIgnoreCase));
                    wiregateMultiSensor.SetHumiditySensor(humSensor);

                    var tempSensor = devices.Single(dev => dev.DeviceId.Equals(tempSensorId, StringComparison.InvariantCultureIgnoreCase));
                    wiregateMultiSensor.SetTemperatureSensor(tempSensor);

                    tmp.Add(wiregateMultiSensor);
                }
                catch (InvalidOperationException)
                {
                    _logger.LogWarning("Eeprom {0} references humidity sensor id {1} and temperature sensor id {2}, but at least one of them could not be found!", memChip.DeviceId, humSensorId, tempSensorId);
                }
            }

            return(tmp.AsEnumerable());
        }