Use setdefault() in scaffold script for setting hass.data (#103338)

This commit is contained in:
Matthias Alphart 2023-11-04 10:51:34 +01:00 committed by GitHub
parent bb8375da72
commit 5cd27a877e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -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

View file

@ -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
)