Class Valve
- Namespace
- HaMqttDiscoverable.Entities
- Assembly
- HaMqttDiscoverable.dll
A valve that can be opened/closed (optionally stopped mid-movement), or - when ReportsPosition is set - opened to a specific 0-100 position.
public sealed class Valve : HaEntity<ValveConfig>, IAsyncDisposable
- Inheritance
-
Valve
- Implements
- Inherited Members
Constructors
Valve(HaMqttConnection, ValveConfig)
Creates a valve from the given config.
public Valve(HaMqttConnection connection, ValveConfig config)
Parameters
connectionHaMqttConnectionconfigValveConfig
Properties
SupportsCommands
Whether this entity type accepts commands from Home Assistant (e.g. switches, numbers). Sensors are read-only and return false.
protected override bool SupportsCommands { get; }
Property Value
Methods
OnCommandReceivedAsync(string)
Called with the raw payload every time a message arrives on CommandTopic. Overridden by controllable entity types.
protected override Task OnCommandReceivedAsync(string payload)
Parameters
payloadstring
Returns
PublishPositionAsync(int, bool, CancellationToken)
Publishes the valve's current position (0-100). Only meaningful when ReportsPosition is true.
public Task PublishPositionAsync(int position, bool retain = true, CancellationToken cancellationToken = default)
Parameters
positionintretainboolcancellationTokenCancellationToken
Returns
PublishStateAsync(ValveState, bool, CancellationToken)
Publishes the valve's open/closed/opening/closing state. Only meaningful when ReportsPosition is false.
public Task PublishStateAsync(ValveState state, bool retain = true, CancellationToken cancellationToken = default)
Parameters
stateValveStateretainboolcancellationTokenCancellationToken
Returns
Events
CommandReceived
Raised when Home Assistant sends an open/close/stop command. Not raised for a valve with ReportsPosition set - see PositionCommandReceived instead.
public event Func<ValveCommand, Task>? CommandReceived
Event Type
PositionCommandReceived
Raised when Home Assistant sends a new target position (0-100). Only raised for a valve with ReportsPosition set.
public event Func<int, Task>? PositionCommandReceived