Use setdefault()
in scaffold script for setting hass.data
(#103338)
This commit is contained in:
parent
bb8375da72
commit
5cd27a877e
2 changed files with 5 additions and 3 deletions
|
@ -11,7 +11,7 @@ from .const import DOMAIN
|
|||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up NEW_NAME from a config entry."""
|
||||
# TODO Optionally store an object for your platforms to access
|
||||
# hass.data[DOMAIN][entry.entry_id] = ...
|
||||
# hass.data.setdefault(DOMAIN, {})[entry.entry_id] = ...
|
||||
|
||||
# TODO Optionally validate config entry options before setting up platform
|
||||
|
||||
|
|
|
@ -25,10 +25,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
|
||||
|
||||
# If using a requests-based API lib
|
||||
hass.data[DOMAIN][entry.entry_id] = api.ConfigEntryAuth(hass, session)
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.ConfigEntryAuth(
|
||||
hass, session
|
||||
)
|
||||
|
||||
# If using an aiohttp-based API lib
|
||||
hass.data[DOMAIN][entry.entry_id] = api.AsyncConfigEntryAuth(
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.AsyncConfigEntryAuth(
|
||||
aiohttp_client.async_get_clientsession(hass), session
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue