mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
[lvgl] Add paused option to suppress updates on boot (#16973)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
@@ -414,6 +414,8 @@ async def to_code(configs):
|
||||
await cg.register_component(lv_component, config)
|
||||
if rotation := config.get(CONF_ROTATION):
|
||||
cg.add(lv_component.set_rotation(rotation))
|
||||
if paused := config[df.CONF_PAUSED]:
|
||||
cg.add(lv_component.set_paused(paused, False))
|
||||
if refr_time := config.get(df.CONF_REFRESH_INTERVAL):
|
||||
cg.add(lv_component.set_refresh_interval(refr_time.total_milliseconds))
|
||||
Widget.create(config[CONF_ID], lv_component, LvScrActType(), config)
|
||||
@@ -645,6 +647,7 @@ LVGL_TOP_LEVEL_SCHEMA = (
|
||||
cv.Optional(df.CONF_KEYPADS, default=None): KEYPADS_CONFIG,
|
||||
cv.GenerateID(df.CONF_DEFAULT_GROUP): cv.declare_id(lv_group_t),
|
||||
cv.Optional(df.CONF_RESUME_ON_INPUT, default=True): cv.boolean,
|
||||
cv.Optional(df.CONF_PAUSED, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(DISP_BG_SCHEMA)
|
||||
|
||||
@@ -758,6 +758,7 @@ CONF_PAD_COLUMN = "pad_column"
|
||||
CONF_PAGE = "page"
|
||||
CONF_PAGE_WRAP = "page_wrap"
|
||||
CONF_PASSWORD_MODE = "password_mode"
|
||||
CONF_PAUSED = "paused"
|
||||
CONF_PIVOT_X = "pivot_x"
|
||||
CONF_PIVOT_Y = "pivot_y"
|
||||
CONF_PLACEHOLDER_TEXT = "placeholder_text"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
esphome:
|
||||
name: test-not-paused
|
||||
|
||||
esp32:
|
||||
board: lolin_c3_mini
|
||||
|
||||
spi:
|
||||
mosi_pin:
|
||||
number: GPIO2
|
||||
ignore_strapping_warning: true
|
||||
clk_pin: GPIO1
|
||||
|
||||
display:
|
||||
- platform: mipi_spi
|
||||
data_rate: 20MHz
|
||||
model: st7735
|
||||
cs_pin:
|
||||
number: GPIO8
|
||||
ignore_strapping_warning: true
|
||||
dc_pin:
|
||||
number: GPIO3
|
||||
|
||||
lvgl:
|
||||
widgets:
|
||||
- obj:
|
||||
id: root_obj
|
||||
@@ -0,0 +1,27 @@
|
||||
esphome:
|
||||
name: test-paused
|
||||
|
||||
esp32:
|
||||
board: lolin_c3_mini
|
||||
|
||||
spi:
|
||||
mosi_pin:
|
||||
number: GPIO2
|
||||
ignore_strapping_warning: true
|
||||
clk_pin: GPIO1
|
||||
|
||||
display:
|
||||
- platform: mipi_spi
|
||||
data_rate: 20MHz
|
||||
model: st7735
|
||||
cs_pin:
|
||||
number: GPIO8
|
||||
ignore_strapping_warning: true
|
||||
dc_pin:
|
||||
number: GPIO3
|
||||
|
||||
lvgl:
|
||||
paused: true
|
||||
widgets:
|
||||
- obj:
|
||||
id: root_obj
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Tests for the LVGL ``paused`` option code generation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
_SET_PAUSED_RE = re.compile(r"->set_paused\((.+?)\);")
|
||||
|
||||
|
||||
def _extract_set_paused(main_cpp: str) -> list[str]:
|
||||
"""Return the normalised argument text of every set_paused() call found.
|
||||
|
||||
Whitespace within and around the arguments is collapsed so unrelated
|
||||
code-generation formatting changes don't break these tests.
|
||||
"""
|
||||
return [" ".join(m.group(1).split()) for m in _SET_PAUSED_RE.finditer(main_cpp)]
|
||||
|
||||
|
||||
class TestPausedCodeGeneration:
|
||||
"""Verify that the ``paused`` option drives the set_paused() call."""
|
||||
|
||||
def test_paused_true_generates_set_paused(
|
||||
self, generate_main, component_config_path
|
||||
):
|
||||
"""``paused: true`` emits a set_paused(true, false) call."""
|
||||
main_cpp = generate_main(component_config_path("paused.yaml"))
|
||||
calls = _extract_set_paused(main_cpp)
|
||||
assert calls == ["true, false"]
|
||||
|
||||
def test_paused_default_omits_set_paused(
|
||||
self, generate_main, component_config_path
|
||||
):
|
||||
"""Without ``paused`` (default false) no set_paused call is generated."""
|
||||
main_cpp = generate_main(component_config_path("not_paused.yaml"))
|
||||
assert _extract_set_paused(main_cpp) == []
|
||||
@@ -35,6 +35,7 @@ lvgl:
|
||||
rotation: 90
|
||||
log_level: debug
|
||||
resume_on_input: true
|
||||
paused: true
|
||||
update_when_display_idle: true
|
||||
refresh_interval: 30ms
|
||||
on_pause:
|
||||
|
||||
Reference in New Issue
Block a user