Table of Contents

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

connection HaMqttConnection
config DateTimeEntityConfig
onCommand Func<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

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(DateTimeOffset, bool, CancellationToken)

Publishes the current date/time.

public Task PublishStateAsync(DateTimeOffset value, bool retain = true, CancellationToken cancellationToken = default)

Parameters

value DateTimeOffset
retain bool
cancellationToken CancellationToken

Returns

Task

Events

CommandReceived

Raised when Home Assistant sends a new date/time.

public event Func<DateTimeOffset, Task>? CommandReceived

Event Type

Func<DateTimeOffset, Task>