Make async_set_state in ConfigEntry a protected method (#96727)

I added this in #77803 but I never designed it to be called
externally. External usage may break at any time because the
class is not designed for this. I should have made it protected
in the original PR but I did not think it would get called
externally (my mistake)
pull/96775/head
J. Nick Koston 2023-07-16 20:58:12 -10:00 committed by GitHub
parent 260e00ffb4
commit 085eebc903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -373,7 +373,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
except InvalidFolder as ex:
_LOGGER.warning("Selected mailbox folder is invalid")
await self._cleanup()
self.config_entry.async_set_state(
self.config_entry._async_set_state( # pylint: disable=protected-access
self.hass,
ConfigEntryState.SETUP_ERROR,
"Selected mailbox folder is invalid.",

View File

@ -338,7 +338,7 @@ class ConfigEntry:
# Only store setup result as state if it was not forwarded.
if self.domain == integration.domain:
self.async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
self._async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
if self.supports_unload is None:
self.supports_unload = await support_entry_unload(hass, self.domain)
@ -357,7 +357,9 @@ class ConfigEntry:
err,
)
if self.domain == integration.domain:
self.async_set_state(hass, ConfigEntryState.SETUP_ERROR, "Import error")
self._async_set_state(
hass, ConfigEntryState.SETUP_ERROR, "Import error"
)
return
if self.domain == integration.domain:
@ -373,12 +375,14 @@ class ConfigEntry:
self.domain,
err,
)
self.async_set_state(hass, ConfigEntryState.SETUP_ERROR, "Import error")
self._async_set_state(
hass, ConfigEntryState.SETUP_ERROR, "Import error"
)
return
# Perform migration
if not await self.async_migrate(hass):
self.async_set_state(hass, ConfigEntryState.MIGRATION_ERROR, None)
self._async_set_state(hass, ConfigEntryState.MIGRATION_ERROR, None)
return
error_reason = None
@ -418,7 +422,7 @@ class ConfigEntry:
self.async_start_reauth(hass)
result = False
except ConfigEntryNotReady as ex:
self.async_set_state(hass, ConfigEntryState.SETUP_RETRY, str(ex) or None)
self._async_set_state(hass, ConfigEntryState.SETUP_RETRY, str(ex) or None)
wait_time = 2 ** min(tries, 4) * 5 + (
randint(RANDOM_MICROSECOND_MIN, RANDOM_MICROSECOND_MAX) / 1000000
)
@ -479,9 +483,9 @@ class ConfigEntry:
return
if result:
self.async_set_state(hass, ConfigEntryState.LOADED, None)
self._async_set_state(hass, ConfigEntryState.LOADED, None)
else:
self.async_set_state(hass, ConfigEntryState.SETUP_ERROR, error_reason)
self._async_set_state(hass, ConfigEntryState.SETUP_ERROR, error_reason)
async def async_shutdown(self) -> None:
"""Call when Home Assistant is stopping."""
@ -502,7 +506,7 @@ class ConfigEntry:
Returns if unload is possible and was successful.
"""
if self.source == SOURCE_IGNORE:
self.async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
return True
if self.state == ConfigEntryState.NOT_LOADED:
@ -516,7 +520,7 @@ class ConfigEntry:
# that was uninstalled, or an integration
# that has been renamed without removing the config
# entry.
self.async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
return True
component = integration.get_component()
@ -527,14 +531,14 @@ class ConfigEntry:
if self.state is not ConfigEntryState.LOADED:
self.async_cancel_retry_setup()
self.async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
return True
supports_unload = hasattr(component, "async_unload_entry")
if not supports_unload:
if integration.domain == self.domain:
self.async_set_state(
self._async_set_state(
hass, ConfigEntryState.FAILED_UNLOAD, "Unload not supported"
)
return False
@ -546,7 +550,7 @@ class ConfigEntry:
# Only adjust state if we unloaded the component
if result and integration.domain == self.domain:
self.async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None)
await self._async_process_on_unload(hass)
@ -556,7 +560,7 @@ class ConfigEntry:
"Error unloading entry %s for %s", self.title, integration.domain
)
if integration.domain == self.domain:
self.async_set_state(
self._async_set_state(
hass, ConfigEntryState.FAILED_UNLOAD, str(ex) or "Unknown error"
)
return False
@ -588,7 +592,7 @@ class ConfigEntry:
)
@callback
def async_set_state(
def _async_set_state(
self, hass: HomeAssistant, state: ConfigEntryState, reason: str | None
) -> None:
"""Set the state of the config entry."""