Update integrations to use async_setup_platforms (#60956)

* Replace forward_entry_setup with setup_platforms

* Apply suggestions from code review

Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de>

Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de>
This commit is contained in:
Marc Mueller 2021-12-04 08:57:24 +01:00 committed by GitHub
parent 10e669e69e
commit 156435d1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 58 deletions

View File

@ -1,7 +1,9 @@
"""Support for Ambiclimate devices."""
import voluptuous as vol
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from . import config_flow
@ -19,6 +21,8 @@ CONFIG_SCHEMA = vol.Schema(
extra=vol.ALLOW_EXTRA,
)
PLATFORMS = [Platform.CLIMATE]
async def async_setup(hass, config) -> bool:
"""Set up Ambiclimate components."""
@ -34,10 +38,7 @@ async def async_setup(hass, config) -> bool:
return True
async def async_setup_entry(hass, entry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Ambiclimate from a config entry."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "climate")
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True

View File

@ -4,6 +4,8 @@ import logging
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from . import home_assistant_cast
@ -15,6 +17,8 @@ CONFIG_SCHEMA = cv.deprecated(DOMAIN)
_LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.MEDIA_PLAYER]
async def async_setup(hass, config):
"""Set up the Cast component."""
@ -41,13 +45,12 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, entry: config_entries.ConfigEntry):
async def async_setup_entry(
hass: HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Set up Cast from a config entry."""
await home_assistant_cast.async_setup_ha_cast(hass, entry)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "media_player")
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True

View File

@ -6,7 +6,8 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView
from homeassistant.core import callback
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.dispatcher import async_dispatcher_send
@ -209,6 +210,8 @@ IDENTIFY_SCHEMA = vol.Schema(
CONFIGURATION_FILE = ".ios.conf"
PLATFORMS = [Platform.SENSOR]
def devices_with_push(hass):
"""Return a dictionary of push enabled targets."""
@ -272,11 +275,11 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, entry):
async def async_setup_entry(
hass: HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Set up an iOS entry."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
hass.http.register_view(iOSIdentifyDeviceView(hass.config.path(CONFIGURATION_FILE)))
hass.http.register_view(iOSPushConfigView(hass.data[DOMAIN][CONF_USER][CONF_PUSH]))

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
CONF_STRUCTURE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
@ -29,7 +30,12 @@ from .const import DATA_NEST, DATA_NEST_CONFIG, DOMAIN, SIGNAL_NEST_UPDATE
_CONFIGURING = {}
_LOGGER = logging.getLogger(__name__)
PLATFORMS = ["climate", "camera", "sensor", "binary_sensor"]
PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.CAMERA,
Platform.CLIMATE,
Platform.SENSOR,
]
# Configuration for the legacy nest API
SERVICE_CANCEL_ETA = "cancel_eta"
@ -134,10 +140,7 @@ async def async_setup_legacy_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
if not await hass.async_add_executor_job(hass.data[DATA_NEST].initialize):
return False
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
def validate_structures(target_structures):
all_structures = [structure.name for structure in nest.structures]

View File

@ -6,7 +6,12 @@ from requests.exceptions import ConnectTimeout, HTTPError
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.const import (
CONF_PASSWORD,
CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
@ -32,7 +37,7 @@ CONFIG_SCHEMA = vol.Schema(
extra=vol.ALLOW_EXTRA,
)
PLATFORMS = ["light"]
PLATFORMS = [Platform.LIGHT]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
@ -71,10 +76,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = plum
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
def cleanup(event):
"""Clean up resources."""

View File

@ -4,7 +4,7 @@ import logging
from roonapi import RoonApi
from homeassistant.const import CONF_API_KEY, CONF_HOST
from homeassistant.const import CONF_API_KEY, CONF_HOST, Platform
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.util.dt import utcnow
@ -12,6 +12,7 @@ from .const import CONF_ROON_ID, ROON_APPINFO
_LOGGER = logging.getLogger(__name__)
FULL_SYNC_INTERVAL = 30
PLATFORMS = [Platform.MEDIA_PLAYER]
class RoonServer:
@ -51,11 +52,7 @@ class RoonServer:
self.roon_id = core_id if core_id is not None else host
# initialize media_player platform
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(
self.config_entry, "media_player"
)
)
hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
# Initialize Roon background polling
asyncio.create_task(self.async_do_loop())

View File

@ -13,13 +13,16 @@ from withings_api import WithingsAuth
from withings_api.common import NotifyAppli
from homeassistant.components import webhook
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.webhook import (
async_unregister as async_unregister_webhook,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_WEBHOOK_ID
from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_WEBHOOK_ID,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.event import async_call_later
@ -36,6 +39,7 @@ from .common import (
)
DOMAIN = const.DOMAIN
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
CONFIG_SCHEMA = vol.Schema(
{
@ -143,12 +147,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Start subscription check in the background, outside this component's setup.
async_call_later(hass, 1, async_call_later_callback)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, BINARY_SENSOR_DOMAIN)
)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, SENSOR_DOMAIN)
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True
@ -162,8 +161,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await asyncio.gather(
data_manager.async_unsubscribe_webhook(),
hass.config_entries.async_forward_entry_unload(entry, BINARY_SENSOR_DOMAIN),
hass.config_entries.async_forward_entry_unload(entry, SENSOR_DOMAIN),
hass.config_entries.async_unload_platforms(entry, PLATFORMS),
)
async_remove_data_manager(hass, entry)

View File

@ -15,8 +15,9 @@ from homeassistant.const import (
ATTR_VIA_DEVICE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import CoreState, callback
from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import (
@ -98,14 +99,14 @@ DEFAULT_CONF_REFRESH_VALUE = False
DEFAULT_CONF_REFRESH_DELAY = 5
PLATFORMS = [
"binary_sensor",
"climate",
"cover",
"fan",
"lock",
"light",
"sensor",
"switch",
Platform.BINARY_SENSOR,
Platform.CLIMATE,
Platform.COVER,
Platform.FAN,
Platform.LIGHT,
Platform.LOCK,
Platform.SENSOR,
Platform.SWITCH,
]
RENAME_NODE_SCHEMA = vol.Schema(
@ -341,7 +342,9 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, config_entry): # noqa: C901
async def async_setup_entry( # noqa: C901
hass: HomeAssistant, config_entry: config_entries.ConfigEntry
) -> bool:
"""Set up Z-Wave from a config entry.
Will automatically load components to support devices found on the network.
@ -1021,10 +1024,7 @@ async def async_setup_entry(hass, config_entry): # noqa: C901
hass.services.async_register(DOMAIN, const.SERVICE_START_NETWORK, start_zwave)
for entry_component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, entry_component)
)
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
return True