CommandPolicy

Enum CommandPolicy 

Source
pub enum CommandPolicy {
    PublishState,
    Manual,
}
Expand description

Determines how an entity handles commands received from Home Assistant.

This policy controls whether an entity automatically publishes its state when it receives a command from Home Assistant, or if the application should handle state updates manually.

§Variants

§PublishState (Default)

When a command is received from Home Assistant, the entity automatically:

  1. Updates its internal state to match the command value
  2. Publishes the new state back to Home Assistant

This is useful for simple entities where the command should immediately be reflected as the current state, such as:

  • A switch that turns on/off immediately when commanded
  • A number input that updates its value when changed in the UI

§Manual

When a command is received from Home Assistant, the entity:

  1. Stores the command for the application to read via wait() or command()
  2. Does NOT automatically update or publish the state

The application must manually update the entity’s state after processing the command. This is useful when:

  • The command triggers an action that may fail (e.g., turning on a motor)
  • The actual state may differ from the commanded state
  • You need to validate or transform the command before applying it

§Examples

§Auto-publish (default)

let config = SwitchConfig {
    command_policy: CommandPolicy::PublishState, // or just use default
    ..Default::default()
};
// When Home Assistant sends "ON", the switch state automatically becomes "ON"

§Manual control

let config = SwitchConfig {
    command_policy: CommandPolicy::Manual,
    ..Default::default()
};

loop {
    let command = switch.wait().await;

    // Try to perform the action
    if turn_on_motor().await.is_ok() {
        // Only update state if the action succeeded
        switch.set(command);
    }
}

Variants§

§

PublishState

Automatically publish the entity’s state when a command is received.

§

Manual

Do not automatically publish state. The application must manually update the state.

Trait Implementations§

Source§

impl Clone for CommandPolicy

Source§

fn clone(&self) -> CommandPolicy

Returns a duplicate 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 CommandPolicy

Source§

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

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

impl Default for CommandPolicy

Source§

fn default() -> CommandPolicy

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CommandPolicy

Source§

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

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

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 Copy for CommandPolicy

Source§

impl Eq for CommandPolicy

Source§

impl StructuralPartialEq for CommandPolicy

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