Add climate hvac_action for ESPHome (#28993)

* Add climate action

* Bump aioesphomeapi
This commit is contained in:
Otto Winter 2019-11-25 14:13:19 +01:00 committed by Pascal Vizeli
parent 5edc45e9af
commit b927f40f00
4 changed files with 51 additions and 24 deletions

View file

@ -3,10 +3,11 @@ import logging
from typing import List, Optional from typing import List, Optional
from aioesphomeapi import ( from aioesphomeapi import (
ClimateAction,
ClimateFanMode,
ClimateInfo, ClimateInfo,
ClimateMode, ClimateMode,
ClimateState, ClimateState,
ClimateFanMode,
ClimateSwingMode, ClimateSwingMode,
) )
@ -15,32 +16,38 @@ from homeassistant.components.climate.const import (
ATTR_HVAC_MODE, ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_LOW,
HVAC_MODE_HEAT_COOL, CURRENT_HVAC_COOL,
HVAC_MODE_COOL, CURRENT_HVAC_DRY,
HVAC_MODE_HEAT, CURRENT_HVAC_FAN,
HVAC_MODE_FAN_ONLY, CURRENT_HVAC_HEAT,
HVAC_MODE_DRY, CURRENT_HVAC_OFF,
HVAC_MODE_OFF, CURRENT_HVAC_IDLE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE,
PRESET_AWAY,
PRESET_HOME,
FAN_ON,
FAN_OFF,
FAN_AUTO, FAN_AUTO,
FAN_DIFFUSE,
FAN_FOCUS,
FAN_HIGH,
FAN_LOW, FAN_LOW,
FAN_MEDIUM, FAN_MEDIUM,
FAN_HIGH,
FAN_MIDDLE, FAN_MIDDLE,
FAN_FOCUS, FAN_OFF,
FAN_DIFFUSE, FAN_ON,
SWING_OFF, HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_HOME,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
SWING_BOTH, SWING_BOTH,
SWING_VERTICAL,
SWING_HORIZONTAL, SWING_HORIZONTAL,
SWING_OFF,
SWING_VERTICAL,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
@ -85,6 +92,18 @@ def _climate_modes():
} }
@esphome_map_enum
def _climate_actions():
return {
ClimateAction.OFF: CURRENT_HVAC_OFF,
ClimateAction.COOLING: CURRENT_HVAC_COOL,
ClimateAction.HEATING: CURRENT_HVAC_HEAT,
ClimateAction.IDLE: CURRENT_HVAC_IDLE,
ClimateAction.DRYING: CURRENT_HVAC_DRY,
ClimateAction.FAN: CURRENT_HVAC_FAN,
}
@esphome_map_enum @esphome_map_enum
def _fan_modes(): def _fan_modes():
return { return {
@ -205,6 +224,14 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
"""Return current operation ie. heat, cool, idle.""" """Return current operation ie. heat, cool, idle."""
return _climate_modes.from_esphome(self._state.mode) return _climate_modes.from_esphome(self._state.mode)
@esphome_state_property
def hvac_action(self) -> Optional[str]:
"""Return current action."""
# HA has no support feature field for hvac_action
if not self._static_info.supports_action:
return None
return _climate_actions.from_esphome(self._state.action)
@esphome_state_property @esphome_state_property
def fan_mode(self): def fan_mode(self):
"""Return current fan setting.""" """Return current fan setting."""

View file

@ -4,7 +4,7 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome", "documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": [ "requirements": [
"aioesphomeapi==2.6.0" "aioesphomeapi==2.6.1"
], ],
"dependencies": [], "dependencies": [],
"zeroconf": ["_esphomelib._tcp.local."], "zeroconf": ["_esphomelib._tcp.local."],

View file

@ -145,7 +145,7 @@ aiobotocore==0.10.4
aiodns==2.0.0 aiodns==2.0.0
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.6.0 aioesphomeapi==2.6.1
# homeassistant.components.freebox # homeassistant.components.freebox
aiofreepybox==0.0.8 aiofreepybox==0.0.8

View file

@ -53,7 +53,7 @@ aioautomatic==0.6.5
aiobotocore==0.10.4 aiobotocore==0.10.4
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==2.6.0 aioesphomeapi==2.6.1
# homeassistant.components.emulated_hue # homeassistant.components.emulated_hue
# homeassistant.components.http # homeassistant.components.http