Home Assistant Unofficial Reference
2024.12.1
config_validation.py
Go to the documentation of this file.
1
"""Config validation for the Z-Wave JS integration."""
2
3
from
typing
import
Any
4
5
import
voluptuous
as
vol
6
7
import
homeassistant.helpers.config_validation
as
cv
8
9
# Validates that a bitmask is provided in hex form and converts it to decimal
10
# int equivalent since that's what the library uses
11
BITMASK_SCHEMA = vol.All(
12
cv.string,
13
vol.Lower,
14
vol.Match(
15
r"^(0x)?[0-9a-f]+$"
,
16
msg=
"Must provide an integer (e.g. 255) or a bitmask in hex form (e.g. 0xff)"
,
17
),
18
lambda
value:
int
(value, 16),
19
)
20
21
22
def
boolean
(value: Any) -> bool:
23
"""Validate and coerce a boolean value."""
24
if
isinstance(value, bool):
25
return
value
26
if
isinstance(value, str):
27
value = value.lower().strip()
28
if
value
in
(
"true"
,
"yes"
,
"on"
,
"enable"
):
29
return
True
30
if
value
in
(
"false"
,
"no"
,
"off"
,
"disable"
):
31
return
False
32
raise
vol.Invalid(f
"invalid boolean value {value}"
)
33
34
35
VALUE_SCHEMA = vol.Any(
36
boolean,
37
float,
38
int,
39
vol.Coerce(int),
40
vol.Coerce(float),
41
BITMASK_SCHEMA,
42
cv.string,
43
dict,
44
)
homeassistant.components.apcupsd.const.int
int
Definition:
const.py:6
homeassistant.components.zwave_js.config_validation.boolean
bool boolean(Any value)
Definition:
config_validation.py:22
homeassistant.helpers.config_validation
Definition:
config_validation.py:1
core
homeassistant
components
zwave_js
config_validation.py
Generated by
1.9.1