Remove uneeded constructor from Whirlpool climate (#143408)

* Remove uneeded constructor from Whirlpool climate

* Update homeassistant/components/whirlpool/climate.py

Co-authored-by: Josef Zweck <josef@zweck.dev>

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
Abílio Costa 2025-04-22 09:04:09 +01:00 committed by GitHub
parent 44f2897919
commit 6534dff4bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -63,13 +63,14 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up entry.""" """Set up entry."""
appliances_manager = config_entry.runtime_data appliances_manager = config_entry.runtime_data
aircons = [AirConEntity(hass, aircon) for aircon in appliances_manager.aircons] async_add_entities(AirConEntity(aircon) for aircon in appliances_manager.aircons)
async_add_entities(aircons)
class AirConEntity(WhirlpoolEntity, ClimateEntity): class AirConEntity(WhirlpoolEntity, ClimateEntity):
"""Representation of an air conditioner.""" """Representation of an air conditioner."""
_appliance: Aircon
_attr_fan_modes = SUPPORTED_FAN_MODES _attr_fan_modes = SUPPORTED_FAN_MODES
_attr_name = None _attr_name = None
_attr_hvac_modes = SUPPORTED_HVAC_MODES _attr_hvac_modes = SUPPORTED_HVAC_MODES
@ -86,86 +87,81 @@ class AirConEntity(WhirlpoolEntity, ClimateEntity):
_attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP _attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP
_attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, hass: HomeAssistant, aircon: Aircon) -> None:
"""Initialize the entity."""
super().__init__(aircon)
self._aircon = aircon
@property @property
def current_temperature(self) -> float: def current_temperature(self) -> float:
"""Return the current temperature.""" """Return the current temperature."""
return self._aircon.get_current_temp() return self._appliance.get_current_temp()
@property @property
def target_temperature(self) -> float: def target_temperature(self) -> float:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
return self._aircon.get_temp() return self._appliance.get_temp()
async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
await self._aircon.set_temp(kwargs.get(ATTR_TEMPERATURE)) await self._appliance.set_temp(kwargs.get(ATTR_TEMPERATURE))
@property @property
def current_humidity(self) -> int: def current_humidity(self) -> int:
"""Return the current humidity.""" """Return the current humidity."""
return self._aircon.get_current_humidity() return self._appliance.get_current_humidity()
@property @property
def target_humidity(self) -> int: def target_humidity(self) -> int:
"""Return the humidity we try to reach.""" """Return the humidity we try to reach."""
return self._aircon.get_humidity() return self._appliance.get_humidity()
async def async_set_humidity(self, humidity: int) -> None: async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity.""" """Set new target humidity."""
await self._aircon.set_humidity(humidity) await self._appliance.set_humidity(humidity)
@property @property
def hvac_mode(self) -> HVACMode | None: def hvac_mode(self) -> HVACMode | None:
"""Return current operation ie. heat, cool, fan.""" """Return current operation ie. heat, cool, fan."""
if not self._aircon.get_power_on(): if not self._appliance.get_power_on():
return HVACMode.OFF return HVACMode.OFF
mode: AirconMode = self._aircon.get_mode() mode: AirconMode = self._appliance.get_mode()
return AIRCON_MODE_MAP.get(mode) return AIRCON_MODE_MAP.get(mode)
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set HVAC mode.""" """Set HVAC mode."""
if hvac_mode == HVACMode.OFF: if hvac_mode == HVACMode.OFF:
await self._aircon.set_power_on(False) await self._appliance.set_power_on(False)
return return
if not (mode := HVAC_MODE_TO_AIRCON_MODE.get(hvac_mode)): if not (mode := HVAC_MODE_TO_AIRCON_MODE.get(hvac_mode)):
raise ValueError(f"Invalid hvac mode {hvac_mode}") raise ValueError(f"Invalid hvac mode {hvac_mode}")
await self._aircon.set_mode(mode) await self._appliance.set_mode(mode)
if not self._aircon.get_power_on(): if not self._appliance.get_power_on():
await self._aircon.set_power_on(True) await self._appliance.set_power_on(True)
@property @property
def fan_mode(self) -> str: def fan_mode(self) -> str:
"""Return the fan setting.""" """Return the fan setting."""
fanspeed = self._aircon.get_fanspeed() fanspeed = self._appliance.get_fanspeed()
return AIRCON_FANSPEED_MAP.get(fanspeed, FAN_OFF) return AIRCON_FANSPEED_MAP.get(fanspeed, FAN_OFF)
async def async_set_fan_mode(self, fan_mode: str) -> None: async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set fan mode.""" """Set fan mode."""
if not (fanspeed := FAN_MODE_TO_AIRCON_FANSPEED.get(fan_mode)): if not (fanspeed := FAN_MODE_TO_AIRCON_FANSPEED.get(fan_mode)):
raise ValueError(f"Invalid fan mode {fan_mode}") raise ValueError(f"Invalid fan mode {fan_mode}")
await self._aircon.set_fanspeed(fanspeed) await self._appliance.set_fanspeed(fanspeed)
@property @property
def swing_mode(self) -> str: def swing_mode(self) -> str:
"""Return the swing setting.""" """Return the swing setting."""
return SWING_HORIZONTAL if self._aircon.get_h_louver_swing() else SWING_OFF return SWING_HORIZONTAL if self._appliance.get_h_louver_swing() else SWING_OFF
async def async_set_swing_mode(self, swing_mode: str) -> None: async def async_set_swing_mode(self, swing_mode: str) -> None:
"""Set new target temperature.""" """Set new target temperature."""
await self._aircon.set_h_louver_swing(swing_mode == SWING_HORIZONTAL) await self._appliance.set_h_louver_swing(swing_mode == SWING_HORIZONTAL)
async def async_turn_on(self) -> None: async def async_turn_on(self) -> None:
"""Turn device on.""" """Turn device on."""
await self._aircon.set_power_on(True) await self._appliance.set_power_on(True)
async def async_turn_off(self) -> None: async def async_turn_off(self) -> None:
"""Turn device off.""" """Turn device off."""
await self._aircon.set_power_on(False) await self._appliance.set_power_on(False)