Ejemplo n.º 1
0
    public string GetTopic(HassTopicKind topicKind)
    {
        Type         type = GetType();
        PropertyInfo prop = type.GetProperty($"{topicKind}Topic");

        if (prop == null)
        {
            throw new NotSupportedException($"Unable to get the topic {topicKind} on {type.Name}");
        }

        return(prop.GetValue(this) as string);
    }
Ejemplo n.º 2
0
    public void SetTopic(HassTopicKind topicKind, string topic)
    {
        Type         type = GetType();
        PropertyInfo prop = type.GetProperty($"{topicKind}Topic");

        if (prop == null)
        {
            throw new NotSupportedException($"Unable to set topic {topicKind} on {type.Name}");
        }

        prop.SetValue(this, topic);
    }
Ejemplo n.º 3
0
 public static ISensorContainer SetValue(this ISensorContainer sensor, HassTopicKind topicKind, object value)
 {
     sensor.GetValueSender(topicKind).Value = value;
     return(sensor);
 }
Ejemplo n.º 4
0
    /// <summary>
    /// Get a well-known value sender for this device and entity
    /// </summary>
    public static MqttStateValueTopic GetValueSender(this ISensorContainer builder, HassTopicKind topicKind)
    {
        string topic = builder.Discovery.GetTopic(topicKind);

        return(builder.HassMqttManager.GetValueSender(topic));
    }