MaidsiteDesk: Added CONF_NUMBERS

This commit is contained in:
ElVit 2025-02-04 15:21:04 +01:00
parent 9e8ae57d33
commit b002b33a38
2 changed files with 14 additions and 16 deletions

View File

@ -47,19 +47,12 @@ namespace esphome
void MaidsiteDeskComponent::setup()
{
ESP_LOGCONFIG(TAG, "Setting up maidsite Desk ...");
ESP_LOGCONFIG(TAG, "Setting up Maidsite Desk ...");
delay(10);
height_abs_number_->traits.set_min_value(0);
height_abs_number_->traits.set_max_value(120);
height_abs_number_->traits.set_step(.2);
height_pct_number_->traits.set_min_value(0);
height_pct_number_->traits.set_max_value(120);
height_pct_number_->traits.set_step(.1);
request_physical_limits();
request_limits();
request_settings();
this->check_uart_settings(9600);
this->request_physical_limits();
this->request_limits();
this->request_settings();
}
void MaidsiteDeskComponent::loop()

View File

@ -16,6 +16,11 @@ TYPES = [
CONF_HEIGHT_PCT,
]
CONF_NUMBERS = [
[ 0, 120, .2, ],
[ 0, 100, .1, ],
]
MaidsiteDeskNumber = maidsite_desk_ns.class_("MaidsiteDeskNumber", number.Number)
CONFIG_SCHEMA = cv.Schema(
@ -35,11 +40,11 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config):
hub = await cg.get_variable(config[CONF_MAIDSITE_DESK_ID])
for key in TYPES:
await setup_conf(config, key, hub)
for index, key in enumerate(TYPES):
await setup_conf(config, key, index, hub)
async def setup_conf(parent_config, key, hub):
async def setup_conf(parent_config, key, index, hub):
if child_config := parent_config.get(key):
var = await number.new_number(child_config, min_value=0, max_value=100, step=.1)
var = await number.new_number(child_config, min_value=CONF_NUMBERS[index][0], max_value=CONF_NUMBERS[index][1], step=CONF_NUMBERS[index][2])
await cg.register_parented(var, parent_config[CONF_MAIDSITE_DESK_ID])
cg.add(getattr(hub, f"set_{key}_number")(var))