diff --git a/homeassistant/components/eufy/__init__.py b/homeassistant/components/eufy/__init__.py index ffa30aa6262e..f2198dc70463 100644 --- a/homeassistant/components/eufy/__init__.py +++ b/homeassistant/components/eufy/__init__.py @@ -10,6 +10,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_TYPE, CONF_USERNAME, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.helpers import discovery @@ -42,14 +43,14 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) -EUFY_DISPATCH = { - "T1011": "light", - "T1012": "light", - "T1013": "light", - "T1201": "switch", - "T1202": "switch", - "T1203": "switch", - "T1211": "switch", +PLATFORMS = { + "T1011": Platform.LIGHT, + "T1012": Platform.LIGHT, + "T1013": Platform.LIGHT, + "T1201": Platform.SWITCH, + "T1202": Platform.SWITCH, + "T1203": Platform.SWITCH, + "T1211": Platform.SWITCH, } @@ -62,19 +63,19 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: ) for device in data: kind = device["type"] - if kind not in EUFY_DISPATCH: + if kind not in PLATFORMS: continue - discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config) + discovery.load_platform(hass, PLATFORMS[kind], DOMAIN, device, config) for device_info in config[DOMAIN][CONF_DEVICES]: kind = device_info["type"] - if kind not in EUFY_DISPATCH: + if kind not in PLATFORMS: continue device = {} device["address"] = device_info["address"] device["code"] = device_info["access_token"] device["type"] = device_info["type"] device["name"] = device_info["name"] - discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config) + discovery.load_platform(hass, PLATFORMS[kind], DOMAIN, device, config) return True diff --git a/homeassistant/components/geniushub/__init__.py b/homeassistant/components/geniushub/__init__.py index 72a759427f53..38a0ff15af35 100644 --- a/homeassistant/components/geniushub/__init__.py +++ b/homeassistant/components/geniushub/__init__.py @@ -18,6 +18,7 @@ from homeassistant.const import ( CONF_TOKEN, CONF_USERNAME, TEMP_CELSIUS, + Platform, ) from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import config_validation as cv @@ -95,6 +96,14 @@ SET_ZONE_OVERRIDE_SCHEMA = vol.Schema( } ) +PLATFORMS = ( + Platform.CLIMATE, + Platform.WATER_HEATER, + Platform.SENSOR, + Platform.BINARY_SENSOR, + Platform.SWITCH, +) + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Create a Genius Hub system.""" @@ -120,7 +129,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async_track_time_interval(hass, broker.async_update, SCAN_INTERVAL) - for platform in ("climate", "water_heater", "sensor", "binary_sensor", "switch"): + for platform in PLATFORMS: hass.async_create_task(async_load_platform(hass, platform, DOMAIN, {}, config)) setup_service_functions(hass, broker) diff --git a/homeassistant/components/incomfort/__init__.py b/homeassistant/components/incomfort/__init__.py index 0d255d84ccec..8a40c279c2af 100644 --- a/homeassistant/components/incomfort/__init__.py +++ b/homeassistant/components/incomfort/__init__.py @@ -7,7 +7,7 @@ from aiohttp import ClientResponseError from incomfortclient import Gateway as InComfortGateway import voluptuous as vol -from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME +from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -33,6 +33,13 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) +PLATFORMS = ( + Platform.WATER_HEATER, + Platform.BINARY_SENSOR, + Platform.SENSOR, + Platform.CLIMATE, +) + async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool: """Create an Intergas InComfort/Intouch system.""" @@ -54,7 +61,7 @@ async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool: for heater in heaters: await heater.update() - for platform in ("water_heater", "binary_sensor", "sensor", "climate"): + for platform in PLATFORMS: hass.async_create_task( async_load_platform(hass, platform, DOMAIN, {}, hass_config) ) diff --git a/homeassistant/components/keba/__init__.py b/homeassistant/components/keba/__init__.py index a754321331aa..b957acd2a310 100644 --- a/homeassistant/components/keba/__init__.py +++ b/homeassistant/components/keba/__init__.py @@ -5,7 +5,7 @@ import logging from keba_kecontact.connection import KebaKeContact import voluptuous as vol -from homeassistant.const import CONF_HOST +from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import discovery import homeassistant.helpers.config_validation as cv @@ -14,7 +14,7 @@ from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) DOMAIN = "keba" -SUPPORTED_COMPONENTS = ["binary_sensor", "sensor", "lock", "notify"] +PLATFORMS = (Platform.BINARY_SENSOR, Platform.SENSOR, Platform.LOCK, Platform.NOTIFY) CONF_RFID = "rfid" CONF_FS = "failsafe" @@ -93,9 +93,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.services.async_register(DOMAIN, service, execute_service) # Load components - for domain in SUPPORTED_COMPONENTS: + for platform in PLATFORMS: hass.async_create_task( - discovery.async_load_platform(hass, domain, DOMAIN, {}, config) + discovery.async_load_platform(hass, platform, DOMAIN, {}, config) ) # Start periodic polling of charging station data diff --git a/homeassistant/components/lightwave/__init__.py b/homeassistant/components/lightwave/__init__.py index 9a33265b2abd..e774a27999de 100644 --- a/homeassistant/components/lightwave/__init__.py +++ b/homeassistant/components/lightwave/__init__.py @@ -2,8 +2,6 @@ from lightwave.lightwave import LWLink import voluptuous as vol -from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN -from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.const import ( CONF_HOST, CONF_LIGHTS, @@ -65,6 +63,8 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) +PLATFORMS = (Platform.CLIMATE, Platform.SENSOR) + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Try to start embedded Lightwave broker.""" @@ -88,8 +88,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: proxy_port = trv[CONF_PROXY_PORT] lwlink.set_trv_proxy(proxy_ip, proxy_port) - platforms = [CLIMATE_DOMAIN, SENSOR_DOMAIN] - for platform in platforms: + for platform in PLATFORMS: hass.async_create_task( async_load_platform(hass, platform, DOMAIN, trvs, config) ) diff --git a/homeassistant/components/modbus/const.py b/homeassistant/components/modbus/const.py index 2594408bd745..dccd2eb49906 100644 --- a/homeassistant/components/modbus/const.py +++ b/homeassistant/components/modbus/const.py @@ -1,19 +1,13 @@ """Constants used in modbus integration.""" from enum import Enum -from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN -from homeassistant.components.climate.const import DOMAIN as CLIMATE_DOMAIN -from homeassistant.components.cover import DOMAIN as COVER_DOMAIN -from homeassistant.components.fan import DOMAIN as FAN_DOMAIN -from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN -from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ( CONF_BINARY_SENSORS, CONF_COVERS, CONF_LIGHTS, CONF_SENSORS, CONF_SWITCHES, + Platform, ) # configuration names @@ -131,11 +125,11 @@ MODBUS_DOMAIN = "modbus" ACTIVE_SCAN_INTERVAL = 2 # limit to force an extra update PLATFORMS = ( - (BINARY_SENSOR_DOMAIN, CONF_BINARY_SENSORS), - (CLIMATE_DOMAIN, CONF_CLIMATES), - (COVER_DOMAIN, CONF_COVERS), - (LIGHT_DOMAIN, CONF_LIGHTS), - (FAN_DOMAIN, CONF_FANS), - (SENSOR_DOMAIN, CONF_SENSORS), - (SWITCH_DOMAIN, CONF_SWITCHES), + (Platform.BINARY_SENSOR, CONF_BINARY_SENSORS), + (Platform.CLIMATE, CONF_CLIMATES), + (Platform.COVER, CONF_COVERS), + (Platform.LIGHT, CONF_LIGHTS), + (Platform.FAN, CONF_FANS), + (Platform.SENSOR, CONF_SENSORS), + (Platform.SWITCH, CONF_SWITCHES), ) diff --git a/homeassistant/components/qwikswitch/__init__.py b/homeassistant/components/qwikswitch/__init__.py index a91440db1ed1..ecf7720b2834 100644 --- a/homeassistant/components/qwikswitch/__init__.py +++ b/homeassistant/components/qwikswitch/__init__.py @@ -15,6 +15,7 @@ from homeassistant.const import ( CONF_URL, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, + Platform, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -166,11 +167,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.data[DOMAIN] = qsusb - comps: dict[str, list] = { - "switch": [], - "light": [], - "sensor": [], - "binary_sensor": [], + comps: dict[Platform, list] = { + Platform.SWITCH: [], + Platform.LIGHT: [], + Platform.SENSOR: [], + Platform.BINARY_SENSOR: [], } sensor_ids = [] @@ -179,9 +180,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: _, _type = SENSORS[sens["type"]] sensor_ids.append(sens["id"]) if _type is bool: - comps["binary_sensor"].append(sens) + comps[Platform.BINARY_SENSOR].append(sens) continue - comps["sensor"].append(sens) + comps[Platform.SENSOR].append(sens) for _key in ("invert", "class"): if _key in sens: _LOGGER.warning( @@ -199,9 +200,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if dev.qstype != QSType.relay: _LOGGER.warning("You specified a switch that is not a relay %s", qsid) continue - comps["switch"].append(qsid) + comps[Platform.SWITCH].append(qsid) elif dev.qstype in (QSType.relay, QSType.dimmer): - comps["light"].append(qsid) + comps[Platform.LIGHT].append(qsid) else: _LOGGER.warning("Ignored unknown QSUSB device: %s", dev) continue diff --git a/homeassistant/components/slide/__init__.py b/homeassistant/components/slide/__init__.py index eee487196852..6ab3528a927a 100644 --- a/homeassistant/components/slide/__init__.py +++ b/homeassistant/components/slide/__init__.py @@ -22,7 +22,7 @@ from homeassistant.helpers.typing import ConfigType from .const import ( API, - COMPONENT, + COMPONENT_PLATFORM, CONF_INVERT_POSITION, DEFAULT_OFFSET, DEFAULT_RETRY, @@ -167,7 +167,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await update_slides() - hass.async_create_task(async_load_platform(hass, COMPONENT, DOMAIN, {}, config)) + hass.async_create_task( + async_load_platform(hass, COMPONENT_PLATFORM, DOMAIN, {}, config) + ) async_track_time_interval(hass, update_slides, scaninterval) diff --git a/homeassistant/components/slide/const.py b/homeassistant/components/slide/const.py index 9748e5e0f8c8..ad59b1f268d3 100644 --- a/homeassistant/components/slide/const.py +++ b/homeassistant/components/slide/const.py @@ -1,7 +1,9 @@ """Define constants for the Slide component.""" +from homeassistant.const import Platform + API = "api" -COMPONENT = "cover" +COMPONENT_PLATFORM = Platform.COVER CONF_INVERT_POSITION = "invert_position" DOMAIN = "slide" SLIDES = "slides" diff --git a/homeassistant/components/supla/__init__.py b/homeassistant/components/supla/__init__.py index 647714bc4616..a1e821695969 100644 --- a/homeassistant/components/supla/__init__.py +++ b/homeassistant/components/supla/__init__.py @@ -8,7 +8,7 @@ import async_timeout from asyncpysupla import SuplaAPI import voluptuous as vol -from homeassistant.const import CONF_ACCESS_TOKEN +from homeassistant.const import CONF_ACCESS_TOKEN, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -28,9 +28,9 @@ CONF_SERVERS = "servers" SCAN_INTERVAL = timedelta(seconds=10) SUPLA_FUNCTION_HA_CMP_MAP = { - "CONTROLLINGTHEROLLERSHUTTER": "cover", - "CONTROLLINGTHEGATE": "cover", - "LIGHTSWITCH": "switch", + "CONTROLLINGTHEROLLERSHUTTER": Platform.COVER, + "CONTROLLINGTHEGATE": Platform.COVER, + "LIGHTSWITCH": Platform.SWITCH, } SUPLA_FUNCTION_NONE = "NONE" SUPLA_SERVERS = "supla_servers" @@ -98,7 +98,7 @@ async def discover_devices(hass, hass_config): Currently it is only run at startup. """ - component_configs = {} + component_configs: dict[Platform, list[dict]] = {} for server_name, server in hass.data[DOMAIN][SUPLA_SERVERS].items():