mirror of
https://github.com/esphome/esphome.git
synced 2025-01-05 20:31:44 +01:00
bytes mandatory for schedule plans
This commit is contained in:
parent
814ae8be8d
commit
0b3a87f471
1 changed files with 42 additions and 21 deletions
|
@ -41,20 +41,21 @@ OptolinkTextSensor = optolink_ns.class_(
|
||||||
|
|
||||||
def check_address():
|
def check_address():
|
||||||
def validator_(config):
|
def validator_(config):
|
||||||
address_needed = config[CONF_MODE] in [
|
modes_address_needed = [
|
||||||
"MAP",
|
"MAP",
|
||||||
"RAW",
|
"RAW",
|
||||||
"DAY_SCHEDULE",
|
"DAY_SCHEDULE",
|
||||||
"DAY_SCHEDULE_SYNCHRONIZED",
|
"DAY_SCHEDULE_SYNCHRONIZED",
|
||||||
]
|
]
|
||||||
|
address_needed = config[CONF_MODE] in modes_address_needed
|
||||||
address_defined = CONF_ADDRESS in config
|
address_defined = CONF_ADDRESS in config
|
||||||
if address_needed and not address_defined:
|
if address_needed and not address_defined:
|
||||||
raise cv.Invalid(
|
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:
|
if not address_needed and address_defined:
|
||||||
raise cv.Invalid(
|
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
|
return config
|
||||||
|
|
||||||
|
@ -63,12 +64,34 @@ def check_address():
|
||||||
|
|
||||||
def check_bytes():
|
def check_bytes():
|
||||||
def validator_(config):
|
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
|
bytes_defined = CONF_BYTES in config
|
||||||
if bytes_needed and not bytes_defined:
|
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:
|
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 config
|
||||||
|
|
||||||
return validator_
|
return validator_
|
||||||
|
@ -76,17 +99,14 @@ def check_bytes():
|
||||||
|
|
||||||
def check_dow():
|
def check_dow():
|
||||||
def validator_(config):
|
def validator_(config):
|
||||||
if (
|
modes_dow_needed = ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||||
config[CONF_MODE] in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
if config[CONF_MODE] in modes_dow_needed and CONF_DAY_OF_WEEK not in config:
|
||||||
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
|
|
||||||
):
|
|
||||||
raise cv.Invalid(
|
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
|
return config
|
||||||
|
|
||||||
|
@ -95,19 +115,20 @@ def check_dow():
|
||||||
|
|
||||||
def check_entity_id():
|
def check_entity_id():
|
||||||
def validator_(config):
|
def validator_(config):
|
||||||
|
modes_entitiy_id_needed = ["DAY_SCHEDULE_SYNCHRONIZED"]
|
||||||
if (
|
if (
|
||||||
config[CONF_MODE] in ["DAY_SCHEDULE_SYNCHRONIZED"]
|
config[CONF_MODE] in modes_entitiy_id_needed
|
||||||
and CONF_ENTITY_ID not in config
|
and CONF_ENTITY_ID not in config
|
||||||
):
|
):
|
||||||
raise cv.Invalid(
|
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 (
|
if (
|
||||||
config[CONF_MODE] not in ["DAY_SCHEDULE_SYNCHRONIZED"]
|
config[CONF_MODE] not in modes_entitiy_id_needed
|
||||||
and CONF_ENTITY_ID in config
|
and CONF_ENTITY_ID in config
|
||||||
):
|
):
|
||||||
raise cv.Invalid(
|
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
|
return config
|
||||||
|
|
||||||
|
@ -120,7 +141,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.GenerateID(): cv.declare_id(OptolinkTextSensor),
|
cv.GenerateID(): cv.declare_id(OptolinkTextSensor),
|
||||||
cv.Required(CONF_MODE): cv.enum(MODE, upper=True),
|
cv.Required(CONF_MODE): cv.enum(MODE, upper=True),
|
||||||
cv.Optional(CONF_ADDRESS): cv.hex_uint32_t,
|
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_DAY_OF_WEEK): cv.enum(DAY_OF_WEEK, upper=True),
|
||||||
cv.Optional(CONF_ENTITY_ID): cv.entity_id,
|
cv.Optional(CONF_ENTITY_ID): cv.entity_id,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue