Add target_temp_step attribute to water_heater (#138920)

Co-authored-by: yunseon.park <yunseon.park@lge.com>
This commit is contained in:
LG-ThinQ-Integration 2025-02-22 08:49:17 +09:00 committed by GitHub
parent 6e71893b50
commit 463d9617ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View File

@ -30,10 +30,15 @@ async def async_setup_entry(
async_add_entities(
[
DemoWaterHeater(
"Demo Water Heater", 119, UnitOfTemperature.FAHRENHEIT, False, "eco"
"Demo Water Heater", 119, UnitOfTemperature.FAHRENHEIT, False, "eco", 1
),
DemoWaterHeater(
"Demo Water Heater Celsius", 45, UnitOfTemperature.CELSIUS, True, "eco"
"Demo Water Heater Celsius",
45,
UnitOfTemperature.CELSIUS,
True,
"eco",
1,
),
]
)
@ -52,6 +57,7 @@ class DemoWaterHeater(WaterHeaterEntity):
unit_of_measurement: str,
away: bool,
current_operation: str,
target_temperature_step: float,
) -> None:
"""Initialize the water_heater device."""
self._attr_name = name
@ -74,6 +80,7 @@ class DemoWaterHeater(WaterHeaterEntity):
"gas",
"off",
]
self._attr_target_temperature_step = target_temperature_step
def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperatures."""

View File

@ -77,6 +77,7 @@ ATTR_OPERATION_MODE = "operation_mode"
ATTR_OPERATION_LIST = "operation_list"
ATTR_TARGET_TEMP_HIGH = "target_temp_high"
ATTR_TARGET_TEMP_LOW = "target_temp_low"
ATTR_TARGET_TEMP_STEP = "target_temp_step"
ATTR_CURRENT_TEMPERATURE = "current_temperature"
CONVERTIBLE_ATTRIBUTE = [ATTR_TEMPERATURE]
@ -154,6 +155,7 @@ CACHED_PROPERTIES_WITH_ATTR_ = {
"target_temperature",
"target_temperature_high",
"target_temperature_low",
"target_temperature_step",
"is_away_mode_on",
}
@ -162,7 +164,12 @@ class WaterHeaterEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
"""Base class for water heater entities."""
_entity_component_unrecorded_attributes = frozenset(
{ATTR_OPERATION_LIST, ATTR_MIN_TEMP, ATTR_MAX_TEMP}
{
ATTR_OPERATION_LIST,
ATTR_MIN_TEMP,
ATTR_MAX_TEMP,
ATTR_TARGET_TEMP_STEP,
}
)
entity_description: WaterHeaterEntityDescription
@ -179,6 +186,7 @@ class WaterHeaterEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
_attr_target_temperature_low: float | None = None
_attr_target_temperature: float | None = None
_attr_temperature_unit: str
_attr_target_temperature_step: float | None = None
@final
@property
@ -206,6 +214,8 @@ class WaterHeaterEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
self.hass, self.max_temp, self.temperature_unit, self.precision
),
}
if target_temperature_step := self.target_temperature_step:
data[ATTR_TARGET_TEMP_STEP] = target_temperature_step
if WaterHeaterEntityFeature.OPERATION_MODE in self.supported_features:
data[ATTR_OPERATION_LIST] = self.operation_list
@ -289,6 +299,11 @@ class WaterHeaterEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
"""Return the lowbound target temperature we try to reach."""
return self._attr_target_temperature_low
@cached_property
def target_temperature_step(self) -> float | None:
"""Return the supported step of target temperature."""
return self._attr_target_temperature_step
@cached_property
def is_away_mode_on(self) -> bool | None:
"""Return true if away mode is on."""

View File

@ -43,6 +43,7 @@ async def test_setup_params(hass: HomeAssistant) -> None:
assert state.attributes.get("temperature") == 119
assert state.attributes.get("away_mode") == "off"
assert state.attributes.get("operation_mode") == "eco"
assert state.attributes.get("target_temp_step") == 1
async def test_default_setup_params(hass: HomeAssistant) -> None: