Add missing ATTR_HVAC_MODE of async_set_temperature to LG ThinQ (#137621)

Co-authored-by: yunseon.park <yunseon.park@lge.com>
pull/139255/head
LG-ThinQ-Integration 2025-02-25 22:14:04 +09:00 committed by GitHub
parent d7301c62e2
commit 507c0739df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 39 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass
import logging import logging
from typing import Any from typing import Any
@ -10,6 +9,7 @@ from thinqconnect import DeviceType
from thinqconnect.integration import ExtendedProperty from thinqconnect.integration import ExtendedProperty
from homeassistant.components.climate import ( from homeassistant.components.climate import (
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_LOW,
SWING_OFF, SWING_OFF,
@ -28,31 +28,19 @@ from . import ThinqConfigEntry
from .coordinator import DeviceDataUpdateCoordinator from .coordinator import DeviceDataUpdateCoordinator
from .entity import ThinQEntity from .entity import ThinQEntity
DEVICE_TYPE_CLIMATE_MAP: dict[DeviceType, tuple[ClimateEntityDescription, ...]] = {
@dataclass(frozen=True, kw_only=True)
class ThinQClimateEntityDescription(ClimateEntityDescription):
"""Describes ThinQ climate entity."""
min_temp: float | None = None
max_temp: float | None = None
step: float | None = None
DEVICE_TYPE_CLIMATE_MAP: dict[DeviceType, tuple[ThinQClimateEntityDescription, ...]] = {
DeviceType.AIR_CONDITIONER: ( DeviceType.AIR_CONDITIONER: (
ThinQClimateEntityDescription( ClimateEntityDescription(
key=ExtendedProperty.CLIMATE_AIR_CONDITIONER, key=ExtendedProperty.CLIMATE_AIR_CONDITIONER,
name=None, name=None,
translation_key=ExtendedProperty.CLIMATE_AIR_CONDITIONER, translation_key=ExtendedProperty.CLIMATE_AIR_CONDITIONER,
), ),
), ),
DeviceType.SYSTEM_BOILER: ( DeviceType.SYSTEM_BOILER: (
ThinQClimateEntityDescription( ClimateEntityDescription(
key=ExtendedProperty.CLIMATE_SYSTEM_BOILER, key=ExtendedProperty.CLIMATE_SYSTEM_BOILER,
name=None, name=None,
min_temp=16, translation_key=ExtendedProperty.CLIMATE_SYSTEM_BOILER,
max_temp=30,
step=1,
), ),
), ),
} }
@ -65,13 +53,7 @@ STR_TO_HVAC: dict[str, HVACMode] = {
"heat": HVACMode.HEAT, "heat": HVACMode.HEAT,
} }
HVAC_TO_STR: dict[HVACMode, str] = { HVAC_TO_STR = {v: k for k, v in STR_TO_HVAC.items()}
HVACMode.AUTO: "auto",
HVACMode.COOL: "cool",
HVACMode.DRY: "air_dry",
HVACMode.FAN_ONLY: "fan",
HVACMode.HEAT: "heat",
}
THINQ_PRESET_MODE: list[str] = ["air_clean", "aroma", "energy_saving"] THINQ_PRESET_MODE: list[str] = ["air_clean", "aroma", "energy_saving"]
@ -111,12 +93,10 @@ async def async_setup_entry(
class ThinQClimateEntity(ThinQEntity, ClimateEntity): class ThinQClimateEntity(ThinQEntity, ClimateEntity):
"""Represent a thinq climate platform.""" """Represent a thinq climate platform."""
entity_description: ThinQClimateEntityDescription
def __init__( def __init__(
self, self,
coordinator: DeviceDataUpdateCoordinator, coordinator: DeviceDataUpdateCoordinator,
entity_description: ThinQClimateEntityDescription, entity_description: ClimateEntityDescription,
property_id: str, property_id: str,
) -> None: ) -> None:
"""Initialize a climate entity.""" """Initialize a climate entity."""
@ -190,18 +170,12 @@ class ThinQClimateEntity(ThinQEntity, ClimateEntity):
self._attr_current_temperature = self.data.current_temp self._attr_current_temperature = self.data.current_temp
# Update min, max and step. # Update min, max and step.
if (max_temp := self.entity_description.max_temp) is not None or ( if self.data.max is not None:
max_temp := self.data.max self._attr_max_temp = self.data.max
) is not None: if self.data.min is not None:
self._attr_max_temp = max_temp self._attr_min_temp = self.data.min
if (min_temp := self.entity_description.min_temp) is not None or (
min_temp := self.data.min self._attr_target_temperature_step = self.data.step
) is not None:
self._attr_min_temp = min_temp
if (step := self.entity_description.step) is not None or (
step := self.data.step
) is not None:
self._attr_target_temperature_step = step
# Update target temperatures. # Update target temperatures.
self._attr_target_temperature = self.data.target_temp self._attr_target_temperature = self.data.target_temp
@ -342,6 +316,10 @@ class ThinQClimateEntity(ThinQEntity, ClimateEntity):
self.property_id, self.property_id,
kwargs, kwargs,
) )
if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
await self.async_set_hvac_mode(HVACMode(hvac_mode))
if hvac_mode == HVACMode.OFF:
return
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None: if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None:
if ( if (