Table of Contents

Class LockEntity

Namespace
HaMqttDiscoverable.Entities
Assembly
HaMqttDiscoverable.dll

A lock entity that can be locked/unlocked (and optionally opened) from Home Assistant.

public sealed class LockEntity : HaEntity<LockConfig>, IAsyncDisposable
Inheritance
LockEntity
Implements
Inherited Members

Constructors

LockEntity(HaMqttConnection, LockConfig, Func<LockCommand, Task>?)

Creates a lock entity from the given config, optionally subscribing onCommand to CommandReceived.

public LockEntity(HaMqttConnection connection, LockConfig config, Func<LockCommand, Task>? onCommand = null)

Parameters

connection HaMqttConnection
config LockConfig
onCommand Func<LockCommand, Task>

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

PublishStateAsync(LockState, bool, CancellationToken)

Publishes the lock's current state.

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

Parameters

state LockState
retain bool
cancellationToken CancellationToken

Returns

Task

Events

CommandReceived

Raised when Home Assistant sends a lock/unlock/open command.

public event Func<LockCommand, Task>? CommandReceived

Event Type

Func<LockCommand, Task>