Esphome fan direction (#44495)

This commit is contained in:
Jim Ekman 2021-01-27 10:40:33 +01:00 committed by GitHub
parent e12e2377af
commit 67b309394f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -1,13 +1,16 @@
"""Support for ESPHome fans.""" """Support for ESPHome fans."""
from typing import List, Optional from typing import List, Optional
from aioesphomeapi import FanInfo, FanSpeed, FanState from aioesphomeapi import FanDirection, FanInfo, FanSpeed, FanState
from homeassistant.components.fan import ( from homeassistant.components.fan import (
DIRECTION_FORWARD,
DIRECTION_REVERSE,
SPEED_HIGH, SPEED_HIGH,
SPEED_LOW, SPEED_LOW,
SPEED_MEDIUM, SPEED_MEDIUM,
SPEED_OFF, SPEED_OFF,
SUPPORT_DIRECTION,
SUPPORT_OSCILLATE, SUPPORT_OSCILLATE,
SUPPORT_SET_SPEED, SUPPORT_SET_SPEED,
FanEntity, 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): class EsphomeFan(EsphomeEntity, FanEntity):
"""A fan implementation for ESPHome.""" """A fan implementation for ESPHome."""
@ -88,6 +99,12 @@ class EsphomeFan(EsphomeEntity, FanEntity):
key=self._static_info.key, oscillating=oscillating 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 # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method # pylint: disable=invalid-overridden-method
@ -110,6 +127,13 @@ class EsphomeFan(EsphomeEntity, FanEntity):
return None return None
return self._state.oscillating 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 @property
def speed_list(self) -> Optional[List[str]]: def speed_list(self) -> Optional[List[str]]:
"""Get the list of available speeds.""" """Get the list of available speeds."""
@ -125,4 +149,6 @@ class EsphomeFan(EsphomeEntity, FanEntity):
flags |= SUPPORT_OSCILLATE flags |= SUPPORT_OSCILLATE
if self._static_info.supports_speed: if self._static_info.supports_speed:
flags |= SUPPORT_SET_SPEED flags |= SUPPORT_SET_SPEED
if self._static_info.supports_direction:
flags |= SUPPORT_DIRECTION
return flags return flags

View File

@ -3,7 +3,7 @@
"name": "ESPHome", "name": "ESPHome",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome", "documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": ["aioesphomeapi==2.6.3"], "requirements": ["aioesphomeapi==2.6.4"],
"zeroconf": ["_esphomelib._tcp.local."], "zeroconf": ["_esphomelib._tcp.local."],
"codeowners": ["@OttoWinter"], "codeowners": ["@OttoWinter"],
"after_dependencies": ["zeroconf", "tag"] "after_dependencies": ["zeroconf", "tag"]

View File

@ -154,7 +154,7 @@ aiodns==2.0.0
aioeafm==0.1.2 aioeafm==0.1.2
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.6.3 aioesphomeapi==2.6.4
# homeassistant.components.flo # homeassistant.components.flo
aioflo==0.4.1 aioflo==0.4.1

View File

@ -88,7 +88,7 @@ aiodns==2.0.0
aioeafm==0.1.2 aioeafm==0.1.2
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.6.3 aioesphomeapi==2.6.4
# homeassistant.components.flo # homeassistant.components.flo
aioflo==0.4.1 aioflo==0.4.1