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); }
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); }
public static ISensorContainer SetValue(this ISensorContainer sensor, HassTopicKind topicKind, object value) { sensor.GetValueSender(topicKind).Value = value; return(sensor); }
/// <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)); }