pub struct Property {
pub id: String,
pub name: Option<String>,
pub datatype: Option<Datatype>,
pub settable: bool,
pub retained: bool,
pub unit: Option<String>,
pub format: Option<String>,
pub value: Option<String>,
}
Expand description
A property of a Homie node.
The id
, name
and datatype
are required, but might not be available immediately when the
property is first discovered. The other attributes are optional.
Fields§
§id: String
The subtopic ID of the property. This is unique per node, and should follow the Homie ID format.
name: Option<String>
The human-readable name of the property. This is a required attribute, but might not be available as soon as the property is first discovered.
datatype: Option<Datatype>
The data type of the property. This is a required attribute, but might not be available as soon as the property is first discovered.
settable: bool
Whether the property can be set by the Homie controller. This should be true for properties like the brightness or power state of a light, and false for things like the temperature reading of a sensor. It is false by default.
retained: bool
Whether the property value is retained by the MQTT broker. This is true by default.
unit: Option<String>
The unit of the property, if any. This may be one of the recommended units, or any other custom unit.
format: Option<String>
The format of the property, if any. This should be specified if the datatype is Enum
or
Color
, and may be specified if the datatype is Integer
or Float
.
This field holds the raw string received from the device. Use color_format, enum_values or range to parse it according to the datatype of the property.
value: Option<String>
The current value of the property, if known. This may change frequently.
This field holds the raw string received from the device. Use value to parse it according to the datatype of the property.
Implementations§
Source§impl Property
impl Property
Sourcepub fn has_required_attributes(&self) -> bool
pub fn has_required_attributes(&self) -> bool
Returns whether all the required attributes of the property are filled in.
Sourcepub fn value<T: Value>(&self) -> Result<T, ValueError>
pub fn value<T: Value>(&self) -> Result<T, ValueError>
The value of the property, parsed as the appropriate Homie Value
type. This will return
WrongDatatype
if you try to parse it as a type which doesn’t match the datatype declared
by the property.
Sourcepub fn color_format(&self) -> Result<ColorFormat, ValueError>
pub fn color_format(&self) -> Result<ColorFormat, ValueError>
If the datatype of the property is Color
, returns the color format.
Sourcepub fn enum_values(&self) -> Result<Vec<&str>, ValueError>
pub fn enum_values(&self) -> Result<Vec<&str>, ValueError>
If the datatype of the property is Enum
, gets the possible values of the enum.
Sourcepub fn range<T: Value + Copy>(&self) -> Result<RangeInclusive<T>, ValueError>
pub fn range<T: Value + Copy>(&self) -> Result<RangeInclusive<T>, ValueError>
If the dataype of the property is Integer
or Float
, gets the allowed range of values (if
any is declared by the device).