Class Fan
- Namespace
- HaMqttDiscoverable.Entities
- Assembly
- HaMqttDiscoverable.dll
A fan that can be turned on/off, and optionally has a speed percentage and/or named preset
modes. Oscillation and direction (forward/reverse) control aren't exposed by this type yet -
they'd follow the same auxiliary-topic pattern as SupportsPercentage
support; see HaEntity.RegisterAuxiliaryCommandTopic if you need to add them.
public sealed class Fan : HaEntity<FanConfig>, IAsyncDisposable
- Inheritance
-
Fan
- Implements
- Inherited Members
Constructors
Fan(HaMqttConnection, FanConfig)
Creates a fan from the given config.
public Fan(HaMqttConnection connection, FanConfig config)
Parameters
connectionHaMqttConnectionconfigFanConfig
Properties
PercentageCommandTopic
The topic this fan accepts a speed percentage on, or null if SupportsPercentage is false.
public string? PercentageCommandTopic { get; }
Property Value
PercentageStateTopic
The topic this fan publishes its speed percentage to, or null if SupportsPercentage is false.
public string? PercentageStateTopic { get; }
Property Value
PresetModeCommandTopic
The topic this fan accepts a preset mode on, or null if PresetModes is empty.
public string? PresetModeCommandTopic { get; }
Property Value
PresetModeStateTopic
The topic this fan publishes its preset mode to, or null if PresetModes is empty.
public string? PresetModeStateTopic { get; }
Property Value
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
EnrichDiscoveryPayload(JsonObject)
Allows subclasses to add fields to the discovery payload that aren't part of EntityConfig directly.
protected override void EnrichDiscoveryPayload(JsonObject payload)
Parameters
payloadJsonObject
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
PublishPercentageAsync(int, bool, CancellationToken)
Publishes the fan's current speed (0-100). Requires SupportsPercentage.
public Task PublishPercentageAsync(int percentage, bool retain = true, CancellationToken cancellationToken = default)
Parameters
percentageintretainboolcancellationTokenCancellationToken
Returns
PublishPresetModeAsync(string, bool, CancellationToken)
Publishes the fan's current preset mode. Requires PresetModes to be non-empty.
public Task PublishPresetModeAsync(string presetMode, bool retain = true, CancellationToken cancellationToken = default)
Parameters
presetModestringretainboolcancellationTokenCancellationToken
Returns
PublishStateAsync(bool, bool, CancellationToken)
Publishes the fan's current on/off state.
public Task PublishStateAsync(bool isOn, bool retain = true, CancellationToken cancellationToken = default)
Parameters
isOnboolretainboolcancellationTokenCancellationToken
Returns
Events
CommandReceived
Raised when Home Assistant sends a command to turn the fan on or off.
public event Func<bool, Task>? CommandReceived
Event Type
PercentageCommandReceived
Raised when Home Assistant sends a new speed percentage (0-100). Only raised when SupportsPercentage is true.
public event Func<int, Task>? PercentageCommandReceived
Event Type
PresetModeCommandReceived
Raised when Home Assistant sends a new preset mode. Only raised when PresetModes is non-empty.
public event Func<string, Task>? PresetModeCommandReceived