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:
- Updates its internal state to match the command value
- 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:
- Stores the command for the application to read via
wait()orcommand() - 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
impl Clone for CommandPolicy
Source§fn clone(&self) -> CommandPolicy
fn clone(&self) -> CommandPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more