mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Update scaffold templates to use runtime_data (#117819)
This commit is contained in:
parent
c9d1b127d8
commit
26fb7627ed
@ -6,30 +6,30 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
# TODO List the platforms that you want to support.
|
# TODO List the platforms that you want to support.
|
||||||
# For your initial PR, limit it to 1 platform.
|
# For your initial PR, limit it to 1 platform.
|
||||||
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
||||||
|
|
||||||
|
# TODO Create ConfigEntry type alias with API object
|
||||||
|
# TODO Rename type alias and update all entry annotations
|
||||||
|
type New_NameConfigEntry = ConfigEntry[MyApi] # noqa: F821
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
# TODO Update entry annotation
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: New_NameConfigEntry) -> bool:
|
||||||
"""Set up NEW_NAME from a config entry."""
|
"""Set up NEW_NAME from a config entry."""
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
# TODO 1. Create API instance
|
# TODO 1. Create API instance
|
||||||
# TODO 2. Validate the API connection (and authentication)
|
# TODO 2. Validate the API connection (and authentication)
|
||||||
# TODO 3. Store an API object for your platforms to access
|
# TODO 3. Store an API object for your platforms to access
|
||||||
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
# entry.runtime_data = MyAPI(...)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
# TODO Update entry annotation
|
||||||
|
async def async_unload_entry(hass: HomeAssistant, entry: New_NameConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -6,30 +6,30 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
# TODO List the platforms that you want to support.
|
# TODO List the platforms that you want to support.
|
||||||
# For your initial PR, limit it to 1 platform.
|
# For your initial PR, limit it to 1 platform.
|
||||||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR]
|
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR]
|
||||||
|
|
||||||
|
# TODO Create ConfigEntry type alias with API object
|
||||||
|
# Alias name should be prefixed by integration name
|
||||||
|
type New_NameConfigEntry = ConfigEntry[MyApi] # noqa: F821
|
||||||
|
|
||||||
|
|
||||||
|
# TODO Update entry annotation
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up NEW_NAME from a config entry."""
|
"""Set up NEW_NAME from a config entry."""
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
# TODO 1. Create API instance
|
# TODO 1. Create API instance
|
||||||
# TODO 2. Validate the API connection (and authentication)
|
# TODO 2. Validate the API connection (and authentication)
|
||||||
# TODO 3. Store an API object for your platforms to access
|
# TODO 3. Store an API object for your platforms to access
|
||||||
# hass.data[DOMAIN][entry.entry_id] = MyApi(...)
|
# entry.runtime_data = MyAPI(...)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# TODO Update entry annotation
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -6,13 +6,11 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up NEW_NAME from a config entry."""
|
"""Set up NEW_NAME from a config entry."""
|
||||||
# TODO Optionally store an object for your platforms to access
|
# TODO Optionally store an object for your platforms to access
|
||||||
# hass.data.setdefault(DOMAIN, {})[entry.entry_id] = ...
|
# entry.runtime_data = ...
|
||||||
|
|
||||||
# TODO Optionally validate config entry options before setting up platform
|
# TODO Optionally validate config entry options before setting up platform
|
||||||
|
|
||||||
@ -32,9 +30,4 @@ async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry)
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(
|
return await hass.config_entries.async_unload_platforms(entry, (Platform.SENSOR,))
|
||||||
entry, (Platform.SENSOR,)
|
|
||||||
):
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -8,14 +8,18 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
# TODO List the platforms that you want to support.
|
# TODO List the platforms that you want to support.
|
||||||
# For your initial PR, limit it to 1 platform.
|
# For your initial PR, limit it to 1 platform.
|
||||||
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
||||||
|
|
||||||
|
# TODO Create ConfigEntry type alias with ConfigEntryAuth or AsyncConfigEntryAuth object
|
||||||
|
# TODO Rename type alias and update all entry annotations
|
||||||
|
type New_NameConfigEntry = ConfigEntry[api.AsyncConfigEntryAuth]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
# # TODO Update entry annotation
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: New_NameConfigEntry) -> bool:
|
||||||
"""Set up NEW_NAME from a config entry."""
|
"""Set up NEW_NAME from a config entry."""
|
||||||
implementation = (
|
implementation = (
|
||||||
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
||||||
@ -26,12 +30,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
|
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
|
||||||
|
|
||||||
# If using a requests-based API lib
|
# If using a requests-based API lib
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.ConfigEntryAuth(
|
entry.runtime_data = api.ConfigEntryAuth(hass, session)
|
||||||
hass, session
|
|
||||||
)
|
|
||||||
|
|
||||||
# If using an aiohttp-based API lib
|
# If using an aiohttp-based API lib
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = api.AsyncConfigEntryAuth(
|
entry.runtime_data = api.AsyncConfigEntryAuth(
|
||||||
aiohttp_client.async_get_clientsession(hass), session
|
aiohttp_client.async_get_clientsession(hass), session
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,9 +42,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
# TODO Update entry annotation
|
||||||
|
async def async_unload_entry(hass: HomeAssistant, entry: New_NameConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user