コード例 #1
0
ファイル: ThSensor.cs プロジェクト: pachman/mi-home
        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;
            }
        }
コード例 #2
0
ファイル: TempSensor.cs プロジェクト: ermac0/mi-home
        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;
            }
        }
コード例 #3
0
ファイル: ThSensor.cs プロジェクト: sergey-brutsky/mi-home
        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();
        }