66from typing import Any , cast
77
88from chip .clusters import Objects as clusters
9+ from chip .clusters .Types import Nullable
910from matter_server .client .models import device_types
11+ from matter_server .common .errors import MatterError
1012from matter_server .common .helpers .util import create_attribute_path_from_attribute
1113
1214from homeassistant .components .water_heater import (
2527 UnitOfTemperature ,
2628)
2729from homeassistant .core import HomeAssistant , callback
30+ from homeassistant .exceptions import HomeAssistantError
2831from homeassistant .helpers .entity_platform import AddConfigEntryEntitiesCallback
2932
3033from .entity import MatterEntity , MatterEntityDescription
4043 STATE_OFF : 0 ,
4144}
4245
46+ DEFAULT_BOOST_DURATION = 3600 # 1 hour
47+
4348
4449async def async_setup_entry (
4550 hass : HomeAssistant ,
@@ -78,6 +83,30 @@ class MatterWaterHeater(MatterEntity, WaterHeaterEntity):
7883 _attr_temperature_unit = UnitOfTemperature .CELSIUS
7984 _platform_translation_key = "water_heater"
8085
86+ async def async_set_boost (
87+ self ,
88+ duration : int ,
89+ emergency_boost : bool = False ,
90+ temporary_setpoint : int | None = None ,
91+ ) -> None :
92+ """Set boost."""
93+ boost_info : clusters .WaterHeaterManagement .Structs .WaterHeaterBoostInfoStruct = clusters .WaterHeaterManagement .Structs .WaterHeaterBoostInfoStruct (
94+ duration = duration ,
95+ emergencyBoost = emergency_boost ,
96+ temporarySetpoint = (
97+ temporary_setpoint * TEMPERATURE_SCALING_FACTOR
98+ if temporary_setpoint is not None
99+ else Nullable
100+ ),
101+ )
102+ try :
103+ await self .send_device_command (
104+ clusters .WaterHeaterManagement .Commands .Boost (boostInfo = boost_info )
105+ )
106+ except MatterError as err :
107+ raise HomeAssistantError (f"Error sending Boost command: { err } " ) from err
108+ self ._update_from_device ()
109+
81110 async def async_set_temperature (self , ** kwargs : Any ) -> None :
82111 """Set new target temperature."""
83112 target_temperature : float | None = kwargs .get (ATTR_TEMPERATURE )
@@ -94,11 +123,11 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
94123 async def async_set_operation_mode (self , operation_mode : str ) -> None :
95124 """Set new operation mode."""
96125 self ._attr_current_operation = operation_mode
97- # Boost 1h (3600s)
126+ # Use the constant for boost duration
98127 boost_info : type [
99128 clusters .WaterHeaterManagement .Structs .WaterHeaterBoostInfoStruct
100129 ] = clusters .WaterHeaterManagement .Structs .WaterHeaterBoostInfoStruct (
101- duration = 3600
130+ duration = DEFAULT_BOOST_DURATION
102131 )
103132 system_mode_value = WATER_HEATER_SYSTEM_MODE_MAP [operation_mode ]
104133 await self .write_attribute (
0 commit comments