Struct homie_device::Property
source · pub struct Property {
pub id: String,
pub name: String,
pub datatype: Datatype,
pub settable: bool,
pub retained: bool,
pub unit: Option<String>,
pub format: Option<String>,
}
Expand description
A property of a Homie node.
Fields§
§id: String
The subtopic ID of the property. This must be unique per node, and should follow the Homie ID format.
name: String
The human-readable name of the property.
datatype: Datatype
The data type of the property.
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.
retained: bool
Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.
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 must be specified if the datatype is Enum
or
Color
, and may be specified if the datatype is Integer
or Float
.
Implementations§
source§impl Property
impl Property
sourcepub fn new(
id: &str,
name: &str,
datatype: Datatype,
settable: bool,
retained: bool,
unit: Option<&str>,
format: Option<&str>
) -> Property
pub fn new( id: &str, name: &str, datatype: Datatype, settable: bool, retained: bool, unit: Option<&str>, format: Option<&str> ) -> Property
Create a new property with the given attributes.
This constructor allows you to create a property with any datatype, but doesn’t check that
the format
is valid. If possible, use the datatype-specific constructors instead.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.datatype
: The data type of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.format
: The format for the property, if any. This must be specified if the datatype isEnum
orColor
, and may be specified if the datatype isInteger
orFloat
.
sourcepub fn integer(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>,
format: Option<Range<i64>>
) -> Property
pub fn integer( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str>, format: Option<Range<i64>> ) -> Property
Create a new integer property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.format
: The valid range for the property, if any.
sourcepub fn float(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>,
format: Option<Range<f64>>
) -> Property
pub fn float( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str>, format: Option<Range<f64>> ) -> Property
Create a new floating-point property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.format
: The valid range for the property, if any.
sourcepub fn boolean(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>
) -> Property
pub fn boolean( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str> ) -> Property
Create a new boolean property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.
sourcepub fn string(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>
) -> Property
pub fn string( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str> ) -> Property
Create a new string property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.
sourcepub fn enumeration(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>,
format: &[&str]
) -> Property
pub fn enumeration( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str>, format: &[&str] ) -> Property
Create a new enum property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.format
: The possible values for the enum.
sourcepub fn color(
id: &str,
name: &str,
settable: bool,
retained: bool,
unit: Option<&str>,
format: ColorFormat
) -> Property
pub fn color( id: &str, name: &str, settable: bool, retained: bool, unit: Option<&str>, format: ColorFormat ) -> Property
Create a new color property with the given attributes.
Arguments
id
: The subtopic ID for the property. This must be unique per node, and follow the Homie ID format.name
: The human-readable name of the property.settable
: 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.retained
: Whether the property value is persisted by the MQTT broker. A non-retained property can be used for a momentary event, like a doorbell being pressed.unit
: The unit for the property, if any. This may be one of the recommended units, or any other custom unit.format
: The color format used for the property.