88from homeassistant .helpers .entity_platform import AddEntitiesCallback
99from homeassistant .helpers .update_coordinator import CoordinatorEntity
1010
11- from .const import DOMAIN , CONF_MODBUS_UNIT
11+ from .const import DOMAIN , CONF_MODBUS_UNIT , CONF_HEATER_ASSIST_TRIGGER_REGISTER
1212from .coordinator import MideaModbusCoordinator
1313
1414_LOGGER = logging .getLogger (__name__ )
@@ -30,9 +30,17 @@ async def async_setup_entry(
3030 entities = [MideaPowerSwitch (coordinator , config , host_suffix )]
3131
3232 # Add sterilize switch if register is configured
33- if config . get ( " sterilize_register" ) is not None :
33+ if coordinator . sterilize_register is not None :
3434 entities .append (MideaSterilizeSwitch (coordinator , config , host_suffix ))
3535
36+ # Add manual heater assist switch only if the profile exposes both the write
37+ # trigger and the R108 diagnostic register it is functionally paired with.
38+ if (
39+ coordinator .heater_assist_trigger_register is not None
40+ and coordinator .heater_assist_register is not None
41+ ):
42+ entities .append (MideaHeaterAssistSwitch (coordinator , config , host_suffix ))
43+
3644 async_add_entities (entities )
3745
3846
@@ -141,4 +149,55 @@ async def async_turn_off(self, **kwargs: Any) -> None:
141149 @callback
142150 def _handle_coordinator_update (self ) -> None :
143151 """Handle updated data from the coordinator."""
144- self .async_write_ha_state ()
152+ self .async_write_ha_state ()
153+
154+
155+ class MideaHeaterAssistSwitch (CoordinatorEntity , SwitchEntity ):
156+ """Representation of the manual E-Heater assist trigger switch."""
157+
158+ def __init__ (
159+ self ,
160+ coordinator : MideaModbusCoordinator ,
161+ config : dict ,
162+ host_suffix : str
163+ ):
164+ """Initialize the heater assist switch."""
165+ super ().__init__ (coordinator )
166+ self ._config = config
167+
168+ # Entity attributes - include host for uniqueness
169+ self ._attr_name = f"Manual Heater Assist{ host_suffix } "
170+ self ._attr_unique_id = f"midea_{ config ['host' ]} _{ config [CONF_MODBUS_UNIT ]} _heater_assist_trigger"
171+ self ._attr_icon = "mdi:fire"
172+
173+ @property
174+ def device_info (self ):
175+ """Return device info to link this switch to the main device."""
176+ return {
177+ "identifiers" : {(DOMAIN , f"{ self ._config ['host' ]} _{ self ._config [CONF_MODBUS_UNIT ]} " )},
178+ "name" : f"Midea Heat Pump ({ self ._config ['host' ]} )" ,
179+ "manufacturer" : "Midea" ,
180+ "model" : "Heat Pump Water Heater" ,
181+ }
182+
183+ @property
184+ def is_on (self ) -> bool :
185+ """Return true if e-heater is triggered."""
186+ if self .coordinator .data :
187+ return self .coordinator .data .get ("heater_assist_trigger_raw" ) == 1
188+ return False
189+
190+ @property
191+ def available (self ) -> bool :
192+ """Return if entity is available."""
193+ return self .coordinator .last_update_success
194+
195+ async def async_turn_on (self , ** kwargs : Any ) -> None :
196+ """Trigger manual heater assist."""
197+ await self .coordinator .write_register ("heater_assist_trigger" , 1 )
198+
199+ async def async_turn_off (self , ** kwargs : Any ) -> None :
200+ """Turn off E-heater assist by resetting power state to clear R4 trigger."""
201+ _LOGGER .info ("Resetting power state to turn off manual E-heater assist" )
202+ await self .coordinator .write_register ("power_state" , False )
203+ await self .coordinator .write_register ("power_state" , True )
0 commit comments