private string FormatSensorValue(SensorValue sv)
        {
            if (sv != null)
                switch (sv.Type)
                {
                    case SensorValueType.Temperature: return sv.Value.ToString("N1") + " C"; // " °C";
                    case SensorValueType.Humidity: return sv.Value.ToString("N1") + "%";
                    case SensorValueType.Pressure: return (sv.Value / 133.3).ToString("N0") + " mmHg";
                    case SensorValueType.Tripped:
                    case SensorValueType.Armed:
                    case SensorValueType.Switch: return sv.Value == 1 ? "On" : "Off";
                    case SensorValueType.Distance: return sv.Value.ToString("N0") + " cm";
                    case SensorValueType.Forecast: return (new string[] {"Clear", "Sunny", "Cloudy", "Rain", "Thunderstorm", "Unknown"})[(int)sv.Value];
                    case SensorValueType.RainRate: return (new string[] { "Dry", "Wet", "Rain", "Thunderstorm" })[(int)sv.Value];
                    //case SensorValueType.: return sv.Value.ToString("N1") + "%";
                    default:
                        return sv.Value.ToString("N1");
                }

            return "--";
        }
        private SensorValue SaveSensorValueToDB(SensorMessage message)
        {
            //SensorValue lastSV = GetLastSensorValue(message.NodeNo, message.SensorNo);
            //if (lastSV != null && lastSV.Type == (SensorValueType)message.SubType && lastSV.Value == message.PayloadFloat)
            //    return lastSV;

            var dtDB = DateTime.UtcNow;
            var dt = DateTime.Now;

            SensorValue sv = new SensorValue()
            {
                Id = Guid.NewGuid(),
                NodeNo = message.NodeNo,
                SensorNo = message.SensorNo,
                TimeStamp = dtDB,
                Type = (SensorValueType)message.SubType,
                Value = message.PayloadFloat
            };

            Save(sv);

            sv.TimeStamp = dt;

            return sv;
        }