Fan
fan
fan domain implementation.
SPEC
module-attribute
SPEC: DomainSpec[Fan] = register_domain(DomainSpec(name='fan', entity_cls=Fan))
The DomainSpec registered with the shared DomainRegistry.
Fan
Bases: Entity
A Home Assistant fan entity.
The public API uses intent-specific actions (on, off,
toggle, set_percentage, set_preset_mode,
set_direction, oscillate) and exposes structured state
(is_on, percentage, preset_mode, preset_modes,
oscillating, direction) rather than raw service calls.
Methods that depend on optional fan capabilities degrade safely: if
the underlying hardware does not advertise the relevant
FanEntityFeature bit in supported_features, the call becomes
a no-op that logs a debug message instead of raising. Callers that
need to know whether an action will actually be dispatched can
pre-check with the supports_* properties.
Source code in src/haclient/domains/fan.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
supports_set_speed
property
supports_set_speed: bool
Whether the device advertises FanEntityFeature.SET_SPEED.
supports_oscillate
property
supports_oscillate: bool
Whether the device advertises FanEntityFeature.OSCILLATE.
supports_direction
property
supports_direction: bool
Whether the device advertises FanEntityFeature.DIRECTION.
supports_preset_mode
property
supports_preset_mode: bool
Whether the device advertises FanEntityFeature.PRESET_MODE.
is_on
property
is_on: bool
Whether the fan is currently on.
percentage
property
percentage: int | None
Current fan speed in percent, or None when not reported.
preset_mode
property
preset_mode: str | None
Active preset mode, or None when the device has none.
preset_modes
property
preset_modes: list[str]
Preset modes supported by the device.
Returns an empty list when the device does not advertise modes. Non-string entries in the underlying attribute are filtered out.
oscillating
property
oscillating: bool | None
Whether the fan is currently oscillating.
Returns None when the device does not report this attribute.
direction
property
direction: str | None
Current fan direction ("forward" or "reverse").
Returns None when the device does not report a direction.
on_turn_on
on_turn_on(func: ValueChangeHandler) -> ValueChangeHandler
Register a listener for when the fan turns on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Sync or async callable invoked with |
required |
Returns:
| Type | Description |
|---|---|
callable
|
The same func, returned for decorator use. |
Source code in src/haclient/domains/fan.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
on_turn_off
on_turn_off(func: ValueChangeHandler) -> ValueChangeHandler
Register a listener for when the fan turns off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Sync or async callable invoked with |
required |
Returns:
| Type | Description |
|---|---|
callable
|
The same func, returned for decorator use. |
Source code in src/haclient/domains/fan.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
on_speed_change
on_speed_change(func: ValueChangeHandler) -> ValueChangeHandler
Register a listener for fan speed (percentage) changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Callable receiving the new |
required |
Returns:
| Type | Description |
|---|---|
callable
|
The same func, returned for decorator use. |
Source code in src/haclient/domains/fan.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
on_direction_change
on_direction_change(func: ValueChangeHandler) -> ValueChangeHandler
Register a listener for fan direction changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Callable receiving the new direction string as
|
required |
Returns:
| Type | Description |
|---|---|
callable
|
The same func, returned for decorator use. |
Source code in src/haclient/domains/fan.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
on
async
on() -> None
Turn the fan on.
Invokes the fan.turn_on Home Assistant service. No feature
check is performed.
Raises:
| Type | Description |
|---|---|
CommandError
|
If Home Assistant rejects the service call. |
HTTPError
|
If the REST call returns a non-2xx response. |
TimeoutError
|
If the call exceeds the configured request timeout. |
ConnectionClosedError
|
If the WebSocket disconnects mid-call. |
Source code in src/haclient/domains/fan.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
off
async
off() -> None
Turn the fan off.
Invokes the fan.turn_off Home Assistant service.
Raises:
| Type | Description |
|---|---|
CommandError
|
If Home Assistant rejects the service call. |
HTTPError
|
If the REST call returns a non-2xx response. |
TimeoutError
|
If the call exceeds the configured request timeout. |
ConnectionClosedError
|
If the WebSocket disconnects mid-call. |
Source code in src/haclient/domains/fan.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
toggle
async
toggle() -> None
Toggle the fan state.
Invokes the fan.toggle Home Assistant service.
Raises:
| Type | Description |
|---|---|
CommandError
|
If Home Assistant rejects the service call. |
HTTPError
|
If the REST call returns a non-2xx response. |
TimeoutError
|
If the call exceeds the configured request timeout. |
ConnectionClosedError
|
If the WebSocket disconnects mid-call. |
Source code in src/haclient/domains/fan.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
set_percentage
async
set_percentage(percentage: int) -> None
Set the fan speed, in percent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percentage
|
int
|
Target speed between 0 and 100 (inclusive). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If percentage is outside the 0-100 range. |
Notes
Degrades safely: if the fan does not advertise the
SET_SPEED feature, this method logs a debug message and
returns without raising. Callers can pre-check with
supports_set_speed.
Source code in src/haclient/domains/fan.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
set_preset_mode
async
set_preset_mode(mode: str) -> None
Activate a named preset mode, when supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Preset mode to activate. Must be one of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the device reports |
Notes
Degrades safely: if the fan does not advertise the
PRESET_MODE feature, or reports no preset modes at all,
this method logs a debug message and returns without raising.
Callers can pre-check with supports_preset_mode.
Source code in src/haclient/domains/fan.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
set_direction
async
set_direction(direction: str) -> None
Set the fan rotation direction, when supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
str
|
Either |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If direction is not |
Notes
Degrades safely: if the fan does not advertise the
DIRECTION feature, this method logs a debug message and
returns without raising. Callers can pre-check with
supports_direction.
Source code in src/haclient/domains/fan.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
oscillate
async
oscillate(oscillating: bool) -> None
Toggle oscillation on or off, when supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oscillating
|
bool
|
|
required |
Notes
Degrades safely: if the fan does not advertise the
OSCILLATE feature, this method logs a debug message and
returns without raising. Callers can pre-check with
supports_oscillate.
Source code in src/haclient/domains/fan.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |