Skip to content

Commit

Permalink
Update integrations to use async_setup_platforms (home-assistant#60956
Browse files Browse the repository at this point in the history
)

* Replace forward_entry_setup with setup_platforms

* Apply suggestions from code review

Co-authored-by: Marvin Wichmann <[email protected]>

Co-authored-by: Marvin Wichmann <[email protected]>
  • Loading branch information
cdce8p and marvin-w authored Dec 4, 2021
1 parent 10e669e commit 156435d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 58 deletions.
13 changes: 7 additions & 6 deletions homeassistant/components/ambiclimate/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +21,8 @@
extra=vol.ALLOW_EXTRA,
)

PLATFORMS = [Platform.CLIMATE]


async def async_setup(hass, config) -> bool:
"""Set up Ambiclimate components."""
Expand All @@ -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
13 changes: 8 additions & 5 deletions homeassistant/components/cast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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
Expand All @@ -15,6 +17,8 @@

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.MEDIA_PLAYER]


async def async_setup(hass, config):
"""Set up the Cast component."""
Expand All @@ -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


Expand Down
13 changes: 8 additions & 5 deletions homeassistant/components/ios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

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
Expand Down Expand Up @@ -209,6 +210,8 @@

CONFIGURATION_FILE = ".ios.conf"

PLATFORMS = [Platform.SENSOR]


def devices_with_push(hass):
"""Return a dictionary of push enabled targets."""
Expand Down Expand Up @@ -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]))
Expand Down
13 changes: 8 additions & 5 deletions homeassistant/components/nest/legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CONF_STRUCTURE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
Expand All @@ -29,7 +30,12 @@
_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"
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 8 additions & 6 deletions homeassistant/components/plum_lightpad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
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
Expand All @@ -32,7 +37,7 @@
extra=vol.ALLOW_EXTRA,
)

PLATFORMS = ["light"]
PLATFORMS = [Platform.LIGHT]


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
Expand Down Expand Up @@ -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."""
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/roon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

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

from .const import CONF_ROON_ID, ROON_APPINFO

_LOGGER = logging.getLogger(__name__)
FULL_SYNC_INTERVAL = 30
PLATFORMS = [Platform.MEDIA_PLAYER]


class RoonServer:
Expand Down Expand Up @@ -51,11 +52,7 @@ async def async_setup(self, tries=0):
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())
Expand Down
20 changes: 9 additions & 11 deletions homeassistant/components/withings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
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
Expand All @@ -36,6 +39,7 @@
)

DOMAIN = const.DOMAIN
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]

CONFIG_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -143,12 +147,7 @@ def async_call_later_callback(now) -> None:
# 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

Expand All @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
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 (
Expand Down Expand Up @@ -98,14 +99,14 @@
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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1021,10 +1024,7 @@ def _finalize_start():

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

Expand Down

0 comments on commit 156435d

Please sign in to comment.