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

source

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 is Enum or Color, and may be specified if the datatype is Integer or Float.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

pub fn make( id: &str, name: &str, datatype: Datatype, settable: bool, retained: bool, unit: Option<&str>, format: Option<String> ) -> Property

Trait Implementations§

source§

impl Clone for Property

source§

fn clone(&self) -> Property

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Property

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<Property> for Property

source§

fn eq(&self, other: &Property) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Property

source§

impl StructuralEq for Property

source§

impl StructuralPartialEq for Property

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.