From b927f40f00e4348184c66ee29c711d0ccc348798 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 25 Nov 2019 14:13:19 +0100 Subject: [PATCH] Add climate hvac_action for ESPHome (#28993) * Add climate action * Bump aioesphomeapi --- homeassistant/components/esphome/climate.py | 69 +++++++++++++------ .../components/esphome/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/esphome/climate.py b/homeassistant/components/esphome/climate.py index 49d284b6de2..14f684f1e32 100644 --- a/homeassistant/components/esphome/climate.py +++ b/homeassistant/components/esphome/climate.py @@ -3,10 +3,11 @@ import logging from typing import List, Optional from aioesphomeapi import ( + ClimateAction, + ClimateFanMode, ClimateInfo, ClimateMode, ClimateState, - ClimateFanMode, ClimateSwingMode, ) @@ -15,32 +16,38 @@ from homeassistant.components.climate.const import ( ATTR_HVAC_MODE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, - HVAC_MODE_HEAT_COOL, - HVAC_MODE_COOL, - HVAC_MODE_HEAT, - HVAC_MODE_FAN_ONLY, - HVAC_MODE_DRY, - HVAC_MODE_OFF, - SUPPORT_TARGET_TEMPERATURE, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE_RANGE, - SUPPORT_FAN_MODE, - SUPPORT_SWING_MODE, - PRESET_AWAY, - PRESET_HOME, - FAN_ON, - FAN_OFF, + CURRENT_HVAC_COOL, + CURRENT_HVAC_DRY, + CURRENT_HVAC_FAN, + CURRENT_HVAC_HEAT, + CURRENT_HVAC_OFF, + CURRENT_HVAC_IDLE, FAN_AUTO, + FAN_DIFFUSE, + FAN_FOCUS, + FAN_HIGH, FAN_LOW, FAN_MEDIUM, - FAN_HIGH, FAN_MIDDLE, - FAN_FOCUS, - FAN_DIFFUSE, - SWING_OFF, + FAN_OFF, + FAN_ON, + 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_VERTICAL, SWING_HORIZONTAL, + SWING_OFF, + SWING_VERTICAL, ) from homeassistant.const import ( 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 def _fan_modes(): return { @@ -205,6 +224,14 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice): """Return current operation ie. heat, cool, idle.""" 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 def fan_mode(self): """Return current fan setting.""" diff --git a/homeassistant/components/esphome/manifest.json b/homeassistant/components/esphome/manifest.json index 425ecc6ce32..549a063528f 100644 --- a/homeassistant/components/esphome/manifest.json +++ b/homeassistant/components/esphome/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/esphome", "requirements": [ - "aioesphomeapi==2.6.0" + "aioesphomeapi==2.6.1" ], "dependencies": [], "zeroconf": ["_esphomelib._tcp.local."], diff --git a/requirements_all.txt b/requirements_all.txt index 9c195ba2a85..82160c08e42 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -145,7 +145,7 @@ aiobotocore==0.10.4 aiodns==2.0.0 # homeassistant.components.esphome -aioesphomeapi==2.6.0 +aioesphomeapi==2.6.1 # homeassistant.components.freebox aiofreepybox==0.0.8 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 51e193c8e7f..0a3c5e576a4 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -53,7 +53,7 @@ aioautomatic==0.6.5 aiobotocore==0.10.4 # homeassistant.components.esphome -aioesphomeapi==2.6.0 +aioesphomeapi==2.6.1 # homeassistant.components.emulated_hue # homeassistant.components.http