mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
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:
parent
10e669e69e
commit
156435d1c2
@ -1,7 +1,9 @@
|
|||||||
"""Support for Ambiclimate devices."""
|
"""Support for Ambiclimate devices."""
|
||||||
import voluptuous as vol
|
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 homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import config_flow
|
from . import config_flow
|
||||||
@ -19,6 +21,8 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
PLATFORMS = [Platform.CLIMATE]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config) -> bool:
|
async def async_setup(hass, config) -> bool:
|
||||||
"""Set up Ambiclimate components."""
|
"""Set up Ambiclimate components."""
|
||||||
@ -34,10 +38,7 @@ async def async_setup(hass, config) -> bool:
|
|||||||
return True
|
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."""
|
"""Set up Ambiclimate from a config entry."""
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "climate")
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -4,6 +4,8 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import home_assistant_cast
|
from . import home_assistant_cast
|
||||||
@ -15,6 +17,8 @@ CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Cast component."""
|
"""Set up the Cast component."""
|
||||||
@ -41,13 +45,12 @@ async def async_setup(hass, config):
|
|||||||
return True
|
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."""
|
"""Set up Cast from a config entry."""
|
||||||
await home_assistant_cast.async_setup_ha_cast(hass, entry)
|
await home_assistant_cast.async_setup_ha_cast(hass, entry)
|
||||||
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "media_player")
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.http import HomeAssistantView
|
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.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_validation as cv, discovery
|
from homeassistant.helpers import config_validation as cv, discovery
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
@ -209,6 +210,8 @@ IDENTIFY_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
CONFIGURATION_FILE = ".ios.conf"
|
CONFIGURATION_FILE = ".ios.conf"
|
||||||
|
|
||||||
|
PLATFORMS = [Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
def devices_with_push(hass):
|
def devices_with_push(hass):
|
||||||
"""Return a dictionary of push enabled targets."""
|
"""Return a dictionary of push enabled targets."""
|
||||||
@ -272,11 +275,11 @@ async def async_setup(hass, config):
|
|||||||
return True
|
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."""
|
"""Set up an iOS entry."""
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
||||||
)
|
|
||||||
|
|
||||||
hass.http.register_view(iOSIdentifyDeviceView(hass.config.path(CONFIGURATION_FILE)))
|
hass.http.register_view(iOSIdentifyDeviceView(hass.config.path(CONFIGURATION_FILE)))
|
||||||
hass.http.register_view(iOSPushConfigView(hass.data[DOMAIN][CONF_USER][CONF_PUSH]))
|
hass.http.register_view(iOSPushConfigView(hass.data[DOMAIN][CONF_USER][CONF_PUSH]))
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||||||
CONF_STRUCTURE,
|
CONF_STRUCTURE,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
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 = {}
|
_CONFIGURING = {}
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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
|
# Configuration for the legacy nest API
|
||||||
SERVICE_CANCEL_ETA = "cancel_eta"
|
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):
|
if not await hass.async_add_executor_job(hass.data[DATA_NEST].initialize):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_structures(target_structures):
|
def validate_structures(target_structures):
|
||||||
all_structures = [structure.name for structure in nest.structures]
|
all_structures = [structure.name for structure in nest.structures]
|
||||||
|
@ -6,7 +6,12 @@ from requests.exceptions import ConnectTimeout, HTTPError
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -32,7 +37,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
PLATFORMS = ["light"]
|
PLATFORMS = [Platform.LIGHT]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
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.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = plum
|
hass.data[DOMAIN][entry.entry_id] = plum
|
||||||
|
|
||||||
for platform in PLATFORMS:
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
||||||
)
|
|
||||||
|
|
||||||
def cleanup(event):
|
def cleanup(event):
|
||||||
"""Clean up resources."""
|
"""Clean up resources."""
|
||||||
|
@ -4,7 +4,7 @@ import logging
|
|||||||
|
|
||||||
from roonapi import RoonApi
|
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.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
@ -12,6 +12,7 @@ from .const import CONF_ROON_ID, ROON_APPINFO
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
FULL_SYNC_INTERVAL = 30
|
FULL_SYNC_INTERVAL = 30
|
||||||
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||||
|
|
||||||
|
|
||||||
class RoonServer:
|
class RoonServer:
|
||||||
@ -51,11 +52,7 @@ class RoonServer:
|
|||||||
self.roon_id = core_id if core_id is not None else host
|
self.roon_id = core_id if core_id is not None else host
|
||||||
|
|
||||||
# initialize media_player platform
|
# initialize media_player platform
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS)
|
||||||
hass.config_entries.async_forward_entry_setup(
|
|
||||||
self.config_entry, "media_player"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize Roon background polling
|
# Initialize Roon background polling
|
||||||
asyncio.create_task(self.async_do_loop())
|
asyncio.create_task(self.async_do_loop())
|
||||||
|
@ -13,13 +13,16 @@ from withings_api import WithingsAuth
|
|||||||
from withings_api.common import NotifyAppli
|
from withings_api.common import NotifyAppli
|
||||||
|
|
||||||
from homeassistant.components import webhook
|
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 (
|
from homeassistant.components.webhook import (
|
||||||
async_unregister as async_unregister_webhook,
|
async_unregister as async_unregister_webhook,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
@ -36,6 +39,7 @@ from .common import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
DOMAIN = const.DOMAIN
|
DOMAIN = const.DOMAIN
|
||||||
|
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
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.
|
# Start subscription check in the background, outside this component's setup.
|
||||||
async_call_later(hass, 1, async_call_later_callback)
|
async_call_later(hass, 1, async_call_later_callback)
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -162,8 +161,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
data_manager.async_unsubscribe_webhook(),
|
data_manager.async_unsubscribe_webhook(),
|
||||||
hass.config_entries.async_forward_entry_unload(entry, BINARY_SENSOR_DOMAIN),
|
hass.config_entries.async_unload_platforms(entry, PLATFORMS),
|
||||||
hass.config_entries.async_forward_entry_unload(entry, SENSOR_DOMAIN),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async_remove_data_manager(hass, entry)
|
async_remove_data_manager(hass, entry)
|
||||||
|
@ -15,8 +15,9 @@ from homeassistant.const import (
|
|||||||
ATTR_VIA_DEVICE,
|
ATTR_VIA_DEVICE,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, callback
|
from homeassistant.core import CoreState, HomeAssistant, callback
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import (
|
||||||
@ -98,14 +99,14 @@ DEFAULT_CONF_REFRESH_VALUE = False
|
|||||||
DEFAULT_CONF_REFRESH_DELAY = 5
|
DEFAULT_CONF_REFRESH_DELAY = 5
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
"binary_sensor",
|
Platform.BINARY_SENSOR,
|
||||||
"climate",
|
Platform.CLIMATE,
|
||||||
"cover",
|
Platform.COVER,
|
||||||
"fan",
|
Platform.FAN,
|
||||||
"lock",
|
Platform.LIGHT,
|
||||||
"light",
|
Platform.LOCK,
|
||||||
"sensor",
|
Platform.SENSOR,
|
||||||
"switch",
|
Platform.SWITCH,
|
||||||
]
|
]
|
||||||
|
|
||||||
RENAME_NODE_SCHEMA = vol.Schema(
|
RENAME_NODE_SCHEMA = vol.Schema(
|
||||||
@ -341,7 +342,9 @@ async def async_setup(hass, config):
|
|||||||
return True
|
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.
|
"""Set up Z-Wave from a config entry.
|
||||||
|
|
||||||
Will automatically load components to support devices found on the network.
|
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)
|
hass.services.async_register(DOMAIN, const.SERVICE_START_NETWORK, start_zwave)
|
||||||
|
|
||||||
for entry_component in PLATFORMS:
|
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.async_forward_entry_setup(config_entry, entry_component)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user