From 4d3f70ad0518f22e320e7d57d6431359a5413a05 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 9 Jan 2022 07:57:51 +0100 Subject: [PATCH] Use Platform enum (#63577) --- homeassistant/components/apple_tv/__init__.py | 5 ++--- .../components/bmw_connected_drive/__init__.py | 2 +- homeassistant/components/huawei_lte/__init__.py | 2 +- homeassistant/components/life360/__init__.py | 8 +++----- homeassistant/components/netgear_lte/__init__.py | 7 ++++--- homeassistant/components/nfandroidtv/__init__.py | 10 +++++++--- homeassistant/components/qvr_pro/__init__.py | 11 ++++++++--- homeassistant/components/rainbird/__init__.py | 4 ++-- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/apple_tv/__init__.py b/homeassistant/components/apple_tv/__init__.py index af581db1a18..1988dbe26e5 100644 --- a/homeassistant/components/apple_tv/__init__.py +++ b/homeassistant/components/apple_tv/__init__.py @@ -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: diff --git a/homeassistant/components/bmw_connected_drive/__init__.py b/homeassistant/components/bmw_connected_drive/__init__.py index d5c3e527a5b..400ab504c22 100644 --- a/homeassistant/components/bmw_connected_drive/__init__.py +++ b/homeassistant/components/bmw_connected_drive/__init__.py @@ -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], diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index f7dc1ca9fe8..6f1eb6c7a60 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -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, diff --git a/homeassistant/components/life360/__init__.py b/homeassistant/components/life360/__init__.py index 96227951527..be77d00f87a 100644 --- a/homeassistant/components/life360/__init__.py +++ b/homeassistant/components/life360/__init__.py @@ -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 diff --git a/homeassistant/components/netgear_lte/__init__.py b/homeassistant/components/netgear_lte/__init__.py index 74ddc15e742..289f1725db4 100644 --- a/homeassistant/components/netgear_lte/__init__.py +++ b/homeassistant/components/netgear_lte/__init__.py @@ -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 ) ) diff --git a/homeassistant/components/nfandroidtv/__init__.py b/homeassistant/components/nfandroidtv/__init__.py index 92bb492bf7d..458015c5bb6 100644 --- a/homeassistant/components/nfandroidtv/__init__.py +++ b/homeassistant/components/nfandroidtv/__init__.py @@ -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], ) ) diff --git a/homeassistant/components/qvr_pro/__init__.py b/homeassistant/components/qvr_pro/__init__.py index d80511f3def..d0fc8511dd3 100644 --- a/homeassistant/components/qvr_pro/__init__.py +++ b/homeassistant/components/qvr_pro/__init__.py @@ -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: diff --git a/homeassistant/components/rainbird/__init__.py b/homeassistant/components/rainbird/__init__.py index 37eff5e81f0..d36cf7786ac 100644 --- a/homeassistant/components/rainbird/__init__.py +++ b/homeassistant/components/rainbird/__init__.py @@ -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__)