Use Platform enum in load_platform [a-l] (#63750)

This commit is contained in:
epenet 2022-01-10 10:30:47 +01:00 committed by GitHub
parent b78e22e012
commit c7cb26cbab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 87 additions and 42 deletions

View file

@ -17,6 +17,7 @@ from homeassistant.const import (
CONF_SWITCHES,
CONF_TIMEOUT,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import discovery
@ -246,14 +247,16 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
mjpeg_camera.update({CONF_USERNAME: username, CONF_PASSWORD: password})
hass.async_create_task(
discovery.async_load_platform(hass, "camera", "mjpeg", mjpeg_camera, config)
discovery.async_load_platform(
hass, Platform.CAMERA, "mjpeg", mjpeg_camera, config
)
)
if sensors:
hass.async_create_task(
discovery.async_load_platform(
hass,
"sensor",
Platform.SENSOR,
DOMAIN,
{CONF_NAME: name, CONF_HOST: host, CONF_SENSORS: sensors},
config,
@ -264,7 +267,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.async_create_task(
discovery.async_load_platform(
hass,
"switch",
Platform.SWITCH,
DOMAIN,
{CONF_NAME: name, CONF_HOST: host, CONF_SWITCHES: switches},
config,
@ -275,7 +278,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.async_create_task(
discovery.async_load_platform(
hass,
"binary_sensor",
Platform.BINARY_SENSOR,
DOMAIN,
{CONF_HOST: host, CONF_NAME: name},
config,

View file

@ -13,6 +13,7 @@ from homeassistant.const import (
CONF_NAME,
CONF_PROFILE_NAME,
CONF_SERVICE,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, discovery
@ -149,7 +150,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# have to use discovery to load platform.
for notify_config in conf[CONF_NOTIFY]:
hass.async_create_task(
discovery.async_load_platform(hass, "notify", DOMAIN, notify_config, config)
discovery.async_load_platform(
hass, Platform.NOTIFY, DOMAIN, notify_config, config
)
)
return validation

View file

@ -1,7 +1,7 @@
"""The Unify Circuit component."""
import voluptuous as vol
from homeassistant.const import CONF_NAME, CONF_URL
from homeassistant.const import CONF_NAME, CONF_URL, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.typing import ConfigType
@ -29,7 +29,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
for webhook_conf in webhooks:
hass.async_create_task(
discovery.async_load_platform(hass, "notify", DOMAIN, webhook_conf, config)
discovery.async_load_platform(
hass, Platform.NOTIFY, DOMAIN, webhook_conf, config
)
)
return True

View file

@ -12,6 +12,7 @@ from homeassistant.const import (
CONF_NAME,
CONF_REGION,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import HomeAssistantError
@ -224,10 +225,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
loaded = True
await hass.helpers.discovery.async_load_platform(
"binary_sensor", DOMAIN, {}, config
Platform.BINARY_SENSOR, DOMAIN, {}, config
)
await hass.helpers.discovery.async_load_platform(
Platform.STT, DOMAIN, {}, config
)
await hass.helpers.discovery.async_load_platform(
Platform.TTS, DOMAIN, {}, config
)
await hass.helpers.discovery.async_load_platform("stt", DOMAIN, {}, config)
await hass.helpers.discovery.async_load_platform("tts", DOMAIN, {}, config)
cloud.iot.register_on_connect(_on_connect)

View file

@ -10,6 +10,7 @@ from homeassistant.const import (
CONF_PIN,
CONF_TOKEN,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
@ -82,7 +83,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown)
# Load platforms
discovery.load_platform(hass, "fan", DOMAIN, {}, config)
discovery.load_platform(hass, Platform.FAN, DOMAIN, {}, config)
return True

View file

@ -10,6 +10,7 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
CONF_NAME,
CONF_PORT,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
@ -74,7 +75,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"client_name": name,
"sensor_types": SENSOR_TYPES[circuit],
}
load_platform(hass, "sensor", DOMAIN, sensor_config, config)
load_platform(hass, Platform.SENSOR, DOMAIN, sensor_config, config)
hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE, hass.data[DOMAIN].write)

View file

@ -11,6 +11,7 @@ from homeassistant.const import (
CONF_SENSORS,
CONF_SWITCHES,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
@ -102,8 +103,8 @@ def setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
hass.data[DATA_ECOAL_BOILER] = ecoal_contr
# Setup switches
switches = conf[CONF_SWITCHES][CONF_MONITORED_CONDITIONS]
load_platform(hass, "switch", DOMAIN, switches, hass_config)
load_platform(hass, Platform.SWITCH, DOMAIN, switches, hass_config)
# Setup temp sensors
sensors = conf[CONF_SENSORS][CONF_MONITORED_CONDITIONS]
load_platform(hass, "sensor", DOMAIN, sensors, hass_config)
load_platform(hass, Platform.SENSOR, DOMAIN, sensors, hass_config)
return True

View file

@ -6,7 +6,12 @@ import string
from sucks import EcoVacsAPI, VacBot
import voluptuous as vol
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.helpers import discovery
import homeassistant.helpers.config_validation as cv
@ -89,6 +94,6 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
if hass.data[ECOVACS_DEVICES]:
_LOGGER.debug("Starting vacuum components")
discovery.load_platform(hass, "vacuum", DOMAIN, {}, config)
discovery.load_platform(hass, Platform.VACUUM, DOMAIN, {}, config)
return True

View file

@ -12,6 +12,7 @@ from homeassistant.const import (
CONF_PORT,
CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
@ -129,13 +130,13 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
return False
discovery.load_platform(
hass, "alarm_control_panel", DOMAIN, discovered=conf, hass_config=config
hass, Platform.ALARM_CONTROL_PANEL, DOMAIN, discovered=conf, hass_config=config
)
# Get the sensors from the device and add those
sensors = device.getsensors()
discovery.load_platform(
hass, "binary_sensor", DOMAIN, {ATTR_DISCOVER_DEVICES: sensors}, config
hass, Platform.BINARY_SENSOR, DOMAIN, {ATTR_DISCOVER_DEVICES: sensors}, config
)
return True

View file

@ -14,6 +14,7 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_SENSORS,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import discovery
@ -154,13 +155,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.async_create_task(
discovery.async_load_platform(
hass, "sensor", DOMAIN, {CONF_SENSORS: sensors}, config
hass, Platform.SENSOR, DOMAIN, {CONF_SENSORS: sensors}, config
)
)
hass.async_create_task(
discovery.async_load_platform(
hass, "binary_sensor", DOMAIN, {CONF_BINARY_SENSORS: binary_sensors}, config
hass,
Platform.BINARY_SENSOR,
DOMAIN,
{CONF_BINARY_SENSORS: binary_sensors},
config,
)
)

View file

@ -2,6 +2,7 @@
from __future__ import annotations
from homeassistant.components import frontend
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
from homeassistant.helpers.typing import ConfigType
@ -25,7 +26,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
frontend.async_register_built_in_panel(hass, DOMAIN, DOMAIN, "mdi:lightning-bolt")
hass.async_create_task(
discovery.async_load_platform(hass, "sensor", DOMAIN, {}, config)
discovery.async_load_platform(hass, Platform.SENSOR, DOMAIN, {}, config)
)
hass.data[DOMAIN] = {
"cost_sensors": {},

View file

@ -10,6 +10,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_TIMEOUT,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import ServiceCall, callback
import homeassistant.helpers.config_validation as cv
@ -206,7 +207,7 @@ async def async_setup(hass, config):
hass.async_create_task(
async_load_platform(
hass,
"alarm_control_panel",
Platform.ALARM_CONTROL_PANEL,
"envisalink",
{CONF_PARTITIONS: partitions, CONF_CODE: code, CONF_PANIC: panic_type},
config,
@ -215,7 +216,7 @@ async def async_setup(hass, config):
hass.async_create_task(
async_load_platform(
hass,
"sensor",
Platform.SENSOR,
"envisalink",
{CONF_PARTITIONS: partitions, CONF_CODE: code},
config,
@ -224,7 +225,7 @@ async def async_setup(hass, config):
if zones:
hass.async_create_task(
async_load_platform(
hass, "binary_sensor", "envisalink", {CONF_ZONES: zones}, config
hass, Platform.BINARY_SENSOR, "envisalink", {CONF_ZONES: zones}, config
)
)

View file

@ -21,6 +21,7 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL,
CONF_USERNAME,
TEMP_CELSIUS,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -247,10 +248,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
await broker.save_auth_tokens()
await broker.async_update() # get initial state
hass.async_create_task(async_load_platform(hass, "climate", DOMAIN, {}, config))
hass.async_create_task(
async_load_platform(hass, Platform.CLIMATE, DOMAIN, {}, config)
)
if broker.tcs.hotwater:
hass.async_create_task(
async_load_platform(hass, "water_heater", DOMAIN, {}, config)
async_load_platform(hass, Platform.WATER_HEATER, DOMAIN, {}, config)
)
hass.helpers.event.async_track_time_interval(

View file

@ -8,7 +8,7 @@ from typing import Any
from fastdotcom import fast_com
import voluptuous as vol
from homeassistant.const import CONF_SCAN_INTERVAL
from homeassistant.const import CONF_SCAN_INTERVAL, Platform
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
@ -54,7 +54,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.services.async_register(DOMAIN, "speedtest", update)
hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config))
hass.async_create_task(
async_load_platform(hass, Platform.SENSOR, DOMAIN, {}, config)
)
return True

View file

@ -2,7 +2,7 @@
import voluptuous as vol
from homeassistant.components.humidifier import HumidifierDeviceClass
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.typing import ConfigType
@ -65,7 +65,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
for hygrostat_conf in config[DOMAIN]:
hass.async_create_task(
discovery.async_load_platform(
hass, "humidifier", DOMAIN, hygrostat_conf, config
hass, Platform.HUMIDIFIER, DOMAIN, hygrostat_conf, config
)
)

View file

@ -23,6 +23,7 @@ from homeassistant.const import (
CONF_ENTITIES,
CONF_NAME,
CONF_OFFSET,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import discovery
@ -283,7 +284,7 @@ def setup_services(
discovery.load_platform(
hass,
"calendar",
Platform.CALENDAR,
DOMAIN,
hass.data[DATA_INDEX][calendar[CONF_CAL_ID]],
hass_config,
@ -370,7 +371,7 @@ def do_setup(hass, hass_config, config):
)
for calendar in hass.data[DATA_INDEX].values():
discovery.load_platform(hass, "calendar", DOMAIN, calendar, hass_config)
discovery.load_platform(hass, Platform.CALENDAR, DOMAIN, calendar, hass_config)
# Look for any new calendars
hass.services.call(DOMAIN, SERVICE_SCAN_CALENDARS, None)

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
TIME_HOURS,
TIME_MINUTES,
TIME_SECONDS,
Platform,
)
from homeassistant.core import Event, HomeAssistant
import homeassistant.helpers.config_validation as cv
@ -143,7 +144,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return False
hass.async_create_task(
async_load_platform(hass, "sensor", DOMAIN, config[DOMAIN], config)
async_load_platform(hass, Platform.SENSOR, DOMAIN, config[DOMAIN], config)
)
return True

View file

@ -10,6 +10,7 @@ from homeassistant.const import (
CONF_NAME,
CONF_PORT,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
@ -84,7 +85,7 @@ def setup(hass: HomeAssistant, base_config: ConfigType) -> bool:
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup)
dimmers = config[CONF_DIMMERS]
load_platform(hass, "light", DOMAIN, {CONF_DIMMERS: dimmers}, base_config)
load_platform(hass, Platform.LIGHT, DOMAIN, {CONF_DIMMERS: dimmers}, base_config)
for key_config in config[CONF_KEYPADS]:
addr = key_config[CONF_ADDR]

View file

@ -271,7 +271,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass.data[DOMAIN] = ios_config
# No entry support for notify component yet
discovery.load_platform(hass, "notify", DOMAIN, {}, config)
discovery.load_platform(hass, Platform.NOTIFY, DOMAIN, {}, config)
if conf is not None:
hass.async_create_task(

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from hdate import Location
import voluptuous as vol
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
@ -97,10 +97,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"prefix": prefix,
}
hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config))
hass.async_create_task(
async_load_platform(hass, Platform.SENSOR, DOMAIN, {}, config)
)
hass.async_create_task(
async_load_platform(hass, "binary_sensor", DOMAIN, {}, config)
async_load_platform(hass, Platform.BINARY_SENSOR, DOMAIN, {}, config)
)
return True

View file

@ -269,7 +269,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if NotifySchema.PLATFORM in config:
hass.async_create_task(
discovery.async_load_platform(
hass, "notify", DOMAIN, {}, hass.data[DATA_HASS_CONFIG]
hass, Platform.NOTIFY, DOMAIN, {}, hass.data[DATA_HASS_CONFIG]
)
)

View file

@ -4,7 +4,13 @@ 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, CONF_NAME, CONF_SWITCHES
from homeassistant.const import (
CONF_HOST,
CONF_LIGHTS,
CONF_NAME,
CONF_SWITCHES,
Platform,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
@ -68,12 +74,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if lights := config[DOMAIN][CONF_LIGHTS]:
hass.async_create_task(
async_load_platform(hass, "light", DOMAIN, lights, config)
async_load_platform(hass, Platform.LIGHT, DOMAIN, lights, config)
)
if switches := config[DOMAIN][CONF_SWITCHES]:
hass.async_create_task(
async_load_platform(hass, "switch", DOMAIN, switches, config)
async_load_platform(hass, Platform.SWITCH, DOMAIN, switches, config)
)
if trv := config[DOMAIN][CONF_TRV]: