mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 13:43:00 +00:00
[lvgl] Fix indicator updates (#16780)
This commit is contained in:
@@ -290,6 +290,7 @@ class Widget:
|
|||||||
# Properties for linear equations
|
# Properties for linear equations
|
||||||
self.slope = None
|
self.slope = None
|
||||||
self.y_int = None
|
self.y_int = None
|
||||||
|
self.parent = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(name, var, wtype: WidgetType, config: dict = None):
|
def create(name, var, wtype: WidgetType, config: dict = None):
|
||||||
|
|||||||
@@ -430,7 +430,8 @@ class MeterType(WidgetType):
|
|||||||
tvar, LV_PART.MAIN, await arc_style.get_var()
|
tvar, LV_PART.MAIN, await arc_style.get_var()
|
||||||
)
|
)
|
||||||
lw = Widget.create(iid, tvar, arc_indicator_type)
|
lw = Widget.create(iid, tvar, arc_indicator_type)
|
||||||
await set_indicator_values(lw, v)
|
lw.parent = scale_var
|
||||||
|
await set_indicator_values(scale_var, lw, v)
|
||||||
|
|
||||||
if t == CONF_TICK_STYLE:
|
if t == CONF_TICK_STYLE:
|
||||||
# No object created for this
|
# No object created for this
|
||||||
@@ -482,7 +483,8 @@ class MeterType(WidgetType):
|
|||||||
if option in v:
|
if option in v:
|
||||||
props["line_" + option] = v[option]
|
props["line_" + option] = v[option]
|
||||||
lw = await widget_to_code(props, line_indicator_type, scale_var)
|
lw = await widget_to_code(props, line_indicator_type, scale_var)
|
||||||
await set_indicator_values(lw, v)
|
lw.parent = scale_var
|
||||||
|
await set_indicator_values(scale_var, lw, v)
|
||||||
|
|
||||||
if t == CONF_IMAGE:
|
if t == CONF_IMAGE:
|
||||||
add_lv_use(CONF_IMAGE)
|
add_lv_use(CONF_IMAGE)
|
||||||
@@ -501,7 +503,8 @@ class MeterType(WidgetType):
|
|||||||
}
|
}
|
||||||
iw = await widget_to_code(props, image_indicator_type, scale_var)
|
iw = await widget_to_code(props, image_indicator_type, scale_var)
|
||||||
await iw.set_property(CONF_SRC, await lv_image.process(src))
|
await iw.set_property(CONF_SRC, await lv_image.process(src))
|
||||||
await set_indicator_values(iw, v)
|
iw.parent = scale_var
|
||||||
|
await set_indicator_values(scale_var, iw, v)
|
||||||
|
|
||||||
# Hide the scale line
|
# Hide the scale line
|
||||||
lv.obj_set_style_arc_opa(scale_var, LV_OPA.TRANSP, LV_PART.MAIN)
|
lv.obj_set_style_arc_opa(scale_var, LV_OPA.TRANSP, LV_PART.MAIN)
|
||||||
@@ -607,27 +610,27 @@ async def indicator_update_to_code(config, action_id, template_arg, args):
|
|||||||
widget = await get_widgets(config)
|
widget = await get_widgets(config)
|
||||||
|
|
||||||
async def set_value(w: Widget):
|
async def set_value(w: Widget):
|
||||||
await set_indicator_values(w, config)
|
await set_indicator_values(w.parent, w, config)
|
||||||
|
|
||||||
return await action_to_code(
|
return await action_to_code(
|
||||||
widget, set_value, action_id, template_arg, args, config
|
widget, set_value, action_id, template_arg, args, config
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def set_indicator_values(indicator: Widget, config):
|
async def set_indicator_values(scale: MockObj, indicator: Widget, config):
|
||||||
"""Update scale section values (replaces meter indicator values)"""
|
"""Update scale section values (replaces meter indicator values)"""
|
||||||
start_value = await get_start_value(config)
|
start_value = await get_start_value(config)
|
||||||
end_value = await get_end_value(config)
|
end_value = await get_end_value(config)
|
||||||
if indicator.type is arc_indicator_type:
|
if indicator.type is arc_indicator_type:
|
||||||
# For scale sections, we update the range
|
# For scale sections, we update the range
|
||||||
if start_value is not None and end_value is not None:
|
if start_value is not None and end_value is not None:
|
||||||
lv.scale_section_set_range(indicator.obj, start_value, end_value)
|
lv.scale_set_section_range(scale, indicator.obj, start_value, end_value)
|
||||||
elif start_value is not None:
|
elif start_value is not None:
|
||||||
# If only start value, use it as both start and end (single point)
|
# If only start value, use it as both start and end (single point)
|
||||||
lv.scale_section_set_range(indicator.obj, start_value, start_value)
|
lv.scale_set_section_range(scale, indicator.obj, start_value, start_value)
|
||||||
elif end_value is not None:
|
elif end_value is not None:
|
||||||
# If only end value, assume range from 0 to end_value
|
# If only end value, assume range from 0 to end_value
|
||||||
lv.scale_section_set_range(indicator.obj, 0, end_value)
|
lv.scale_set_section_range(scale, indicator.obj, 0, end_value)
|
||||||
return
|
return
|
||||||
|
|
||||||
if start_value is None:
|
if start_value is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user