1414from homeassistant .config_entries import ConfigEntry
1515from homeassistant .core import HomeAssistant
1616from homeassistant .exceptions import ConfigEntryAuthFailed , HomeAssistantError
17- from homeassistant .helpers .update_coordinator import DataUpdateCoordinator
17+ from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
1818
1919from .const import (
2020 CHARGER_CURRENCY_KEY ,
2121 CHARGER_DATA_KEY ,
22+ CHARGER_DATA_POST_L1_KEY ,
23+ CHARGER_DATA_POST_L2_KEY ,
2224 CHARGER_ECO_SMART_KEY ,
2325 CHARGER_ECO_SMART_MODE_KEY ,
2426 CHARGER_ECO_SMART_STATUS_KEY ,
2527 CHARGER_ENERGY_PRICE_KEY ,
2628 CHARGER_FEATURES_KEY ,
2729 CHARGER_LOCKED_UNLOCKED_KEY ,
2830 CHARGER_MAX_CHARGING_CURRENT_KEY ,
31+ CHARGER_MAX_CHARGING_CURRENT_POST_KEY ,
2932 CHARGER_MAX_ICP_CURRENT_KEY ,
3033 CHARGER_PLAN_KEY ,
3134 CHARGER_POWER_BOOST_KEY ,
@@ -192,10 +195,10 @@ def _get_data(self) -> dict[str, Any]:
192195 return data # noqa: TRY300
193196 except requests .exceptions .HTTPError as wallbox_connection_error :
194197 if wallbox_connection_error .response .status_code == 429 :
195- raise HomeAssistantError (
198+ raise UpdateFailed (
196199 translation_domain = DOMAIN , translation_key = "too_many_requests"
197200 ) from wallbox_connection_error
198- raise HomeAssistantError (
201+ raise UpdateFailed (
199202 translation_domain = DOMAIN , translation_key = "api_failed"
200203 ) from wallbox_connection_error
201204
@@ -204,10 +207,19 @@ async def _async_update_data(self) -> dict[str, Any]:
204207 return await self .hass .async_add_executor_job (self ._get_data )
205208
206209 @_require_authentication
207- def _set_charging_current (self , charging_current : float ) -> None :
210+ def _set_charging_current (
211+ self , charging_current : float
212+ ) -> dict [str , dict [str , dict [str , Any ]]]:
208213 """Set maximum charging current for Wallbox."""
209214 try :
210- self ._wallbox .setMaxChargingCurrent (self ._station , charging_current )
215+ result = self ._wallbox .setMaxChargingCurrent (
216+ self ._station , charging_current
217+ )
218+ data = self .data
219+ data [CHARGER_MAX_CHARGING_CURRENT_KEY ] = result [CHARGER_DATA_POST_L1_KEY ][
220+ CHARGER_DATA_POST_L2_KEY
221+ ][CHARGER_MAX_CHARGING_CURRENT_POST_KEY ]
222+ return data # noqa: TRY300
211223 except requests .exceptions .HTTPError as wallbox_connection_error :
212224 if wallbox_connection_error .response .status_code == 403 :
213225 raise InvalidAuth from wallbox_connection_error
@@ -221,16 +233,19 @@ def _set_charging_current(self, charging_current: float) -> None:
221233
222234 async def async_set_charging_current (self , charging_current : float ) -> None :
223235 """Set maximum charging current for Wallbox."""
224- await self .hass .async_add_executor_job (
236+ data = await self .hass .async_add_executor_job (
225237 self ._set_charging_current , charging_current
226238 )
227- await self .async_request_refresh ( )
239+ self .async_set_updated_data ( data )
228240
229241 @_require_authentication
230- def _set_icp_current (self , icp_current : float ) -> None :
242+ def _set_icp_current (self , icp_current : float ) -> dict [ str , Any ] :
231243 """Set maximum icp current for Wallbox."""
232244 try :
233- self ._wallbox .setIcpMaxCurrent (self ._station , icp_current )
245+ result = self ._wallbox .setIcpMaxCurrent (self ._station , icp_current )
246+ data = self .data
247+ data [CHARGER_MAX_ICP_CURRENT_KEY ] = result [CHARGER_MAX_ICP_CURRENT_KEY ]
248+ return data # noqa: TRY300
234249 except requests .exceptions .HTTPError as wallbox_connection_error :
235250 if wallbox_connection_error .response .status_code == 403 :
236251 raise InvalidAuth from wallbox_connection_error
@@ -244,14 +259,19 @@ def _set_icp_current(self, icp_current: float) -> None:
244259
245260 async def async_set_icp_current (self , icp_current : float ) -> None :
246261 """Set maximum icp current for Wallbox."""
247- await self .hass .async_add_executor_job (self ._set_icp_current , icp_current )
248- await self .async_request_refresh ()
262+ data = await self .hass .async_add_executor_job (
263+ self ._set_icp_current , icp_current
264+ )
265+ self .async_set_updated_data (data )
249266
250267 @_require_authentication
251- def _set_energy_cost (self , energy_cost : float ) -> None :
268+ def _set_energy_cost (self , energy_cost : float ) -> dict [ str , Any ] :
252269 """Set energy cost for Wallbox."""
253270 try :
254- self ._wallbox .setEnergyCost (self ._station , energy_cost )
271+ result = self ._wallbox .setEnergyCost (self ._station , energy_cost )
272+ data = self .data
273+ data [CHARGER_ENERGY_PRICE_KEY ] = result [CHARGER_ENERGY_PRICE_KEY ]
274+ return data # noqa: TRY300
255275 except requests .exceptions .HTTPError as wallbox_connection_error :
256276 if wallbox_connection_error .response .status_code == 429 :
257277 raise HomeAssistantError (
@@ -263,17 +283,24 @@ def _set_energy_cost(self, energy_cost: float) -> None:
263283
264284 async def async_set_energy_cost (self , energy_cost : float ) -> None :
265285 """Set energy cost for Wallbox."""
266- await self .hass .async_add_executor_job (self ._set_energy_cost , energy_cost )
267- await self .async_request_refresh ()
286+ data = await self .hass .async_add_executor_job (
287+ self ._set_energy_cost , energy_cost
288+ )
289+ self .async_set_updated_data (data )
268290
269291 @_require_authentication
270- def _set_lock_unlock (self , lock : bool ) -> None :
292+ def _set_lock_unlock (self , lock : bool ) -> dict [ str , dict [ str , dict [ str , Any ]]] :
271293 """Set wallbox to locked or unlocked."""
272294 try :
273295 if lock :
274- self ._wallbox .lockCharger (self ._station )
296+ result = self ._wallbox .lockCharger (self ._station )
275297 else :
276- self ._wallbox .unlockCharger (self ._station )
298+ result = self ._wallbox .unlockCharger (self ._station )
299+ data = self .data
300+ data [CHARGER_LOCKED_UNLOCKED_KEY ] = result [CHARGER_DATA_POST_L1_KEY ][
301+ CHARGER_DATA_POST_L2_KEY
302+ ][CHARGER_LOCKED_UNLOCKED_KEY ]
303+ return data # noqa: TRY300
277304 except requests .exceptions .HTTPError as wallbox_connection_error :
278305 if wallbox_connection_error .response .status_code == 403 :
279306 raise InvalidAuth from wallbox_connection_error
@@ -287,8 +314,8 @@ def _set_lock_unlock(self, lock: bool) -> None:
287314
288315 async def async_set_lock_unlock (self , lock : bool ) -> None :
289316 """Set wallbox to locked or unlocked."""
290- await self .hass .async_add_executor_job (self ._set_lock_unlock , lock )
291- await self .async_request_refresh ( )
317+ data = await self .hass .async_add_executor_job (self ._set_lock_unlock , lock )
318+ self .async_set_updated_data ( data )
292319
293320 @_require_authentication
294321 def _pause_charger (self , pause : bool ) -> None :
0 commit comments