mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Esphome fan direction (#44495)
This commit is contained in:
parent
e12e2377af
commit
67b309394f
@ -1,13 +1,16 @@
|
||||
"""Support for ESPHome fans."""
|
||||
from typing import List, Optional
|
||||
|
||||
from aioesphomeapi import FanInfo, FanSpeed, FanState
|
||||
from aioesphomeapi import FanDirection, FanInfo, FanSpeed, FanState
|
||||
|
||||
from homeassistant.components.fan import (
|
||||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
SPEED_HIGH,
|
||||
SPEED_LOW,
|
||||
SPEED_MEDIUM,
|
||||
SPEED_OFF,
|
||||
SUPPORT_DIRECTION,
|
||||
SUPPORT_OSCILLATE,
|
||||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
@ -47,6 +50,14 @@ def _fan_speeds():
|
||||
}
|
||||
|
||||
|
||||
@esphome_map_enum
|
||||
def _fan_directions():
|
||||
return {
|
||||
FanDirection.FORWARD: DIRECTION_FORWARD,
|
||||
FanDirection.REVERSE: DIRECTION_REVERSE,
|
||||
}
|
||||
|
||||
|
||||
class EsphomeFan(EsphomeEntity, FanEntity):
|
||||
"""A fan implementation for ESPHome."""
|
||||
|
||||
@ -88,6 +99,12 @@ class EsphomeFan(EsphomeEntity, FanEntity):
|
||||
key=self._static_info.key, oscillating=oscillating
|
||||
)
|
||||
|
||||
async def async_set_direction(self, direction: str):
|
||||
"""Set direction of the fan."""
|
||||
await self._client.fan_command(
|
||||
key=self._static_info.key, direction=_fan_directions.from_hass(direction)
|
||||
)
|
||||
|
||||
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
|
||||
# pylint: disable=invalid-overridden-method
|
||||
|
||||
@ -110,6 +127,13 @@ class EsphomeFan(EsphomeEntity, FanEntity):
|
||||
return None
|
||||
return self._state.oscillating
|
||||
|
||||
@esphome_state_property
|
||||
def current_direction(self) -> None:
|
||||
"""Return the current fan direction."""
|
||||
if not self._static_info.supports_direction:
|
||||
return None
|
||||
return _fan_directions.from_esphome(self._state.direction)
|
||||
|
||||
@property
|
||||
def speed_list(self) -> Optional[List[str]]:
|
||||
"""Get the list of available speeds."""
|
||||
@ -125,4 +149,6 @@ class EsphomeFan(EsphomeEntity, FanEntity):
|
||||
flags |= SUPPORT_OSCILLATE
|
||||
if self._static_info.supports_speed:
|
||||
flags |= SUPPORT_SET_SPEED
|
||||
if self._static_info.supports_direction:
|
||||
flags |= SUPPORT_DIRECTION
|
||||
return flags
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "ESPHome",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/esphome",
|
||||
"requirements": ["aioesphomeapi==2.6.3"],
|
||||
"requirements": ["aioesphomeapi==2.6.4"],
|
||||
"zeroconf": ["_esphomelib._tcp.local."],
|
||||
"codeowners": ["@OttoWinter"],
|
||||
"after_dependencies": ["zeroconf", "tag"]
|
||||
|
@ -154,7 +154,7 @@ aiodns==2.0.0
|
||||
aioeafm==0.1.2
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==2.6.3
|
||||
aioesphomeapi==2.6.4
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
@ -88,7 +88,7 @@ aiodns==2.0.0
|
||||
aioeafm==0.1.2
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==2.6.3
|
||||
aioesphomeapi==2.6.4
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user