Table of Contents

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

connection HaMqttConnection
config ValveConfig

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

bool

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

payload string

Returns

Task

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

position int
retain bool
cancellationToken CancellationToken

Returns

Task

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

state ValveState
retain bool
cancellationToken CancellationToken

Returns

Task

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

Func<ValveCommand, Task>

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

Event Type

Func<int, Task>