Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 17 additions & 63 deletions homeassistant/components/template/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
import voluptuous as vol

from homeassistant.components import websocket_api
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.button import ButtonDeviceClass
from homeassistant.components.cover import CoverDeviceClass
from homeassistant.components.event import EventDeviceClass
from homeassistant.components.number import NumberDeviceClass
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASS_STATE_CLASSES,
DEVICE_CLASS_UNITS,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.components.update import UpdateDeviceClass
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_DEVICE_ID,
Expand Down Expand Up @@ -188,13 +181,8 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:

if domain == Platform.BINARY_SENSOR:
schema |= _SCHEMA_STATE | {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in BinarySensorDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="binary_sensor_device_class",
sort=True,
),
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.BINARY_SENSOR),
),
}

Expand All @@ -204,14 +192,9 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:
}
if flow_type == "config":
schema |= {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in ButtonDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="button_device_class",
sort=True,
),
)
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.BUTTON),
),
}

if domain == Platform.COVER:
Expand All @@ -224,14 +207,9 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:
}
if flow_type == "config":
schema |= {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in CoverDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="cover_device_class",
sort=True,
),
)
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.COVER),
),
}

if domain == Platform.DEVICE_TRACKER:
Expand All @@ -252,14 +230,9 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:

if flow_type == "config":
schema |= {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in EventDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="event_device_class",
sort=True,
),
)
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.EVENT),
),
}

if domain == Platform.FAN:
Expand Down Expand Up @@ -303,13 +276,8 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:

if domain == Platform.NUMBER:
schema |= {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in NumberDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="number_device_class",
sort=True,
),
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.NUMBER),
),
vol.Required(CONF_STATE): selector.TemplateSelector(),
vol.Required(CONF_MIN, default=DEFAULT_MIN_VALUE): selector.NumberSelector(
Expand Down Expand Up @@ -353,17 +321,8 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:
sort=True,
),
),
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[
cls.value
for cls in SensorDeviceClass
if cls != SensorDeviceClass.ENUM
],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="sensor_device_class",
sort=True,
),
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.SENSOR),
),
vol.Optional(CONF_STATE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
Expand Down Expand Up @@ -397,13 +356,8 @@ def generate_schema(domain: str, flow_type: str) -> vol.Schema:
}
if flow_type == "config":
schema |= {
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[cls.value for cls in UpdateDeviceClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="update_device_class",
sort=True,
),
vol.Optional(CONF_DEVICE_CLASS): selector.DeviceClassSelector(
selector.DeviceClassSelectorConfig(domain=Platform.UPDATE),
),
}

Expand Down
Loading
Loading