Skip to content

Commit

Permalink
Remove unneeded preset_mode checks for mqtt climate (home-assistant#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored Jan 5, 2024
1 parent c7b6c9d commit 8c4a29c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,23 +989,17 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set a preset mode."""
if self._feature_preset_mode and self.preset_modes:
if preset_mode not in self.preset_modes and preset_mode is not PRESET_NONE:
_LOGGER.warning("'%s' is not a valid preset mode", preset_mode)
return
mqtt_payload = self._command_templates[CONF_PRESET_MODE_COMMAND_TEMPLATE](
preset_mode
)
await self._publish(
CONF_PRESET_MODE_COMMAND_TOPIC,
mqtt_payload,
)

if self._optimistic_preset_mode:
self._attr_preset_mode = preset_mode
self.async_write_ha_state()
mqtt_payload = self._command_templates[CONF_PRESET_MODE_COMMAND_TEMPLATE](
preset_mode
)
await self._publish(
CONF_PRESET_MODE_COMMAND_TOPIC,
mqtt_payload,
)

return
if self._optimistic_preset_mode:
self._attr_preset_mode = preset_mode
self.async_write_ha_state()

# Options CONF_AUX_COMMAND_TOPIC, CONF_AUX_STATE_TOPIC
# and CONF_AUX_STATE_TEMPLATE were deprecated in HA Core 2023.9
Expand Down

0 comments on commit 8c4a29c

Please sign in to comment.