Class DateTimeEntity
- Namespace
- HaMqttDiscoverable.Entities
- Assembly
- HaMqttDiscoverable.dll
A combined date and time value that can be read and set from Home Assistant, formatted as
ISO 8601 ("yyyy-MM-ddTHH:mm:ss"). Named DateTimeEntity rather than DateTime to
avoid colliding with DateTime.
public sealed class DateTimeEntity : HaEntity<DateTimeEntityConfig>, IAsyncDisposable
- Inheritance
-
DateTimeEntity
- Implements
- Inherited Members
Constructors
DateTimeEntity(HaMqttConnection, DateTimeEntityConfig, Func<DateTimeOffset, Task>?)
Creates a date/time entity from the given config, optionally subscribing onCommand to CommandReceived.
public DateTimeEntity(HaMqttConnection connection, DateTimeEntityConfig config, Func<DateTimeOffset, Task>? onCommand = null)
Parameters
connectionHaMqttConnectionconfigDateTimeEntityConfigonCommandFunc<DateTimeOffset, 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(DateTimeOffset, bool, CancellationToken)
Publishes the current date/time.
public Task PublishStateAsync(DateTimeOffset value, bool retain = true, CancellationToken cancellationToken = default)
Parameters
valueDateTimeOffsetretainboolcancellationTokenCancellationToken
Returns
Events
CommandReceived
Raised when Home Assistant sends a new date/time.
public event Func<DateTimeOffset, Task>? CommandReceived