Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from homeassistant.components.climate import (
PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA,
ClimateEntity,
ClimateEntityFeature,
)
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
Expand All @@ -23,14 +22,13 @@
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_NONE,
SWING_OFF,
SWING_ON,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
Expand All @@ -43,7 +41,6 @@
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
STATE_ON,
)
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -272,12 +269,12 @@ def valid_preset_mode_configuration(config):
vol.Optional(
CONF_MODE_LIST,
default=[
HVAC_MODE_AUTO,
HVAC_MODE_OFF,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVACMode.AUTO,
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.FAN_ONLY,
],
): cv.ensure_list,
vol.Optional(CONF_MODE_STATE_TEMPLATE): cv.template,
Expand Down Expand Up @@ -309,7 +306,7 @@ def valid_preset_mode_configuration(config):
vol.Optional(CONF_SWING_MODE_COMMAND_TEMPLATE): cv.template,
vol.Optional(CONF_SWING_MODE_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(
CONF_SWING_MODE_LIST, default=[STATE_ON, HVAC_MODE_OFF]
CONF_SWING_MODE_LIST, default=[SWING_ON, SWING_OFF]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a bug...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like it. And the underlying strings are "on"/"off" anyway in both cases, so this change should make no difference.

): cv.ensure_list,
vol.Optional(CONF_SWING_MODE_STATE_TEMPLATE): cv.template,
vol.Optional(CONF_SWING_MODE_STATE_TOPIC): mqtt.valid_subscribe_topic,
Expand Down Expand Up @@ -460,9 +457,9 @@ def _setup_from_config(self, config):
if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None:
self._current_fan_mode = FAN_LOW
if self._topic[CONF_SWING_MODE_STATE_TOPIC] is None:
self._current_swing_mode = HVAC_MODE_OFF
self._current_swing_mode = SWING_OFF
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a bug also...

if self._topic[CONF_MODE_STATE_TOPIC] is None:
self._current_operation = HVAC_MODE_OFF
self._current_operation = HVACMode.OFF
self._feature_preset_mode = CONF_PRESET_MODE_COMMAND_TOPIC in config
if self._feature_preset_mode:
self._preset_modes = config[CONF_PRESET_MODES_LIST]
Expand Down Expand Up @@ -773,17 +770,17 @@ def target_temperature_high(self):
return self._target_temp_high

@property
def hvac_action(self):
def hvac_action(self) -> HVACAction | None:
"""Return the current running hvac operation if supported."""
return self._action

@property
def hvac_mode(self):
def hvac_mode(self) -> HVACMode:
"""Return current operation ie. heat, cool, idle."""
return self._current_operation

@property
def hvac_modes(self):
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available operation modes."""
return self._config[CONF_MODE_LIST]

Expand Down Expand Up @@ -859,7 +856,7 @@ async def _set_temperature(
setattr(self, attr, temp)

# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
if self._send_if_off or self._current_operation != HVAC_MODE_OFF:
if self._send_if_off or self._current_operation != HVACMode.OFF:
payload = self._command_templates[cmnd_template](temp)
await self._publish(cmnd_topic, payload)

Expand Down Expand Up @@ -899,7 +896,7 @@ async def async_set_temperature(self, **kwargs):
async def async_set_swing_mode(self, swing_mode):
"""Set new swing mode."""
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
if self._send_if_off or self._current_operation != HVAC_MODE_OFF:
if self._send_if_off or self._current_operation != HVACMode.OFF:
payload = self._command_templates[CONF_SWING_MODE_COMMAND_TEMPLATE](
swing_mode
)
Expand All @@ -912,7 +909,7 @@ async def async_set_swing_mode(self, swing_mode):
async def async_set_fan_mode(self, fan_mode):
"""Set new target temperature."""
# CONF_SEND_IF_OFF is deprecated, support will be removed with release 2022.9
if self._send_if_off or self._current_operation != HVAC_MODE_OFF:
if self._send_if_off or self._current_operation != HVACMode.OFF:
payload = self._command_templates[CONF_FAN_MODE_COMMAND_TEMPLATE](fan_mode)
await self._publish(CONF_FAN_MODE_COMMAND_TOPIC, payload)

Expand All @@ -922,7 +919,7 @@ async def async_set_fan_mode(self, fan_mode):

async def async_set_hvac_mode(self, hvac_mode) -> None:
"""Set new operation mode."""
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
await self._publish(
CONF_POWER_COMMAND_TOPIC, self._config[CONF_PAYLOAD_OFF]
)
Expand Down
39 changes: 15 additions & 24 deletions tests/components/mqtt/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,14 @@
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_ACTIONS,
DOMAIN as CLIMATE_DOMAIN,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
PRESET_AWAY,
PRESET_ECO,
PRESET_NONE,
SUPPORT_AUX_HEAT,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
ClimateEntityFeature,
HVACMode,
)
from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.setup import async_setup_component

from .test_common import (
Expand Down Expand Up @@ -171,12 +162,12 @@ async def test_supported_features(hass, mqtt_mock):

state = hass.states.get(ENTITY_CLIMATE)
support = (
SUPPORT_TARGET_TEMPERATURE
| SUPPORT_SWING_MODE
| SUPPORT_FAN_MODE
| SUPPORT_PRESET_MODE
| SUPPORT_AUX_HEAT
| SUPPORT_TARGET_TEMPERATURE_RANGE
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.AUX_HEAT
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)

assert state.attributes.get("supported_features") == support
Expand All @@ -190,12 +181,12 @@ async def test_get_hvac_modes(hass, mqtt_mock):
state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes")
assert [
HVAC_MODE_AUTO,
STATE_OFF,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVACMode.AUTO,
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.FAN_ONLY,
] == modes


Expand Down