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>
This commit is contained in:
Richard Kroegel 2024-06-03 07:48:48 +02:00 committed by GitHub
parent c23ec96174
commit 7c5a6602b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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: