Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
apt-itude committed Dec 3, 2023
1 parent 05f13f3 commit 4d5598c
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions homeassistant/components/lyric/climate.py
Expand Up @@ -318,41 +318,29 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)

if device.changeableValues.mode == LYRIC_HVAC_MODE_HEAT_COOL:
# If the device supports "Auto" mode, don't pass the mode when setting the
# temperature
if device.changeableValues.autoChangeoverActive:
if target_temp_low is None or target_temp_high is None:
raise HomeAssistantError(
"Could not find target_temp_low and/or target_temp_high in"
" arguments"
)

# If the device supports "Auto" mode, don't pass the mode when setting the
# temperature
mode = (
None
if device.changeableValues.mode == LYRIC_HVAC_MODE_HEAT_COOL
else device.changeableValues.heatCoolMode
)

_LOGGER.debug("Set temperature: %s - %s", target_temp_low, target_temp_high)
try:
await self._update_thermostat(
self.location,
device,
coolSetpoint=target_temp_high,
heatSetpoint=target_temp_low,
)
except LYRIC_EXCEPTIONS as exception:
_LOGGER.error(exception)
await self.coordinator.async_refresh()
elif device.changeableValues.autoChangeoverActive:
# If the device uses "autoChangeoverActive", pass the "heatCoolMode" as the
# mode
if target_temp_low is None or target_temp_high is None:
raise HomeAssistantError(
"Could not find target_temp_low and/or target_temp_high in"
" arguments"
)
_LOGGER.debug("Set temperature: %s - %s", target_temp_low, target_temp_high)
try:
await self._update_thermostat(
self.location,
device,
coolSetpoint=target_temp_high,
heatSetpoint=target_temp_low,
mode=HVAC_MODES[device.changeableValues.heatCoolMode],
mode=mode,
)
except LYRIC_EXCEPTIONS as exception:
_LOGGER.error(exception)
Expand Down

0 comments on commit 4d5598c

Please sign in to comment.