diff --git a/homeassistant/components/lg_thinq/climate.py b/homeassistant/components/lg_thinq/climate.py index ff57709f9a8..063705f5d0d 100644 --- a/homeassistant/components/lg_thinq/climate.py +++ b/homeassistant/components/lg_thinq/climate.py @@ -12,6 +12,8 @@ from thinqconnect.integration import ExtendedProperty from homeassistant.components.climate import ( ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, + SWING_OFF, + SWING_ON, ClimateEntity, ClimateEntityDescription, ClimateEntityFeature, @@ -73,6 +75,13 @@ HVAC_TO_STR: dict[HVACMode, str] = { THINQ_PRESET_MODE: list[str] = ["air_clean", "aroma", "energy_saving"] +STR_TO_SWING = { + "true": SWING_ON, + "false": SWING_OFF, +} + +SWING_TO_STR = {v: k for k, v in STR_TO_SWING.items()} + _LOGGER = logging.getLogger(__name__) @@ -142,6 +151,14 @@ class ThinQClimateEntity(ThinQEntity, ClimateEntity): self._attr_supported_features |= ( ClimateEntityFeature.TARGET_TEMPERATURE_RANGE ) + # Supports swing mode. + if self.data.swing_modes: + self._attr_swing_modes = [SWING_ON, SWING_OFF] + self._attr_supported_features |= ClimateEntityFeature.SWING_MODE + + if self.data.swing_horizontal_modes: + self._attr_swing_horizontal_modes = [SWING_ON, SWING_OFF] + self._attr_supported_features |= ClimateEntityFeature.SWING_HORIZONTAL_MODE def _update_status(self) -> None: """Update status itself.""" @@ -150,6 +167,13 @@ class ThinQClimateEntity(ThinQEntity, ClimateEntity): # Update fan, hvac and preset mode. if self.supported_features & ClimateEntityFeature.FAN_MODE: self._attr_fan_mode = self.data.fan_mode + if self.supported_features & ClimateEntityFeature.SWING_MODE: + self._attr_swing_mode = STR_TO_SWING.get(self.data.swing_mode) + if self.supported_features & ClimateEntityFeature.SWING_HORIZONTAL_MODE: + self._attr_swing_horizontal_mode = STR_TO_SWING.get( + self.data.swing_horizontal_mode + ) + if self.data.is_on: hvac_mode = self._requested_hvac_mode or self.data.hvac_mode if hvac_mode in STR_TO_HVAC: @@ -268,6 +292,34 @@ class ThinQClimateEntity(ThinQEntity, ClimateEntity): self.coordinator.api.async_set_fan_mode(self.property_id, fan_mode) ) + async def async_set_swing_mode(self, swing_mode: str) -> None: + """Set new swing mode.""" + _LOGGER.debug( + "[%s:%s] async_set_swing_mode: %s", + self.coordinator.device_name, + self.property_id, + swing_mode, + ) + await self.async_call_api( + self.coordinator.api.async_set_swing_mode( + self.property_id, SWING_TO_STR.get(swing_mode) + ) + ) + + async def async_set_swing_horizontal_mode(self, swing_horizontal_mode: str) -> None: + """Set new swing horizontal mode.""" + _LOGGER.debug( + "[%s:%s] async_set_swing_horizontal_mode: %s", + self.coordinator.device_name, + self.property_id, + swing_horizontal_mode, + ) + await self.async_call_api( + self.coordinator.api.async_set_swing_horizontal_mode( + self.property_id, SWING_TO_STR.get(swing_horizontal_mode) + ) + ) + def _round_by_step(self, temperature: float) -> float: """Round the value by step.""" if ( diff --git a/tests/components/lg_thinq/snapshots/test_climate.ambr b/tests/components/lg_thinq/snapshots/test_climate.ambr index e2fcc2540f3..db57e824487 100644 --- a/tests/components/lg_thinq/snapshots/test_climate.ambr +++ b/tests/components/lg_thinq/snapshots/test_climate.ambr @@ -20,6 +20,14 @@ 'preset_modes': list([ 'air_clean', ]), + 'swing_horizontal_modes': list([ + 'on', + 'off', + ]), + 'swing_modes': list([ + 'on', + 'off', + ]), 'target_temp_step': 1, }), 'config_entry_id': , @@ -44,7 +52,7 @@ 'original_name': None, 'platform': 'lg_thinq', 'previous_unique_id': None, - 'supported_features': , + 'supported_features': , 'translation_key': , 'unique_id': 'MW2-2E247F93-B570-46A6-B827-920E9E10F966_climate_air_conditioner', 'unit_of_measurement': None, @@ -73,7 +81,17 @@ 'preset_modes': list([ 'air_clean', ]), - 'supported_features': , + 'supported_features': , + 'swing_horizontal_mode': 'off', + 'swing_horizontal_modes': list([ + 'on', + 'off', + ]), + 'swing_mode': 'off', + 'swing_modes': list([ + 'on', + 'off', + ]), 'target_temp_high': None, 'target_temp_low': None, 'target_temp_step': 1,