diff --git a/homeassistant/components/esphome/entry_data.py b/homeassistant/components/esphome/entry_data.py index 7ce195d68fc..225ae3961e8 100644 --- a/homeassistant/components/esphome/entry_data.py +++ b/homeassistant/components/esphome/entry_data.py @@ -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: