2023-06-07 23:10:02 +00:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import number
|
2023-06-09 20:54:28 +00:00
|
|
|
from esphome.const import CONF_ID
|
|
|
|
|
|
|
|
from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child
|
2023-06-07 23:10:02 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ["ratgdo"]
|
|
|
|
|
2023-06-07 23:49:13 +00:00
|
|
|
RATGDONumber = ratgdo_ns.class_("RATGDONumber", number.Number, cg.Component)
|
2023-06-07 23:10:02 +00:00
|
|
|
NumberType = ratgdo_ns.enum("NumberType")
|
|
|
|
|
|
|
|
CONF_TYPE = "type"
|
|
|
|
TYPES = {
|
2023-10-26 17:04:35 +00:00
|
|
|
"client_id": NumberType.RATGDO_CLIENT_ID,
|
2023-06-07 23:10:02 +00:00
|
|
|
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
|
2023-06-25 23:03:39 +00:00
|
|
|
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
|
|
|
|
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
|
2023-06-07 23:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-07 23:49:13 +00:00
|
|
|
CONFIG_SCHEMA = (
|
|
|
|
number.number_schema(RATGDONumber)
|
|
|
|
.extend(
|
|
|
|
{
|
|
|
|
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.extend(RATGDO_CLIENT_SCHMEA)
|
|
|
|
)
|
2023-06-07 23:10:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def to_code(config):
|
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2023-06-07 23:13:02 +00:00
|
|
|
await number.register_number(var, config, step=1, min_value=0, max_value=4294967295)
|
2023-06-07 23:10:02 +00:00
|
|
|
await cg.register_component(var, config)
|
|
|
|
cg.add(var.set_number_type(config[CONF_TYPE]))
|
|
|
|
await register_ratgdo_child(var, config)
|