Fix ESPHome climate migration (#25366)

This commit is contained in:
Otto Winter 2019-07-21 19:01:16 +02:00 committed by Paulus Schoutsen
parent 7a8130cd2b
commit b6ba24de5d

View file

@ -76,6 +76,11 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
for mode in self._static_info.supported_modes 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 @property
def target_temperature_step(self) -> float: def target_temperature_step(self) -> float:
"""Return the supported step of target temperature.""" """Return the supported step of target temperature."""
@ -97,7 +102,7 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
"""Return the list of supported features.""" """Return the list of supported features."""
features = 0 features = 0
if self._static_info.supports_two_point_target_temperature: if self._static_info.supports_two_point_target_temperature:
features |= (SUPPORT_TARGET_TEMPERATURE_RANGE) features |= SUPPORT_TARGET_TEMPERATURE_RANGE
else: else:
features |= SUPPORT_TARGET_TEMPERATURE features |= SUPPORT_TARGET_TEMPERATURE
if self._static_info.supports_away: if self._static_info.supports_away:
@ -109,6 +114,11 @@ 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 preset_mode(self):
"""Return current preset mode."""
return PRESET_AWAY if self._state.away else None
@esphome_state_property @esphome_state_property
def current_temperature(self) -> Optional[float]: def current_temperature(self) -> Optional[float]:
"""Return the current temperature.""" """Return the current temperature."""
@ -143,29 +153,13 @@ class EsphomeClimateDevice(EsphomeEntity, ClimateDevice):
data['target_temperature_high'] = kwargs[ATTR_TARGET_TEMP_HIGH] data['target_temperature_high'] = kwargs[ATTR_TARGET_TEMP_HIGH]
await self._client.climate_command(**data) 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.""" """Set new target operation mode."""
await self._client.climate_command( await self._client.climate_command(
key=self._static_info.key, 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): async def async_set_preset_mode(self, preset_mode):
"""Set preset mode.""" """Set preset mode."""
away = preset_mode == PRESET_AWAY away = preset_mode == PRESET_AWAY