Table of Contents

Class Cover

Namespace
HaMqttDiscoverable.Entities
Assembly
HaMqttDiscoverable.dll

A cover (blind, garage door, shade, awning, ...) that can be opened/closed/stopped, and optionally reports/accepts a 0-100 position and, independently, a 0-100 tilt.

public sealed class Cover : HaEntity<CoverConfig>, IAsyncDisposable
Inheritance
Cover
Implements
Inherited Members

Examples

var blind = new Cover(connection, new CoverConfig
{
    Name = "Blind",
    UniqueId = "living-room-blind",
    Device = device,
    DeviceClass = "blind",
    SupportsPosition = true,
});
blind.PositionCommandReceived += async position =>
{
    MoveTo(position);
    await blind.PublishPositionAsync(position);
};
await blind.PublishDiscoveryAsync();

Constructors

Cover(HaMqttConnection, CoverConfig)

Creates a cover from the given config.

public Cover(HaMqttConnection connection, CoverConfig config)

Parameters

connection HaMqttConnection
config CoverConfig

Properties

SetPositionTopic

The topic this cover accepts a target position on, or null if SupportsPosition is false.

public string? SetPositionTopic { get; }

Property Value

string

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

TiltCommandTopic

The topic this cover accepts tilt commands on, or null if SupportsTilt is false.

public string? TiltCommandTopic { get; }

Property Value

string

TiltStatusTopic

The topic this cover publishes its tilt status to, or null if SupportsTilt is false.

public string? TiltStatusTopic { get; }

Property Value

string

Methods

EnrichDiscoveryPayload(JsonObject)

Allows subclasses to add fields to the discovery payload that aren't part of EntityConfig directly.

protected override void EnrichDiscoveryPayload(JsonObject payload)

Parameters

payload JsonObject

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, CoverState?, bool, CancellationToken)

Publishes the cover's current position (0-100), and optionally its state, as a single JSON payload. Requires SupportsPosition.

public Task PublishPositionAsync(int position, CoverState? state = null, bool retain = true, CancellationToken cancellationToken = default)

Parameters

position int
state CoverState?
retain bool
cancellationToken CancellationToken

Returns

Task

PublishStateAsync(CoverState, bool, CancellationToken)

Publishes open/closed/opening/closing/stopped state.

public Task PublishStateAsync(CoverState state, bool retain = true, CancellationToken cancellationToken = default)

Parameters

state CoverState
retain bool
cancellationToken CancellationToken

Returns

Task

PublishTiltAsync(int, bool, CancellationToken)

Publishes the cover's current tilt (0-100). Requires SupportsTilt.

public Task PublishTiltAsync(int tilt, bool retain = true, CancellationToken cancellationToken = default)

Parameters

tilt int
retain bool
cancellationToken CancellationToken

Returns

Task

Events

CommandReceived

Raised when Home Assistant sends an open/close/stop command.

public event Func<CoverCommand, Task>? CommandReceived

Event Type

Func<CoverCommand, Task>

PositionCommandReceived

Raised when Home Assistant sends a new target position (0-100). Only raised when SupportsPosition is true.

public event Func<int, Task>? PositionCommandReceived

Event Type

Func<int, Task>

TiltCommandReceived

Raised when Home Assistant sends a new target tilt (0-100). Only raised when SupportsTilt is true.

public event Func<int, Task>? TiltCommandReceived

Event Type

Func<int, Task>