Handle exceptions to prevent disconnect when esphome state subscription raises (#93723)

This commit is contained in:
J. Nick Koston 2023-05-29 13:41:50 -05:00 committed by GitHub
parent a547181984
commit 9443ca89bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -266,8 +266,14 @@ class RuntimeEntryData:
)
stale_state.discard(subscription_key)
current_state_by_type[key] = state
if subscription_key in self.state_subscriptions:
self.state_subscriptions[subscription_key]()
if subscription := self.state_subscriptions.get(subscription_key):
try:
subscription()
except Exception as ex: # pylint: disable=broad-except
# If we allow this exception to raise it will
# make it all the way to data_received in aioesphomeapi
# which will cause the connection to be closed.
_LOGGER.exception("Error while calling subscription: %s", ex)
@callback
def async_update_device_state(self, hass: HomeAssistant) -> None: