Table of Contents

Class Event

Namespace
HaMqttDiscoverable.Entities
Assembly
HaMqttDiscoverable.dll

A read-only stream of discrete, named events, e.g. a doorbell's "single_press"/"double_press"/"held".

public sealed class Event : HaEntity<EventConfig>, IAsyncDisposable
Inheritance
Event
Implements
Inherited Members

Examples

var doorbell = new Event(connection, new EventConfig
{
    Name = "Doorbell",
    UniqueId = "doorbell",
    Device = device,
    EventTypes = new List<string> { "single_press", "double_press", "held" },
    DeviceClass = "button",
});
await doorbell.PublishDiscoveryAsync();
await doorbell.PublishEventAsync("single_press");

Constructors

Event(HaMqttConnection, EventConfig)

Creates an event entity from the given config.

public Event(HaMqttConnection connection, EventConfig config)

Parameters

connection HaMqttConnection
config EventConfig

Methods

PublishEventAsync(string, IReadOnlyDictionary<string, object?>?, CancellationToken)

Publishes an event. eventType must be one of EventTypes. extraAttributes, if given, are merged into the JSON payload alongside event_type and exposed as extra state attributes in Home Assistant.

public Task PublishEventAsync(string eventType, IReadOnlyDictionary<string, object?>? extraAttributes = null, CancellationToken cancellationToken = default)

Parameters

eventType string
extraAttributes IReadOnlyDictionary<string, object>
cancellationToken CancellationToken

Returns

Task