Skip to content

Commit

Permalink
Fix ESPHome climate migration (#25366)
Browse files Browse the repository at this point in the history
  • Loading branch information
OttoWinter authored and balloob committed Jul 21, 2019
1 parent 7a8130c commit b6ba24d
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions homeassistant/components/esphome/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def hvac_modes(self) -> List[str]:
for mode in self._static_info.supported_modes
]

@property
def preset_modes(self):
"""Return preset modes."""
return [PRESET_AWAY] if self._static_info.supports_away else []

@property
def target_temperature_step(self) -> float:
"""Return the supported step of target temperature."""
Expand All @@ -97,7 +102,7 @@ def supported_features(self) -> int:
"""Return the list of supported features."""
features = 0
if self._static_info.supports_two_point_target_temperature:
features |= (SUPPORT_TARGET_TEMPERATURE_RANGE)
features |= SUPPORT_TARGET_TEMPERATURE_RANGE
else:
features |= SUPPORT_TARGET_TEMPERATURE
if self._static_info.supports_away:
Expand All @@ -109,6 +114,11 @@ def hvac_mode(self) -> Optional[str]:
"""Return current operation ie. heat, cool, idle."""
return _climate_modes.from_esphome(self._state.mode)

@esphome_state_property
def preset_mode(self):
"""Return current preset mode."""
return PRESET_AWAY if self._state.away else None

@esphome_state_property
def current_temperature(self) -> Optional[float]:
"""Return the current temperature."""
Expand Down Expand Up @@ -143,29 +153,13 @@ async def async_set_temperature(self, **kwargs) -> None:
data['target_temperature_high'] = kwargs[ATTR_TARGET_TEMP_HIGH]
await self._client.climate_command(**data)

async def async_set_operation_mode(self, operation_mode) -> None:
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target operation mode."""
await self._client.climate_command(
key=self._static_info.key,
mode=_climate_modes.from_hass(operation_mode),
mode=_climate_modes.from_hass(hvac_mode),
)

@property
def preset_mode(self):
"""Return current preset mode."""
if self._state and self._state.away:
return PRESET_AWAY

return None

@property
def preset_modes(self):
"""Return preset modes."""
if self._static_info.supports_away:
return [PRESET_AWAY]

return []

async def async_set_preset_mode(self, preset_mode):
"""Set preset mode."""
away = preset_mode == PRESET_AWAY
Expand Down

0 comments on commit b6ba24d

Please sign in to comment.