From 94b162b06c6f2dc4141ce9aac90be394a73dd525 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:20:17 +0100 Subject: [PATCH] Use the action field enums in midea (#195975) --- homeassistant/components/midea/climate.py | 17 ++++++----------- homeassistant/components/midea/light.py | 17 ++++++++--------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/midea/climate.py b/homeassistant/components/midea/climate.py index f533e1401c6d..da10a610d602 100644 --- a/homeassistant/components/midea/climate.py +++ b/homeassistant/components/midea/climate.py @@ -11,7 +11,6 @@ from midealocal.devices.cf import DeviceAttributes as CFAttributes, MideaCFDevic from midealocal.devices.fb import DeviceAttributes as FBAttributes, MideaFBDevice from homeassistant.components.climate import ( - ATTR_HVAC_MODE, FAN_AUTO, FAN_HIGH, FAN_LOW, @@ -30,14 +29,10 @@ from homeassistant.components.climate import ( ClimateEntity, ClimateEntityDescription, ClimateEntityFeature, + ClimateServiceArgument, HVACMode, ) -from homeassistant.const import ( - ATTR_TEMPERATURE, - PRECISION_HALVES, - PRECISION_WHOLE, - UnitOfTemperature, -) +from homeassistant.const import PRECISION_HALVES, PRECISION_WHOLE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -246,10 +241,10 @@ class MideaClimate(MideaEntity, ClimateEntity): @override async def async_set_temperature(self, **kwargs: Any) -> None: """Midea Climate set temperature.""" - if ATTR_TEMPERATURE not in kwargs: + if ClimateServiceArgument.TEMPERATURE not in kwargs: return - temperature = kwargs[ATTR_TEMPERATURE] - hvac_mode = kwargs.get(ATTR_HVAC_MODE) + temperature = kwargs[ClimateServiceArgument.TEMPERATURE] + hvac_mode = kwargs.get(ClimateServiceArgument.HVAC_MODE) if hvac_mode == HVACMode.OFF: await self.async_turn_off() else: @@ -745,7 +740,7 @@ class MideaFBClimate(MideaClimate): @override async def async_set_temperature(self, **kwargs: Any) -> None: """Midea FB Climate set temperature.""" - wants_heat = kwargs.get(ATTR_HVAC_MODE) == HVACMode.HEAT + wants_heat = kwargs.get(ClimateServiceArgument.HVAC_MODE) == HVACMode.HEAT if wants_heat and self.hvac_mode == HVACMode.OFF: await self.async_turn_on() await super().async_set_temperature(**kwargs) diff --git a/homeassistant/components/midea/light.py b/homeassistant/components/midea/light.py index be7a22e755aa..4d08884241e6 100644 --- a/homeassistant/components/midea/light.py +++ b/homeassistant/components/midea/light.py @@ -7,14 +7,12 @@ from midealocal.const import DeviceType from midealocal.devices.x13 import Midea13Device from homeassistant.components.light import ( - ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP_KELVIN, - ATTR_EFFECT, EFFECT_OFF, ColorMode, LightEntity, LightEntityDescription, LightEntityFeature, + LightServiceArgument, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -145,16 +143,17 @@ class MideaLight(MideaEntity, LightEntity): with midea_api_call(): if not self.is_on: self._device.set_attribute(attr="power", value=True) - if ATTR_BRIGHTNESS in kwargs: + if LightServiceArgument.BRIGHTNESS in kwargs: self._device.set_attribute( - attr="brightness", value=kwargs[ATTR_BRIGHTNESS] + attr="brightness", value=kwargs[LightServiceArgument.BRIGHTNESS] ) - if ATTR_COLOR_TEMP_KELVIN in kwargs: + if LightServiceArgument.COLOR_TEMP_KELVIN in kwargs: self._device.set_attribute( - attr="color_temperature", value=kwargs[ATTR_COLOR_TEMP_KELVIN] + attr="color_temperature", + value=kwargs[LightServiceArgument.COLOR_TEMP_KELVIN], ) - if ATTR_EFFECT in kwargs: - effect = kwargs[ATTR_EFFECT] + if LightServiceArgument.EFFECT in kwargs: + effect = kwargs[LightServiceArgument.EFFECT] self._device.set_attribute( attr="effect", value="none" if effect == EFFECT_OFF else effect,