Show an alert from a Home Assistant automation (0.2.36)

Every screen gets the user action esphome.<device>_show_alert with title,
subtitle, icon, color, button_text, timeout and flash. The card sits on
LVGL's top layer above every page, card and the dim overlay, wakes the
screen and keeps the backlight at its normal brightness until the button
(or the timeout; 0 waits for the button, the button always closes at
once). flash: true blinks the backlight four times on arrival. Icons are
the tile picker names (also mdi:name or the hex codepoint of a compiled
glyph, else alert-outline), colours the tile pastels. A new alert replaces
the current one; every ending fires esphome.screen_alert with action,
title and screen. dismiss_alert removes the card remotely.

The field is button_text rather than button: ESPHome reserves the names
of loaded components as ids and the CYD profile loads button:. The C++
namespace is screen_alert because the widget id alert_overlay becomes a
global lv_obj_t*.

tools/generate_icons.py now also writes tile_icon_names.h (name to
codepoint) from the one icon list. Firmware 0.2.31 for both boards.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Max Gramser
2026-09-14 14:39:03 +02:00
parent 61ceb40075
commit e37148f9b1
17 changed files with 1638 additions and 11 deletions
+27
View File
@@ -23,6 +23,7 @@ import tile_icons # noqa: E402
TTF = ROOT / 'fonts/materialdesignicons-webfont.ttf'
PROFILES = [ROOT / 'home-like-2432s028.yaml', ROOT / 'guition-4848s040.yaml']
WEB_FONT = ROOT / 'screen_manager/app/static/tile-icons.woff'
NAME_TABLE = ROOT / 'components/smart_display/tile_icon_names.h'
FONT_BLOCK = re.compile(r"( - file: 'fonts/materialdesignicons-webfont\.ttf'\n id: \w+\n size: \d+\n) glyphs:.*\n(?: .*\n)*")
def verify():
@@ -56,6 +57,30 @@ def profile(text):
last = block.end()
return ''.join(out) + text[last:]
def name_table():
"""Name -> codepoint for the firmware, so a Home Assistant action can say icon: doorbell."""
lines = ['#pragma once',
'// GENERATED by tools/generate_icons.py from screen_manager/app/tile_icons.py; do not edit.',
'#include <cstdint>', '#include <string>', '', 'namespace tile_icon {',
'struct Named { const char *name; uint32_t codepoint; };',
'// Every glyph the three icon fonts of both boards carry, by Material Design Icons name.',
'inline constexpr Named NAMES[] = {']
lines += [f' {{"{name}", 0x{code}}},' for name, code in tile_icons.GLYPHS.items()]
lines += ['};',
'inline constexpr size_t NAME_COUNT = sizeof(NAMES) / sizeof(NAMES[0]);',
'// Codepoint of a name the fonts carry; 0 for any other name.',
'inline uint32_t named(const std::string &name) {',
' for (const auto &entry : NAMES) if (name == entry.name) return entry.codepoint;',
' return 0;',
'}',
'// True when the fonts carry this codepoint, so a label can draw it.',
'inline bool carried(uint32_t codepoint) {',
' for (const auto &entry : NAMES) if (entry.codepoint == codepoint) return true;',
' return false;',
'}',
'} // namespace tile_icon']
return '\n'.join(lines) + '\n'
def web_font():
font = TTFont(TTF)
options = subset.Options()
@@ -90,11 +115,13 @@ def main():
else:
path.write_text(expected)
if args.check:
if not NAME_TABLE.exists() or NAME_TABLE.read_text() != name_table(): raise SystemExit(f'Outdated: {NAME_TABLE.name}')
# Compare glyph coverage, not bytes: font output differs between fontTools versions.
wanted = {int(code, 16) for code in tile_icons.GLYPHS.values()}
if not WEB_FONT.exists() or set(TTFont(WEB_FONT).getBestCmap()) != wanted:
raise SystemExit(f'Outdated: {WEB_FONT.name}')
else:
NAME_TABLE.write_text(name_table())
WEB_FONT.write_bytes(web_font())
print(f'{len(tile_icons.ICONS)} pickable icons, {len(tile_icons.GLYPHS)} glyphs: ' + ('verified' if args.check else 'generated'))
+1 -1
View File
@@ -21,7 +21,7 @@ def generate(board):
s = re.sub(r'^ota:\n.*?(?=^\w)', '', s, flags=re.M | re.S)
s = re.sub(r'^wifi:\n.*?(?=^\w)', '', s, flags=re.M | re.S)
# Referenced files are fetched as an external component or over HTTPS.
s = re.sub(r'^ - (cyd_ui.h|light_controls.h|guition_diagnostics.h|backlight_fade.h)$', r' - <esphome/components/smart_display/\1>', s, flags=re.M)
s = re.sub(r'^ - (cyd_ui.h|light_controls.h|guition_diagnostics.h|backlight_fade.h|alert_overlay.h)$', r' - <esphome/components/smart_display/\1>', s, flags=re.M)
components = '[xpt2046, smart_display]' if board == 'cyd' else '[smart_display]'
external = f'''external_components:
- source: