Use Platform enum (#63577)

pull/63724/head
Marc Mueller 2022-01-09 07:57:51 +01:00 committed by GitHub
parent 8e0b124875
commit 4d3f70ad05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 21 deletions

View File

@ -7,8 +7,6 @@ from pyatv import connect, exceptions, scan
from pyatv.const import DeviceModel, Protocol
from pyatv.convert import model_str
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_CONNECTIONS,
@ -21,6 +19,7 @@ from homeassistant.const import (
CONF_ADDRESS,
CONF_NAME,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
@ -43,7 +42,7 @@ BACKOFF_TIME_UPPER_LIMIT = 300 # Five minutes
SIGNAL_CONNECTED = "apple_tv_connected"
SIGNAL_DISCONNECTED = "apple_tv_disconnected"
PLATFORMS = [MP_DOMAIN, REMOTE_DOMAIN]
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

View File

@ -164,7 +164,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.async_create_task(
discovery.async_load_platform(
hass,
NOTIFY_DOMAIN,
Platform.NOTIFY,
DOMAIN,
{CONF_NAME: DOMAIN},
hass.data[DOMAIN][DATA_HASS_CONFIG],

View File

@ -461,7 +461,7 @@ async def async_setup_entry( # noqa: C901
# Notify doesn't support config entry setup yet, load with discovery for now
await discovery.async_load_platform(
hass,
NOTIFY_DOMAIN,
Platform.NOTIFY,
DOMAIN,
{
ATTR_UNIQUE_ID: entry.unique_id,

View File

@ -2,10 +2,7 @@
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.device_tracker import (
CONF_SCAN_INTERVAL,
DOMAIN as DEVICE_TRACKER,
)
from homeassistant.components.device_tracker import CONF_SCAN_INTERVAL
from homeassistant.components.device_tracker.const import (
SCAN_INTERVAL as DEFAULT_SCAN_INTERVAL,
)
@ -16,6 +13,7 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_PREFIX,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
@ -153,7 +151,7 @@ def setup(hass, config):
"""Set up integration."""
conf = config.get(DOMAIN, LIFE360_SCHEMA({}))
hass.data[DOMAIN] = {"config": conf, "apis": {}}
discovery.load_platform(hass, DEVICE_TRACKER, DOMAIN, None, config)
discovery.load_platform(hass, Platform.DEVICE_TRACKER, DOMAIN, None, config)
if CONF_ACCOUNTS not in conf:
return True

View File

@ -18,6 +18,7 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_RECIPIENT,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import config_validation as cv, discovery
@ -232,7 +233,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
}
hass.async_create_task(
discovery.async_load_platform(
hass, NOTIFY_DOMAIN, DOMAIN, discovery_info, config
hass, Platform.NOTIFY, DOMAIN, discovery_info, config
)
)
@ -241,7 +242,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
discovery_info = {CONF_HOST: lte_conf[CONF_HOST], SENSOR_DOMAIN: sensor_conf}
hass.async_create_task(
discovery.async_load_platform(
hass, SENSOR_DOMAIN, DOMAIN, discovery_info, config
hass, Platform.SENSOR, DOMAIN, discovery_info, config
)
)
@ -253,7 +254,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
}
hass.async_create_task(
discovery.async_load_platform(
hass, BINARY_SENSOR_DOMAIN, DOMAIN, discovery_info, config
hass, Platform.BINARY_SENSOR, DOMAIN, discovery_info, config
)
)

View File

@ -3,7 +3,7 @@ from notifications_android_tv.notifications import ConnectError, Notifications
from homeassistant.components.notify import DOMAIN as NOTIFY
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PLATFORM
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PLATFORM, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import discovery
@ -11,7 +11,7 @@ from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN
PLATFORMS = [NOTIFY]
PLATFORMS = [Platform.NOTIFY]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
@ -48,7 +48,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.async_create_task(
discovery.async_load_platform(
hass, NOTIFY, DOMAIN, hass.data[DOMAIN][entry.entry_id], hass.data[DOMAIN]
hass,
Platform.NOTIFY,
DOMAIN,
hass.data[DOMAIN][entry.entry_id],
hass.data[DOMAIN],
)
)

View File

@ -6,8 +6,13 @@ from pyqvrpro.client import AuthenticationError, InsufficientPermissionsError
from requests.exceptions import ConnectionError as RequestsConnectionError
import voluptuous as vol
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
@ -82,7 +87,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.data[DOMAIN] = {"channels": channels, "client": qvrpro}
load_platform(hass, CAMERA_DOMAIN, DOMAIN, {}, config)
load_platform(hass, Platform.CAMERA, DOMAIN, {}, config)
# Register services
def handle_start_record(call: ServiceCall) -> None:

View File

@ -6,7 +6,6 @@ import logging
from pyrainbird import RainbirdController
import voluptuous as vol
from homeassistant.components import binary_sensor, sensor, switch
from homeassistant.components.binary_sensor import BinarySensorEntityDescription
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.const import (
@ -14,6 +13,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_TRIGGER_TIME,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
@ -22,7 +22,7 @@ from homeassistant.helpers.typing import ConfigType
CONF_ZONES = "zones"
PLATFORMS = [switch.DOMAIN, sensor.DOMAIN, binary_sensor.DOMAIN]
PLATFORMS = [Platform.SWITCH, Platform.SENSOR, Platform.BINARY_SENSOR]
_LOGGER = logging.getLogger(__name__)