mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Adjust shutdown registration in EntityComponent (#90938)
* Adjust shutdown registration in EntityComponent * Adjust * Make it more explicit * docstring
This commit is contained in:
@@ -109,6 +109,14 @@ class EntityComponent(Generic[_EntityT]):
|
||||
return entity_obj # type: ignore[return-value]
|
||||
return None
|
||||
|
||||
def register_shutdown(self) -> None:
|
||||
"""Register shutdown on Home Assistant STOP event.
|
||||
|
||||
Note: this is only required if the integration never calls
|
||||
`setup` or `async_setup`.
|
||||
"""
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_shutdown)
|
||||
|
||||
def setup(self, config: ConfigType) -> None:
|
||||
"""Set up a full entity component.
|
||||
|
||||
@@ -126,7 +134,7 @@ class EntityComponent(Generic[_EntityT]):
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_shutdown)
|
||||
self.register_shutdown()
|
||||
|
||||
self.config = config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user