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
connectionHaMqttConnectionconfigLockConfigonCommandFunc<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
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
PublishStateAsync(LockState, bool, CancellationToken)
Publishes the lock's current state.
public Task PublishStateAsync(LockState state, bool retain = true, CancellationToken cancellationToken = default)
Parameters
stateLockStateretainboolcancellationTokenCancellationToken
Returns
Events
CommandReceived
Raised when Home Assistant sends a lock/unlock/open command.
public event Func<LockCommand, Task>? CommandReceived