Set lock state to unkown on BMW API error (#118559)

* Revert to previous lock state on BMW API error

* Set lock state to unkown on error and force refresh from API

---------

Co-authored-by: Richard <rikroe@users.noreply.github.com>
pull/118845/head
Richard Kroegel 2024-06-03 07:48:48 +02:00 committed by Franck Nijhof
parent f2b1635969
commit 4bfff12570
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
1 changed files with 10 additions and 6 deletions

View File

@ -65,11 +65,13 @@ class BMWLock(BMWBaseEntity, LockEntity):
try:
await self.vehicle.remote_services.trigger_remote_door_lock()
except MyBMWAPIError as ex:
self._attr_is_locked = False
# Set the state to unknown if the command fails
self._attr_is_locked = None
self.async_write_ha_state()
raise HomeAssistantError(ex) from ex
self.coordinator.async_update_listeners()
finally:
# Always update the listeners to get the latest state
self.coordinator.async_update_listeners()
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock the car."""
@ -83,11 +85,13 @@ class BMWLock(BMWBaseEntity, LockEntity):
try:
await self.vehicle.remote_services.trigger_remote_door_unlock()
except MyBMWAPIError as ex:
self._attr_is_locked = True
# Set the state to unknown if the command fails
self._attr_is_locked = None
self.async_write_ha_state()
raise HomeAssistantError(ex) from ex
self.coordinator.async_update_listeners()
finally:
# Always update the listeners to get the latest state
self.coordinator.async_update_listeners()
@callback
def _handle_coordinator_update(self) -> None: