1 """Support for config validation using voluptuous and Translate Trigger."""
3 from __future__
import annotations
10 import voluptuous
as vol
14 """Check rules for WiLight Trigger."""
16 err_desc =
"Value is None"
24 err_desc =
"Expected a string"
26 if (step == 2) & isinstance(value, str):
28 err_desc =
"String should only contain 8 decimals character"
29 if re.search(
r"^([0-9]{8})$", value)
is not None:
31 err_desc =
"First 3 character should be less than 128"
32 result_128 =
int(value[0:3]) < 128
33 result_24 =
int(value[3:5]) < 24
34 result_60 =
int(value[5:7]) < 60
35 result_2 =
int(value[7:8]) < 2
37 if (step == 4) & result_128:
39 err_desc =
"Hour part should be less than 24"
41 if (step == 5) & result_24:
43 err_desc =
"Minute part should be less than 60"
45 if (step == 6) & result_60:
47 err_desc =
"Active part should be less than 2"
49 if (step == 7) & result_2:
52 raise vol.Invalid(err_desc)
56 """Convert wilight trigger to hass description.
58 Ex: "12719001" -> "sun mon tue wed thu fri sat 19:00 On"
59 "00000000" -> "00:00 Off"
64 locale.setlocale(locale.LC_ALL,
"")
65 week_days =
list(calendar.day_abbr)
66 days = bin(
int(value[0:3]))[2:].zfill(8)
68 if int(days[7:8]) == 1:
69 desc += f
"{week_days[6]} "
70 if int(days[6:7]) == 1:
71 desc += f
"{week_days[0]} "
72 if int(days[5:6]) == 1:
73 desc += f
"{week_days[1]} "
74 if int(days[4:5]) == 1:
75 desc += f
"{week_days[2]} "
76 if int(days[3:4]) == 1:
77 desc += f
"{week_days[3]} "
78 if int(days[2:3]) == 1:
79 desc += f
"{week_days[4]} "
80 if int(days[1:2]) == 1:
81 desc += f
"{week_days[5]} "
82 desc += f
"{value[3:5]}:{value[5:7]} "
83 if int(value[7:8]) == 1:
str|None wilight_to_hass_trigger(str|None value)
str|None wilight_trigger(Any value)