public override void ParseData(string command) { var jObject = JObject.Parse(command); if (jObject["temperature"] != null && float.TryParse(jObject["temperature"].ToString(), out float t)) { var newTemperature = t / 100; if (Temperature != null && Math.Abs(newTemperature - Temperature.Value) > 0.01) { OnTemperatureChange?.Invoke(this, new TemperatureEventArgs(newTemperature)); } Temperature = newTemperature; } if (jObject["humidity"] != null && float.TryParse(jObject["humidity"].ToString(), out float h)) { var newHumidity = h / 100; if (Humidity != null && Math.Abs(newHumidity - Humidity.Value) > 0.01) { OnHumidityChange?.Invoke(this, new HumidityEventArgs(newHumidity)); } Humidity = newHumidity; } if (jObject["voltage"] != null && float.TryParse(jObject["voltage"].ToString(), out float v)) { Voltage = v / 1000; } }
public override void ParseData(JObject data) { if (data["temperature"] != null && float.TryParse(data["temperature"].ToString(), out float t)) { var newTemperature = t / 100; if (Temperature != null && Math.Abs(newTemperature - Temperature.Value) > 0.01) { OnTemperatureChange?.Invoke(this, new TemperatureEventArgs(newTemperature)); } Temperature = newTemperature; } if (data["humidity"] != null && float.TryParse(data["humidity"].ToString(), out float h)) { var newHumidity = h / 100; if (Humidity != null && Math.Abs(newHumidity - Humidity.Value) > 0.01) { OnHumidityChange?.Invoke(this, new HumidityEventArgs(newHumidity)); } Humidity = newHumidity; } }
public override void ParseData(string command) { var jObject = JObject.Parse(command); if (jObject.ParseFloat("temperature", out float t)) { var newTemperature = t / 100; if (Temperature != null && Math.Abs(newTemperature - Temperature.Value) > 0.01) { OnTemperatureChange?.Invoke(this, new TemperatureEventArgs(newTemperature)); } Temperature = newTemperature; } if (jObject.ParseFloat("humidity", out float h)) { var newHumidity = h / 100; if (Humidity != null && Math.Abs(newHumidity - Humidity.Value) > 0.01) { OnHumidityChange?.Invoke(this, new HumidityEventArgs(newHumidity)); } Humidity = newHumidity; } Voltage = jObject.ParseVoltage(); }