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
connectionHaMqttConnectionconfigCoverConfig
Properties
SetPositionTopic
The topic this cover accepts a target position on, or null if SupportsPosition is false.
public string? SetPositionTopic { get; }
Property Value
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
TiltCommandTopic
The topic this cover accepts tilt commands on, or null if SupportsTilt is false.
public string? TiltCommandTopic { get; }
Property Value
TiltStatusTopic
The topic this cover publishes its tilt status to, or null if SupportsTilt is false.
public string? TiltStatusTopic { get; }
Property Value
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
payloadJsonObject
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, 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
positionintstateCoverState?retainboolcancellationTokenCancellationToken
Returns
PublishStateAsync(CoverState, bool, CancellationToken)
Publishes open/closed/opening/closing/stopped state.
public Task PublishStateAsync(CoverState state, bool retain = true, CancellationToken cancellationToken = default)
Parameters
stateCoverStateretainboolcancellationTokenCancellationToken
Returns
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
tiltintretainboolcancellationTokenCancellationToken
Returns
Events
CommandReceived
Raised when Home Assistant sends an open/close/stop command.
public event Func<CoverCommand, Task>? CommandReceived
Event Type
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
TiltCommandReceived
Raised when Home Assistant sends a new target tilt (0-100). Only raised when SupportsTilt is true.
public event Func<int, Task>? TiltCommandReceived