Skip to content

Commit fba6498

Browse files
Validation
1 parent b2ef492 commit fba6498

2 files changed

Lines changed: 11 additions & 22 deletions

File tree

custom_components/label_state/config_flow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from homeassistant.helpers.schema_config_entry_flow import (
1212
SchemaCommonFlowHandler,
1313
SchemaConfigFlowHandler,
14+
SchemaFlowError,
1415
SchemaFlowFormStep,
1516
SchemaFlowMenuStep,
1617
)
@@ -85,7 +86,7 @@ def _validate_upper_or_lower(options: dict[str, Any]) -> None:
8586
lower_limit = options.get(CONF_LOWER_LIMIT)
8687

8788
if upper_limit is None and lower_limit is None:
88-
raise vol.Invalid("An upper or lower limit must be set")
89+
raise SchemaFlowError("upper_or_lower_not_specified")
8990

9091

9192
def _validate_from_or_to(options: dict[str, Any]) -> None:
@@ -94,7 +95,7 @@ def _validate_from_or_to(options: dict[str, Any]) -> None:
9495
state_to = options.get(CONF_STATE_TO)
9596

9697
if state_from is None and state_to is None:
97-
raise vol.Invalid("A from or to must be specified")
98+
raise SchemaFlowError("from_or_to_not_specified")
9899

99100

100101
def validate_user_input(

custom_components/label_state/translations/en.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"config": {
3+
"error": {
4+
"from_or_to_not_specified": "A from or to must be specified.",
5+
"upper_or_lower_not_specified": "An upper or lower limit must be set."
6+
},
37
"step": {
48
"user": {
59
"title": "Label State",
@@ -36,6 +40,10 @@
3640
}
3741
},
3842
"options": {
43+
"error": {
44+
"from_or_to_not_specified": "A from or to must be specified.",
45+
"upper_or_lower_not_specified": "An upper or lower limit must be set."
46+
},
3947
"step": {
4048
"numeric_state": {
4149
"title": "Label State",
@@ -60,25 +68,5 @@
6068
}
6169
}
6270
}
63-
},
64-
"selector": {
65-
"type": {
66-
"options": {
67-
"min": "Minimum",
68-
"max": "Maximum"
69-
}
70-
}
71-
},
72-
"services": {
73-
"reset": {
74-
"name": "Reset",
75-
"description": "Reset a Label State sensor to the current input entity value.",
76-
"fields": {
77-
"entity_id": {
78-
"name": "Entity",
79-
"description": "Select the Label State sensor."
80-
}
81-
}
82-
}
8371
}
8472
}

0 commit comments

Comments
 (0)