1212
1313from givenergy_modbus .client import commands as ge_commands
1414from givenergy_modbus .model import TimeSlot
15+ from givenergy_modbus .model .slot_map import SINGLE_PHASE_SLOTS
1516from givenergy_modbus .pdu .transparent import TransparentRequest
1617
1718from .const import DOMAIN , LOGGER
@@ -184,12 +185,19 @@ async def _async_enable_timed_charge(hass: HomeAssistant, data: dict[str, Any])
184185 Note that this isn't a battery mode like "Timed Discharge", "Eco", etc. It operates in
185186 parallel to those modes.
186187 """
187- commands = ge_commands . set_enable_charge ( True )
188+ commands : list [ TransparentRequest ] = []
188189
189- if _ATTR_START_TIME in data and _ATTR_END_TIME in data :
190+ if _ATTR_START_TIME in data :
190191 start_time = datetime .time .fromisoformat (data [_ATTR_START_TIME ])
192+ commands .extend (
193+ ge_commands .set_charge_slot_start (1 , start_time , SINGLE_PHASE_SLOTS )
194+ )
195+
196+ if _ATTR_END_TIME in data :
191197 end_time = datetime .time .fromisoformat (data [_ATTR_END_TIME ])
192- commands .extend (ge_commands .set_charge_slot_1 (TimeSlot (start_time , end_time )))
198+ commands .extend (
199+ ge_commands .set_charge_slot_end (1 , end_time , SINGLE_PHASE_SLOTS )
200+ )
193201
194202 if _ATTR_CHARGE_TARGET in data :
195203 target_soc = int (data [_ATTR_CHARGE_TARGET ])
@@ -198,8 +206,13 @@ async def _async_enable_timed_charge(hass: HomeAssistant, data: dict[str, Any])
198206 # bounces between 99-100% in a charge/discharge cycle, so avoid this, matching
199207 # behaviour of GivEnergy logic. set_charge_target_enabled() applies exactly
200208 # this rule: it enables charging and, for a target of 100%, clears the charge
201- # target rather than setting it.
209+ # target rather than setting it. It also enables charging itself, so it must
210+ # not be combined with a separate set_enable_charge() call below - the two
211+ # would write ENABLE_CHARGE (HR 96) twice in the same batch, and the client
212+ # cancels the first of any two same-register writes it sees in flight together.
202213 commands .extend (ge_commands .set_charge_target_enabled (target_soc ))
214+ else :
215+ commands .extend (ge_commands .set_enable_charge (True ))
203216
204217 LOGGER .debug ("Activating timed charge mode" )
205218 await _async_service_call (hass , data [ATTR_DEVICE_ID ], commands )
0 commit comments