1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-19 16:25:50 +00:00

[lvgl] Apply scale to spinbox value (#11946)

This commit is contained in:
Clyde Stubbs
2025-11-18 14:27:50 +10:00
committed by GitHub
parent a4242dee64
commit 11d0d4d128
2 changed files with 7 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
from esphome import automation from esphome import automation
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_RANGE_FROM, CONF_RANGE_TO, CONF_STEP, CONF_VALUE from esphome.const import CONF_ID, CONF_RANGE_FROM, CONF_RANGE_TO, CONF_STEP, CONF_VALUE
from esphome.cpp_generator import MockObj
from ..automation import action_to_code from ..automation import action_to_code
from ..defines import ( from ..defines import (
@@ -114,7 +115,9 @@ class SpinboxType(WidgetType):
w.obj, digits, digits - config[CONF_DECIMAL_PLACES] w.obj, digits, digits - config[CONF_DECIMAL_PLACES]
) )
if (value := config.get(CONF_VALUE)) is not None: if (value := config.get(CONF_VALUE)) is not None:
lv.spinbox_set_value(w.obj, await lv_float.process(value)) lv.spinbox_set_value(
w.obj, MockObj(await lv_float.process(value)) * w.get_scale()
)
def get_scale(self, config): def get_scale(self, config):
return 10 ** config[CONF_DECIMAL_PLACES] return 10 ** config[CONF_DECIMAL_PLACES]

View File

@@ -703,7 +703,9 @@ lvgl:
on_value: on_value:
- lvgl.spinbox.update: - lvgl.spinbox.update:
id: spinbox_id id: spinbox_id
value: !lambda return x; value: !lambda |-
static float yyy = 83.0;
return yyy + .8;
- button: - button:
styles: spin_button styles: spin_button
id: spin_up id: spin_up