mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use platform enum (8) [Misc] (#61013)
This commit is contained in:
parent
c8f2d4a82b
commit
d6f48683a3
@ -1,10 +1,7 @@
|
||||
"""Constants for the Axis component."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import Platform
|
||||
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
@ -22,4 +19,4 @@ DEFAULT_STREAM_PROFILE = "No stream profile"
|
||||
DEFAULT_TRIGGER_TIME = 0
|
||||
DEFAULT_VIDEO_SOURCE = "No video source"
|
||||
|
||||
PLATFORMS = [BINARY_SENSOR_DOMAIN, CAMERA_DOMAIN, LIGHT_DOMAIN, SWITCH_DOMAIN]
|
||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.LIGHT, Platform.SWITCH]
|
||||
|
@ -4,6 +4,7 @@ from homeassistant.const import (
|
||||
CONF_LIGHTS,
|
||||
CONF_SENSORS,
|
||||
CONF_SWITCHES,
|
||||
Platform,
|
||||
)
|
||||
|
||||
CONF_ARDUINO_INSTANCE_ID = "arduino_instance_id"
|
||||
@ -27,8 +28,8 @@ CONF_SLEEP_TUNE = "sleep_tune"
|
||||
DOMAIN = "firmata"
|
||||
FIRMATA_MANUFACTURER = "Firmata"
|
||||
CONF_PLATFORM_MAP = {
|
||||
CONF_BINARY_SENSORS: "binary_sensor",
|
||||
CONF_LIGHTS: "light",
|
||||
CONF_SENSORS: "sensor",
|
||||
CONF_SWITCHES: "switch",
|
||||
CONF_BINARY_SENSORS: Platform.BINARY_SENSOR,
|
||||
CONF_LIGHTS: Platform.LIGHT,
|
||||
CONF_SENSORS: Platform.SENSOR,
|
||||
CONF_SWITCHES: Platform.SWITCH,
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Constants for Hive."""
|
||||
from homeassistant.const import Platform
|
||||
|
||||
ATTR_MODE = "mode"
|
||||
ATTR_TIME_PERIOD = "time_period"
|
||||
ATTR_ONOFF = "on_off"
|
||||
@ -7,22 +9,22 @@ CONFIG_ENTRY_VERSION = 1
|
||||
DEFAULT_NAME = "Hive"
|
||||
DOMAIN = "hive"
|
||||
PLATFORMS = [
|
||||
"alarm_control_panel",
|
||||
"binary_sensor",
|
||||
"climate",
|
||||
"light",
|
||||
"sensor",
|
||||
"switch",
|
||||
"water_heater",
|
||||
Platform.ALARM_CONTROL_PANEL,
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
Platform.LIGHT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.WATER_HEATER,
|
||||
]
|
||||
PLATFORM_LOOKUP = {
|
||||
"alarm_control_panel": "alarm_control_panel",
|
||||
"binary_sensor": "binary_sensor",
|
||||
"climate": "climate",
|
||||
"light": "light",
|
||||
"sensor": "sensor",
|
||||
"switch": "switch",
|
||||
"water_heater": "water_heater",
|
||||
Platform.ALARM_CONTROL_PANEL: "alarm_control_panel",
|
||||
Platform.BINARY_SENSOR: "binary_sensor",
|
||||
Platform.CLIMATE: "climate",
|
||||
Platform.LIGHT: "light",
|
||||
Platform.SENSOR: "sensor",
|
||||
Platform.SWITCH: "switch",
|
||||
Platform.WATER_HEATER: "water_heater",
|
||||
}
|
||||
SERVICE_BOOST_HOT_WATER = "boost_hot_water"
|
||||
SERVICE_BOOST_HEATING_ON = "boost_heating_on"
|
||||
|
@ -8,7 +8,7 @@ from homepluscontrol.homeplusapi import HomePlusControlApiError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
|
||||
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import (
|
||||
config_entry_oauth2_flow,
|
||||
@ -46,7 +46,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
)
|
||||
|
||||
# The Legrand Home+ Control platform is currently limited to "switch" entities
|
||||
PLATFORMS = ["switch"]
|
||||
PLATFORMS = [Platform.SWITCH]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -10,11 +10,8 @@ from typing import Any, cast
|
||||
from awesomeversion import AwesomeVersion
|
||||
from hyperion import client, const as hyperion_const
|
||||
|
||||
from homeassistant.components.camera.const import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@ -36,7 +33,7 @@ from .const import (
|
||||
SIGNAL_INSTANCE_REMOVE,
|
||||
)
|
||||
|
||||
PLATFORMS = [LIGHT_DOMAIN, SWITCH_DOMAIN, CAMERA_DOMAIN]
|
||||
PLATFORMS = [Platform.LIGHT, Platform.SWITCH, Platform.CAMERA]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -25,7 +25,7 @@ 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.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
@ -135,19 +135,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
forward_setup = hass.config_entries.async_forward_entry_setup
|
||||
if binary_sensors:
|
||||
_LOGGER.debug("Got %s binary sensors: %s", len(binary_sensors), binary_sensors)
|
||||
hass.async_create_task(forward_setup(entry, BINARY_SENSOR_DOMAIN))
|
||||
hass.async_create_task(forward_setup(entry, Platform.BINARY_SENSOR))
|
||||
if climates:
|
||||
_LOGGER.debug("Got %s climates: %s", len(climates), climates)
|
||||
hass.async_create_task(forward_setup(entry, CLIMATE_DOMAIN))
|
||||
hass.async_create_task(forward_setup(entry, Platform.CLIMATE))
|
||||
if lights:
|
||||
_LOGGER.debug("Got %s lights: %s", len(lights), lights)
|
||||
hass.async_create_task(forward_setup(entry, LIGHT_DOMAIN))
|
||||
hass.async_create_task(forward_setup(entry, Platform.LIGHT))
|
||||
if sensors:
|
||||
_LOGGER.debug("Got %s sensors: %s", len(sensors), sensors)
|
||||
hass.async_create_task(forward_setup(entry, SENSOR_DOMAIN))
|
||||
hass.async_create_task(forward_setup(entry, Platform.SENSOR))
|
||||
if switches:
|
||||
_LOGGER.debug("Got %s switches: %s", len(switches), switches)
|
||||
hass.async_create_task(forward_setup(entry, SWITCH_DOMAIN))
|
||||
hass.async_create_task(forward_setup(entry, Platform.SWITCH))
|
||||
|
||||
async def _async_systems_update(now):
|
||||
"""Refresh internal state for all systems."""
|
||||
|
@ -34,15 +34,17 @@ from pyinsteon.groups import (
|
||||
TEST_SENSOR,
|
||||
)
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
DOMAIN = "insteon"
|
||||
|
||||
INSTEON_PLATFORMS = [
|
||||
"binary_sensor",
|
||||
"climate",
|
||||
"cover",
|
||||
"fan",
|
||||
"light",
|
||||
"switch",
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
Platform.COVER,
|
||||
Platform.FAN,
|
||||
Platform.LIGHT,
|
||||
Platform.SWITCH,
|
||||
]
|
||||
|
||||
X10_PLATFORMS = [
|
||||
|
@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
from collections import defaultdict
|
||||
from typing import Final, Literal, Tuple, TypedDict
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
ATTR_DEVICES: Final = "devices"
|
||||
ATTR_GATEWAY_ID: Final = "gateway_id"
|
||||
|
||||
@ -144,15 +146,15 @@ SWITCH_TYPES: dict[SensorType, set[ValueType]] = {
|
||||
}
|
||||
|
||||
|
||||
PLATFORM_TYPES: dict[str, dict[SensorType, set[ValueType]]] = {
|
||||
"binary_sensor": BINARY_SENSOR_TYPES,
|
||||
"climate": CLIMATE_TYPES,
|
||||
"cover": COVER_TYPES,
|
||||
"device_tracker": DEVICE_TRACKER_TYPES,
|
||||
"light": LIGHT_TYPES,
|
||||
"notify": NOTIFY_TYPES,
|
||||
"sensor": SENSOR_TYPES,
|
||||
"switch": SWITCH_TYPES,
|
||||
PLATFORM_TYPES: dict[Platform, dict[SensorType, set[ValueType]]] = {
|
||||
Platform.BINARY_SENSOR: BINARY_SENSOR_TYPES,
|
||||
Platform.CLIMATE: CLIMATE_TYPES,
|
||||
Platform.COVER: COVER_TYPES,
|
||||
Platform.DEVICE_TRACKER: DEVICE_TRACKER_TYPES,
|
||||
Platform.LIGHT: LIGHT_TYPES,
|
||||
Platform.NOTIFY: NOTIFY_TYPES,
|
||||
Platform.SENSOR: SENSOR_TYPES,
|
||||
Platform.SWITCH: SWITCH_TYPES,
|
||||
}
|
||||
|
||||
FLAT_PLATFORM_TYPES: dict[tuple[str, SensorType], set[ValueType]] = {
|
||||
@ -168,6 +170,6 @@ for platform, platform_types in PLATFORM_TYPES.items():
|
||||
TYPE_TO_PLATFORMS[s_type_name].append(platform)
|
||||
|
||||
PLATFORMS_WITH_ENTRY_SUPPORT = set(PLATFORM_TYPES.keys()) - {
|
||||
"notify",
|
||||
"device_tracker",
|
||||
Platform.NOTIFY,
|
||||
Platform.DEVICE_TRACKER,
|
||||
}
|
||||
|
@ -6,10 +6,15 @@ from urllib.error import HTTPError, URLError
|
||||
from panasonic_viera import EncryptionRequired, Keys, RemoteControl, SOAPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player.const import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
@ -46,7 +51,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
PLATFORMS = [MEDIA_PLAYER_DOMAIN, REMOTE_DOMAIN]
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE]
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
|
@ -11,6 +11,7 @@ from homeassistant.const import (
|
||||
CONF_PIN,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -20,7 +21,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
|
||||
from .const import DATA_COORDINATOR, DEFAULT_SCAN_INTERVAL, DOMAIN, EVENTS_COORDINATOR
|
||||
|
||||
PLATFORMS = ["alarm_control_panel", "binary_sensor", "sensor"]
|
||||
PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||
LAST_EVENT_STORAGE_VERSION = 1
|
||||
LAST_EVENT_TIMESTAMP_KEY = "last_event_timestamp"
|
||||
|
@ -9,7 +9,7 @@ from aioswitcher.device import SwitcherBase
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_DEVICE_ID, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.const import CONF_DEVICE_ID, EVENT_HOMEASSISTANT_STOP, Platform
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
@ -30,7 +30,7 @@ from .const import (
|
||||
)
|
||||
from .utils import async_start_bridge, async_stop_bridge
|
||||
|
||||
PLATFORMS = ["switch", "sensor"]
|
||||
PLATFORMS = [Platform.SWITCH, Platform.SENSOR]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Constants used by multiple Tasmota modules."""
|
||||
from homeassistant.const import Platform
|
||||
|
||||
CONF_DISCOVERY_PREFIX = "discovery_prefix"
|
||||
|
||||
DATA_REMOVE_DISCOVER_COMPONENT = "tasmota_discover_{}"
|
||||
@ -9,12 +11,12 @@ DEFAULT_PREFIX = "tasmota/discovery"
|
||||
DOMAIN = "tasmota"
|
||||
|
||||
PLATFORMS = [
|
||||
"binary_sensor",
|
||||
"cover",
|
||||
"fan",
|
||||
"light",
|
||||
"sensor",
|
||||
"switch",
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.COVER,
|
||||
Platform.FAN,
|
||||
Platform.LIGHT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
]
|
||||
|
||||
TASMOTA_EVENT = "tasmota_event"
|
||||
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
||||
CONF_EXCLUDE,
|
||||
CONF_LIGHTS,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -124,7 +125,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
# Exclude devices unwanted by user.
|
||||
devices = [device for device in all_devices if device.device_id not in exclude_ids]
|
||||
|
||||
vera_devices = defaultdict(list)
|
||||
vera_devices: defaultdict[Platform, list[veraApi.VeraDevice]] = defaultdict(list)
|
||||
for device in devices:
|
||||
device_type = map_vera_device(device, light_ids)
|
||||
if device_type is not None:
|
||||
@ -144,10 +145,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
set_controller_data(hass, entry, controller_data)
|
||||
|
||||
# Forward the config data to the necessary platforms.
|
||||
for platform in get_configured_platforms(controller_data):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
||||
)
|
||||
hass.config_entries.async_setup_platforms(
|
||||
entry, platforms=get_configured_platforms(controller_data)
|
||||
)
|
||||
|
||||
def stop_subscription(event):
|
||||
"""Stop SubscriptionRegistry updates."""
|
||||
@ -181,24 +181,24 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry):
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
def map_vera_device(vera_device: veraApi.VeraDevice, remap: list[int]) -> str:
|
||||
def map_vera_device(vera_device: veraApi.VeraDevice, remap: list[int]) -> Platform:
|
||||
"""Map vera classes to Home Assistant types."""
|
||||
|
||||
type_map = {
|
||||
veraApi.VeraDimmer: "light",
|
||||
veraApi.VeraBinarySensor: "binary_sensor",
|
||||
veraApi.VeraSensor: "sensor",
|
||||
veraApi.VeraArmableDevice: "switch",
|
||||
veraApi.VeraLock: "lock",
|
||||
veraApi.VeraThermostat: "climate",
|
||||
veraApi.VeraCurtain: "cover",
|
||||
veraApi.VeraSceneController: "sensor",
|
||||
veraApi.VeraSwitch: "switch",
|
||||
veraApi.VeraDimmer: Platform.LIGHT,
|
||||
veraApi.VeraBinarySensor: Platform.BINARY_SENSOR,
|
||||
veraApi.VeraSensor: Platform.SENSOR,
|
||||
veraApi.VeraArmableDevice: Platform.SWITCH,
|
||||
veraApi.VeraLock: Platform.LOCK,
|
||||
veraApi.VeraThermostat: Platform.CLIMATE,
|
||||
veraApi.VeraCurtain: Platform.COVER,
|
||||
veraApi.VeraSceneController: Platform.SENSOR,
|
||||
veraApi.VeraSwitch: Platform.SWITCH,
|
||||
}
|
||||
|
||||
def map_special_case(instance_class: type, entity_type: str) -> str:
|
||||
def map_special_case(instance_class: type, entity_type: Platform) -> Platform:
|
||||
if instance_class is veraApi.VeraSwitch and vera_device.device_id in remap:
|
||||
return "light"
|
||||
return Platform.LIGHT
|
||||
return entity_type
|
||||
|
||||
return next(
|
||||
|
@ -2,12 +2,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import defaultdict
|
||||
from collections.abc import Sequence
|
||||
from typing import NamedTuple
|
||||
|
||||
import pyvera as pv
|
||||
|
||||
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.event import call_later
|
||||
|
||||
@ -18,19 +19,19 @@ class ControllerData(NamedTuple):
|
||||
"""Controller data."""
|
||||
|
||||
controller: pv.VeraController
|
||||
devices: defaultdict[str, list[pv.VeraDevice]]
|
||||
devices: defaultdict[Platform, list[pv.VeraDevice]]
|
||||
scenes: list[pv.VeraScene]
|
||||
config_entry: ConfigEntry
|
||||
|
||||
|
||||
def get_configured_platforms(controller_data: ControllerData) -> set[str]:
|
||||
def get_configured_platforms(controller_data: ControllerData) -> set[Platform]:
|
||||
"""Get configured platforms for a controller."""
|
||||
platforms = []
|
||||
platforms: Sequence[Platform] = []
|
||||
for platform in controller_data.devices:
|
||||
platforms.append(platform)
|
||||
|
||||
if controller_data.scenes:
|
||||
platforms.append(SCENE_DOMAIN)
|
||||
platforms.append(Platform.SCENE)
|
||||
|
||||
return set(platforms)
|
||||
|
||||
|
@ -3,7 +3,7 @@ import logging
|
||||
|
||||
from pyvesync import VeSync
|
||||
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
@ -56,15 +56,15 @@ async def async_setup_entry(hass, config_entry):
|
||||
|
||||
if device_dict[VS_SWITCHES]:
|
||||
switches.extend(device_dict[VS_SWITCHES])
|
||||
hass.async_create_task(forward_setup(config_entry, "switch"))
|
||||
hass.async_create_task(forward_setup(config_entry, Platform.SWITCH))
|
||||
|
||||
if device_dict[VS_FANS]:
|
||||
fans.extend(device_dict[VS_FANS])
|
||||
hass.async_create_task(forward_setup(config_entry, "fan"))
|
||||
hass.async_create_task(forward_setup(config_entry, Platform.FAN))
|
||||
|
||||
if device_dict[VS_LIGHTS]:
|
||||
lights.extend(device_dict[VS_LIGHTS])
|
||||
hass.async_create_task(forward_setup(config_entry, "light"))
|
||||
hass.async_create_task(forward_setup(config_entry, Platform.LIGHT))
|
||||
|
||||
async def async_new_device_discovery(service):
|
||||
"""Discover if new devices should be added."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user