mirror of
https://github.com/esphome/esphome.git
synced 2024-12-05 13:54:09 +01:00
bytes mandatory for schedule plans
This commit is contained in:
parent
814ae8be8d
commit
0b3a87f471
@ -41,20 +41,21 @@ OptolinkTextSensor = optolink_ns.class_(
|
||||
|
||||
def check_address():
|
||||
def validator_(config):
|
||||
address_needed = config[CONF_MODE] in [
|
||||
modes_address_needed = [
|
||||
"MAP",
|
||||
"RAW",
|
||||
"DAY_SCHEDULE",
|
||||
"DAY_SCHEDULE_SYNCHRONIZED",
|
||||
]
|
||||
address_needed = config[CONF_MODE] in modes_address_needed
|
||||
address_defined = CONF_ADDRESS in config
|
||||
if address_needed and not address_defined:
|
||||
raise cv.Invalid(
|
||||
f"{CONF_ADDRESS} is required in mode MAP, RAW, DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_ADDRESS} is required in this modes: {modes_address_needed}"
|
||||
)
|
||||
if not address_needed and address_defined:
|
||||
raise cv.Invalid(
|
||||
f"{CONF_ADDRESS} is only allowed in mode MAP, RAW, DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_ADDRESS} is only allowed in this modes mode: {modes_address_needed}"
|
||||
)
|
||||
return config
|
||||
|
||||
@ -63,12 +64,34 @@ def check_address():
|
||||
|
||||
def check_bytes():
|
||||
def validator_(config):
|
||||
bytes_needed = config[CONF_MODE] in ["MAP", "RAW"]
|
||||
modes_bytes_needed = ["MAP", "RAW", "DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
bytes_needed = config[CONF_MODE] in modes_bytes_needed
|
||||
bytes_defined = CONF_BYTES in config
|
||||
if bytes_needed and not bytes_defined:
|
||||
raise cv.Invalid(f"{CONF_BYTES} is required in mode MAP or RAW")
|
||||
raise cv.Invalid(
|
||||
f"{CONF_BYTES} is required in this modes: {modes_bytes_needed}"
|
||||
)
|
||||
if not bytes_needed and bytes_defined:
|
||||
raise cv.Invalid(f"{CONF_BYTES} is only allowed in mode MAP or RAW")
|
||||
raise cv.Invalid(
|
||||
f"{CONF_BYTES} is only allowed in this modes: {modes_bytes_needed}"
|
||||
)
|
||||
|
||||
modes_bytes_range_1_to_9 = ["MAP", "RAW"]
|
||||
if config[CONF_MODE] in modes_bytes_range_1_to_9 and config[
|
||||
CONF_BYTES
|
||||
] not in range(0, 10):
|
||||
raise cv.Invalid(
|
||||
f"{CONF_BYTES} must be between 1 and 9 for this modes: {modes_bytes_range_1_to_9}"
|
||||
)
|
||||
|
||||
modes_bytes_day_schedule = ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
if config[CONF_MODE] in modes_bytes_day_schedule and config[CONF_BYTES] not in [
|
||||
56
|
||||
]:
|
||||
raise cv.Invalid(
|
||||
f"{CONF_BYTES} must be 56 for this modes: {modes_bytes_day_schedule}"
|
||||
)
|
||||
|
||||
return config
|
||||
|
||||
return validator_
|
||||
@ -76,17 +99,14 @@ def check_bytes():
|
||||
|
||||
def check_dow():
|
||||
def validator_(config):
|
||||
if (
|
||||
config[CONF_MODE] in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
and CONF_DAY_OF_WEEK not in config
|
||||
):
|
||||
raise cv.Invalid(f"{CONF_DAY_OF_WEEK} is required in mode DAY_SCHEDULE")
|
||||
if (
|
||||
config[CONF_MODE] not in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
and CONF_DAY_OF_WEEK in config
|
||||
):
|
||||
modes_dow_needed = ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
if config[CONF_MODE] in modes_dow_needed and CONF_DAY_OF_WEEK not in config:
|
||||
raise cv.Invalid(
|
||||
f"{CONF_DAY_OF_WEEK} is only allowed in mode DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_DAY_OF_WEEK} is required in this modes: {modes_dow_needed}"
|
||||
)
|
||||
if config[CONF_MODE] not in modes_dow_needed and CONF_DAY_OF_WEEK in config:
|
||||
raise cv.Invalid(
|
||||
f"{CONF_DAY_OF_WEEK} is only allowed in this modes: {modes_dow_needed}"
|
||||
)
|
||||
return config
|
||||
|
||||
@ -95,19 +115,20 @@ def check_dow():
|
||||
|
||||
def check_entity_id():
|
||||
def validator_(config):
|
||||
modes_entitiy_id_needed = ["DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
if (
|
||||
config[CONF_MODE] in ["DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
config[CONF_MODE] in modes_entitiy_id_needed
|
||||
and CONF_ENTITY_ID not in config
|
||||
):
|
||||
raise cv.Invalid(
|
||||
f"{CONF_ENTITY_ID} is required in mode DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_ENTITY_ID} is required in this modes: {modes_entitiy_id_needed}"
|
||||
)
|
||||
if (
|
||||
config[CONF_MODE] not in ["DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
config[CONF_MODE] not in modes_entitiy_id_needed
|
||||
and CONF_ENTITY_ID in config
|
||||
):
|
||||
raise cv.Invalid(
|
||||
f"{CONF_ENTITY_ID} is only allowed in mode DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_ENTITY_ID} is only allowed in this modes: {modes_entitiy_id_needed}"
|
||||
)
|
||||
return config
|
||||
|
||||
@ -120,7 +141,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.GenerateID(): cv.declare_id(OptolinkTextSensor),
|
||||
cv.Required(CONF_MODE): cv.enum(MODE, upper=True),
|
||||
cv.Optional(CONF_ADDRESS): cv.hex_uint32_t,
|
||||
cv.Optional(CONF_BYTES): cv.int_range(min=1, max=9),
|
||||
cv.Optional(CONF_BYTES): cv.uint8_t,
|
||||
cv.Optional(CONF_DAY_OF_WEEK): cv.enum(DAY_OF_WEEK, upper=True),
|
||||
cv.Optional(CONF_ENTITY_ID): cv.entity_id,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user