Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
105 changes: 45 additions & 60 deletions homeassistant/components/midea/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,15 @@ def set_temperature(self, **kwargs: Any) -> None:
if hvac_mode == HVACMode.OFF:
self.turn_off()
else:
mode = None
if hvac_mode:
if hvac_mode not in self.hvac_modes:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="unsupported_hvac_mode",
translation_placeholders={"hvac_mode": hvac_mode},
)
mode = self.hvac_modes.index(hvac_mode)
self._device.set_target_temperature(
if hvac_mode and hvac_mode not in self.hvac_modes:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="unsupported_hvac_mode",
translation_placeholders={"hvac_mode": hvac_mode},
)
self._device.set_raw_target_temperature(
target_temperature=temperature,
mode=mode,
hvac_mode=hvac_mode,
zone=self._zone,
)
Comment thread
chemelli74 marked this conversation as resolved.

Expand Down Expand Up @@ -319,12 +316,6 @@ class MideaACClimate(MideaClimate):
FAN_AUTO,
]

_attr_swing_modes: list[str] = [
SWING_OFF,
SWING_VERTICAL,
SWING_HORIZONTAL,
SWING_BOTH,
]
_attr_preset_modes = [
PRESET_NONE,
PRESET_COMFORT,
Expand Down Expand Up @@ -355,31 +346,13 @@ def __init__(
@property
@override
def hvac_modes(self) -> list[HVACMode]:
"""Midea AC Climate hvac modes."""
return (
[HVACMode.OFF]
+ (
[HVACMode.AUTO]
if self._device.capabilities.get("auto_mode", True)
else []
)
+ (
[HVACMode.COOL]
if self._device.capabilities.get("cool_mode", True)
else []
)
+ (
[HVACMode.DRY]
if self._device.capabilities.get("dry_mode", True)
else []
)
+ (
[HVACMode.HEAT]
if self._device.capabilities.get("heat_mode", True)
else []
)
+ [HVACMode.FAN_ONLY]
)
"""Midea AC Climate hvac modes.

The device reports the generic mode names in protocol-index order
(``off`` first, ``fan_only`` last), already filtered by its B5
capabilities.
"""
return [HVACMode(mode) for mode in self._device.raw_hvac_modes]
Comment thread
chemelli74 marked this conversation as resolved.

@property
@override
Expand Down Expand Up @@ -411,10 +384,32 @@ def fan_mode(self) -> str | None:
return mode
return FAN_SILENT

@property
@override
def supported_features(self) -> ClimateEntityFeature:
"""Midea AC Climate supported features.

AC devices on the BB subprotocol have no swing fields, so the
library reports no swing modes and rejects swing commands; hide the
swing action for them instead of letting it raise.
"""
features = super().supported_features
if not self._device.raw_swing_modes:
features &= ~ClimateEntityFeature.SWING_MODE
return features

@property
@override
def swing_modes(self) -> list[str] | None:
"""Midea AC Climate swing modes."""
return [str(mode) for mode in self._device.raw_swing_modes] or None

Comment thread
chemelli74 marked this conversation as resolved.
Outdated
@property
@override
def swing_mode(self) -> str | None:
"""Midea AC Climate swing mode."""
if not self._device.raw_swing_modes:
return None
Comment thread
chemelli74 marked this conversation as resolved.
Outdated
vertical = bool(self._device.get_attribute(ACAttributes.swing_vertical))
horizontal = bool(self._device.get_attribute(ACAttributes.swing_horizontal))
return _SWING_STATE_MAP.get((vertical, horizontal))
Expand All @@ -439,13 +434,7 @@ def set_fan_mode(self, fan_mode: str) -> None:
@override
def set_swing_mode(self, swing_mode: str) -> None:
"""Midea AC Climate set swing mode."""
swing_vertical, swing_horizontal = _SWING_MODE_MAP.get(
swing_mode, (False, False)
)
self._device.set_swing(
swing_vertical=swing_vertical,
swing_horizontal=swing_horizontal,
)
self._device.set_raw_swing_mode(swing_mode)
Comment thread
chemelli74 marked this conversation as resolved.


class MideaCCClimate(MideaClimate):
Expand Down Expand Up @@ -481,16 +470,13 @@ def __init__(
@override
def fan_modes(self) -> list[str] | None:
"""Midea CC Climate fan modes."""
return self._device.fan_modes
return list(self._device.raw_fan_modes)

@property
@override
def fan_mode(self) -> str | None:
"""Midea CC Climate fan mode."""
fan_mode = self._device.get_attribute(CCAttributes.fan_speed)
if not isinstance(fan_mode, str):
return None
return fan_mode
return self._device.raw_fan_mode

@property
@override
Expand All @@ -510,7 +496,7 @@ def swing_mode(self) -> str | None:
@override
def set_fan_mode(self, fan_mode: str) -> None:
"""Midea CC Climate set fan mode."""
self._device.set_attribute(attr=CCAttributes.fan_speed, value=fan_mode)
self._device.set_raw_fan_mode(fan_mode)

@override
def set_swing_mode(self, swing_mode: str) -> None:
Expand Down Expand Up @@ -554,10 +540,9 @@ def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if hvac_mode == HVACMode.OFF:
self.turn_off()
else:
target_temperature = self.target_temperature or self.min_temp
self._device.set_target_temperature(
target_temperature=target_temperature,
mode=self._hvac_to_protocol_mode(hvac_mode),
self._device.set_raw_target_temperature(
target_temperature=self.target_temperature or self.min_temp,
hvac_mode=hvac_mode,
Comment thread
chemelli74 marked this conversation as resolved.
)

@property
Expand Down Expand Up @@ -709,7 +694,7 @@ def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if hvac_mode == HVACMode.OFF:
self.turn_off()
else:
self._device.set_mode(self._zone, self._hvac_to_protocol_mode(hvac_mode))
self._device.set_raw_hvac_mode(hvac_mode, zone=self._zone)
Comment thread
chemelli74 marked this conversation as resolved.


class MideaFBClimate(MideaClimate):
Expand Down
Loading
Loading