Esempio n. 1
0
        private async Task PublishSensorConfigAsync(SensorAttribute sensor)
        {
            var json = new JObject();

            var device = new JObject();

            device.Add("name", new JValue("Zehnder WHR 930"));
            device.Add("identifiers", new JValue("zehnder-whr-930"));
            json.Add("device", device);

            json.Add("name", new JValue(sensor.SensorName));
            json.Add("unique_id", new JValue(sensor.UniqueID));
            json.Add("state_topic", new JValue("homeassistant/sensor/whr930/state"));
            json.Add("value_template", new JValue("{{ value_json['" + sensor.UniqueID + "'] }}"));

            if (!string.IsNullOrEmpty(sensor.DeviceClass))
            {
                json.Add("device_class", new JValue(sensor.DeviceClass));
            }

            if (!string.IsNullOrEmpty(sensor.Icon))
            {
                json.Add("icon", new JValue(sensor.Icon));
            }

            if (!string.IsNullOrEmpty(sensor.UnitOfMeasurement))
            {
                json.Add("unit_of_measurement", new JValue(sensor.UnitOfMeasurement));
            }

            var message = new MqttApplicationMessageBuilder()
                          .WithPayload(json.ToString())
                          .WithTopic($"homeassistant/sensor/whr930-{sensor.UniqueID}/config")
                          .WithRetainFlag(false)
                          .Build();

            await client.PublishAsync(message);
        }
Esempio n. 2
0
 public void RegisterSensor(SensorAttribute sensor) => sensors.Add(sensor);