mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Adjust shutdown registration in EntityComponent (#90938)
* Adjust shutdown registration in EntityComponent * Adjust * Make it more explicit * docstring
This commit is contained in:
parent
6dbe67e909
commit
4a0988eb5d
@ -47,6 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
component = hass.data[DOMAIN] = EntityComponent[BaseTrackerEntity](
|
component = hass.data[DOMAIN] = EntityComponent[BaseTrackerEntity](
|
||||||
LOGGER, DOMAIN, hass
|
LOGGER, DOMAIN, hass
|
||||||
)
|
)
|
||||||
|
component.register_shutdown()
|
||||||
|
|
||||||
# Clean up old devices created by device tracker entities in the past.
|
# Clean up old devices created by device tracker entities in the past.
|
||||||
# Can be removed after 2022.6
|
# Can be removed after 2022.6
|
||||||
|
@ -86,6 +86,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
component = EntityComponent[MailboxEntity](
|
component = EntityComponent[MailboxEntity](
|
||||||
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
|
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
|
||||||
)
|
)
|
||||||
|
component.register_shutdown()
|
||||||
await component.async_add_entities([mailbox_entity])
|
await component.async_add_entities([mailbox_entity])
|
||||||
|
|
||||||
setup_tasks = [
|
setup_tasks = [
|
||||||
|
@ -109,6 +109,14 @@ class EntityComponent(Generic[_EntityT]):
|
|||||||
return entity_obj # type: ignore[return-value]
|
return entity_obj # type: ignore[return-value]
|
||||||
return None
|
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:
|
def setup(self, config: ConfigType) -> None:
|
||||||
"""Set up a full entity component.
|
"""Set up a full entity component.
|
||||||
|
|
||||||
@ -126,7 +134,7 @@ class EntityComponent(Generic[_EntityT]):
|
|||||||
|
|
||||||
This method must be run in the event loop.
|
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
|
self.config = config
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user