Skip to content

Commit ad7c991

Browse files
committed
feat: add power-reset turn_off for E-heater assist and fix sterilize profile mapping
1 parent bc4cae3 commit ad7c991

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

custom_components/midea_heatpump_hws/profile_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def apply_profile_to_config(self, profile_data: dict[str, Any], user_input: dict
235235
config["mode_register"] = registers.get("mode", 1)
236236
config["temp_register"] = registers.get("current_temp", 102)
237237
config["target_temp_register"] = registers.get("target_temp", 2)
238+
config["sterilize_register"] = registers.get("sterilize", 3)
238239
config["tank_top_temp_register"] = registers.get("tank_top_temp", 101)
239240
config["tank_bottom_temp_register"] = registers.get("tank_bottom_temp", 102)
240241
config["condensor_temp_register"] = registers.get("condensor_temp", 103)
@@ -246,6 +247,8 @@ def apply_profile_to_config(self, profile_data: dict[str, Any], user_input: dict
246247
config["heater_assist_register"] = registers["heater_assist_register"]
247248
if "sanitize_state_register" in registers:
248249
config["sanitize_state_register"] = registers["sanitize_state_register"]
250+
if "heater_assist_trigger_register" in registers:
251+
config["heater_assist_trigger_register"] = registers["heater_assist_trigger_register"]
249252

250253
# Apply mode values
251254
mode_values = profile_data.get("mode_values", {})

custom_components/midea_heatpump_hws/switch.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from homeassistant.helpers.entity_platform import AddEntitiesCallback
99
from 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
1212
from .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

Comments
 (0)