Skip to content
Merged
25 changes: 13 additions & 12 deletions homeassistant/components/eufy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CONF_PASSWORD,
CONF_TYPE,
CONF_USERNAME,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
Expand Down Expand Up @@ -42,14 +43,14 @@
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,
}


Expand All @@ -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
11 changes: 10 additions & 1 deletion homeassistant/components/geniushub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CONF_TOKEN,
CONF_USERNAME,
TEMP_CELSIUS,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -95,6 +96,14 @@
}
)

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."""
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions homeassistant/components/incomfort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand All @@ -33,6 +33,13 @@
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."""
Expand All @@ -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)
)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/keba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -14,7 +14,7 @@
_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"
Expand Down Expand Up @@ -93,9 +93,9 @@ async def execute_service(call: ServiceCall) -> None:
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
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/lightwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +63,8 @@
extra=vol.ALLOW_EXTRA,
)

PLATFORMS = (Platform.CLIMATE, Platform.SENSOR)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Try to start embedded Lightwave broker."""
Expand All @@ -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)
)
Expand Down
22 changes: 8 additions & 14 deletions homeassistant/components/modbus/const.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -131,11 +125,11 @@ class DataType(str, Enum):
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),
)
19 changes: 10 additions & 9 deletions homeassistant/components/qwikswitch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CONF_URL,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand Down Expand Up @@ -166,11 +167,11 @@ def callback_value_changed(_qsd, qsid, _val):

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 = []
Expand All @@ -179,9 +180,9 @@ def callback_value_changed(_qsd, qsid, _val):
_, _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(
Expand All @@ -199,9 +200,9 @@ def callback_value_changed(_qsd, qsid, _val):
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
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/slide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from .const import (
API,
COMPONENT,
COMPONENT_PLATFORM,
CONF_INVERT_POSITION,
DEFAULT_OFFSET,
DEFAULT_RETRY,
Expand Down Expand Up @@ -167,7 +167,9 @@ async def retry_setup(now):

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)

Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/slide/const.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/supla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
Expand All @@ -28,9 +28,9 @@
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"
Expand Down Expand Up @@ -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():

Expand Down