Struct Property

Source
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

Source

pub fn has_required_attributes(&self) -> bool

Returns whether all the required attributes of the property are filled in.

Source

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.

Source

pub fn color_format(&self) -> Result<ColorFormat, ValueError>

If the datatype of the property is Color, returns the color format.

Source

pub fn enum_values(&self) -> Result<Vec<&str>, ValueError>

If the datatype of the property is Enum, gets the possible values of the enum.

Source

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

Trait Implementations§

Source§

impl Clone for Property

Source§

fn clone(&self) -> Property

Returns a duplicate of the value. Read more
1.0.0 · Source§

const 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 for Property

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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 StructuralPartialEq for Property

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.