22// HARDWARE SECTION GENERATORS
33// ============================================================================
44
5- function generateTouchscreenSection ( profile ) {
5+ function generateTouchscreenSection ( profile , displayId = "my_display" ) {
66 if ( ! profile . touch ) return [ ] ; // E-paper usually has no touch or handled differently
77
88 const t = profile . touch ;
99 const lines = [ "touchscreen:" ] ;
1010 lines . push ( ` - platform: ${ t . platform } ` ) ;
1111 lines . push ( ` id: my_touchscreen` ) ;
12- lines . push ( ` display: my_display ` ) ; // Assumes display ID is my_display (LCDs)
12+ lines . push ( ` display: ${ displayId } ` ) ;
1313
1414 if ( t . i2c_id ) lines . push ( ` i2c_id: ${ t . i2c_id } ` ) ;
1515 if ( t . spi_id ) lines . push ( ` spi_id: ${ t . spi_id } ` ) ;
@@ -191,6 +191,7 @@ function generateSPISection(profile) {
191191function generateDisplaySection ( profile ) {
192192 const lines = [ ] ;
193193
194+
194195 // Display Platform Configuration
195196 if ( profile . display_config ) {
196197 lines . push ( "display:" ) ;
@@ -219,7 +220,19 @@ function generateDisplaySection(profile) {
219220 addPin ( "reset_pin" , p . reset ) ;
220221 addPin ( "busy_pin" , p . busy ) ;
221222
222- if ( profile . displayModel ) lines . push ( ` model: "${ profile . displayModel } "` ) ;
223+ if ( profile . displayModel === "M5Paper" || profile . displayPlatform === "it8951e" ) {
224+ lines . push ( " rotation: 0" ) ;
225+ lines . push ( " reversed: false" ) ;
226+ lines . push ( " reset_duration: 100ms" ) ;
227+ }
228+ else if ( profile . displayModel ) {
229+ let modelLine = ` model: "${ profile . displayModel } "` ;
230+ // Add warning for E1002 consumers using older ESPHome versions
231+ if ( profile . displayModel === "Seeed-reTerminal-E1002" ) {
232+ modelLine += " #Please update your ESPHome version to 2025.11.1 above" ;
233+ }
234+ lines . push ( modelLine ) ;
235+ }
223236
224237 lines . push ( " update_interval: never" ) ;
225238
@@ -245,7 +258,9 @@ function generateDisplaySection(profile) {
245258 }
246259
247260 // Add Touchscreen if present
248- lines . push ( ...generateTouchscreenSection ( profile ) ) ;
261+ // Fallback generation (e-paper) uses epaper_display, custom/LCD likely uses my_display
262+ const linkedDisplayId = profile . display_config ? "my_display" : "epaper_display" ;
263+ lines . push ( ...generateTouchscreenSection ( profile , linkedDisplayId ) ) ;
249264
250265 // Note: Backlight section is generated in yaml_export.js, not here (to avoid duplicates)
251266
@@ -341,9 +356,15 @@ function generateBinarySensorSection(profile, numPages, displayId = "my_display"
341356 if ( b . left ) {
342357 lines . push ( " - platform: gpio" ) ; // Left Button
343358 lines . push ( ` pin:` ) ;
344- lines . push ( ` number: ${ b . left } ` ) ;
345- lines . push ( ` mode: INPUT_PULLUP` ) ;
346- lines . push ( ` inverted: true` ) ;
359+ if ( typeof b . left === 'object' ) {
360+ lines . push ( ` number: ${ b . left . number } ` ) ;
361+ lines . push ( ` mode: ${ b . left . mode || 'INPUT_PULLUP' } ` ) ;
362+ lines . push ( ` inverted: ${ b . left . inverted !== undefined ? b . left . inverted : true } ` ) ;
363+ } else {
364+ lines . push ( ` number: ${ b . left } ` ) ;
365+ lines . push ( ` mode: INPUT_PULLUP` ) ;
366+ lines . push ( ` inverted: true` ) ;
367+ }
347368 lines . push ( " name: \"Left Button\"" ) ;
348369 lines . push ( " id: button_left" ) ;
349370 lines . push ( " on_press:" ) ;
@@ -362,9 +383,15 @@ function generateBinarySensorSection(profile, numPages, displayId = "my_display"
362383 if ( b . right ) {
363384 lines . push ( " - platform: gpio" ) ; // Right Button
364385 lines . push ( ` pin:` ) ;
365- lines . push ( ` number: ${ b . right } ` ) ;
366- lines . push ( ` mode: INPUT_PULLUP` ) ;
367- lines . push ( ` inverted: true` ) ;
386+ if ( typeof b . right === 'object' ) {
387+ lines . push ( ` number: ${ b . right . number } ` ) ;
388+ lines . push ( ` mode: ${ b . right . mode || 'INPUT_PULLUP' } ` ) ;
389+ lines . push ( ` inverted: ${ b . right . inverted !== undefined ? b . right . inverted : true } ` ) ;
390+ } else {
391+ lines . push ( ` number: ${ b . right } ` ) ;
392+ lines . push ( ` mode: INPUT_PULLUP` ) ;
393+ lines . push ( ` inverted: true` ) ;
394+ }
368395 lines . push ( " name: \"Right Button\"" ) ;
369396 lines . push ( " id: button_right" ) ;
370397 lines . push ( " on_press:" ) ;
@@ -383,9 +410,15 @@ function generateBinarySensorSection(profile, numPages, displayId = "my_display"
383410 if ( b . refresh ) {
384411 lines . push ( " - platform: gpio" ) ; // Refresh Button
385412 lines . push ( ` pin:` ) ;
386- lines . push ( ` number: ${ b . refresh } ` ) ;
387- lines . push ( ` mode: INPUT_PULLUP` ) ;
388- lines . push ( ` inverted: true` ) ;
413+ if ( typeof b . refresh === 'object' ) {
414+ lines . push ( ` number: ${ b . refresh . number } ` ) ;
415+ lines . push ( ` mode: ${ b . refresh . mode || 'INPUT_PULLUP' } ` ) ;
416+ lines . push ( ` inverted: ${ b . refresh . inverted !== undefined ? b . refresh . inverted : true } ` ) ;
417+ } else {
418+ lines . push ( ` number: ${ b . refresh } ` ) ;
419+ lines . push ( ` mode: INPUT_PULLUP` ) ;
420+ lines . push ( ` inverted: true` ) ;
421+ }
389422 lines . push ( " name: \"Refresh Button\"" ) ;
390423 lines . push ( " id: button_refresh" ) ;
391424 lines . push ( " on_press:" ) ;
@@ -555,7 +588,18 @@ function generateOutputSection(profile) {
555588 lines . push ( "output:" ) ;
556589 if ( profile . pins . batteryEnable ) {
557590 lines . push ( " - platform: gpio" ) ; // Use standard gpio output
558- lines . push ( ` pin: ${ profile . pins . batteryEnable } ` ) ;
591+ if ( typeof profile . pins . batteryEnable === 'object' ) {
592+ lines . push ( " pin:" ) ;
593+ lines . push ( ` number: ${ profile . pins . batteryEnable . number } ` ) ;
594+ if ( profile . pins . batteryEnable . ignore_strapping_warning ) {
595+ lines . push ( " ignore_strapping_warning: true" ) ;
596+ }
597+ if ( profile . pins . batteryEnable . inverted !== undefined ) {
598+ lines . push ( ` inverted: ${ profile . pins . batteryEnable . inverted } ` ) ;
599+ }
600+ } else {
601+ lines . push ( ` pin: ${ profile . pins . batteryEnable } ` ) ;
602+ }
559603 lines . push ( " id: bsp_battery_enable" ) ;
560604 // Often good to set restore_mode or inverted if needed
561605 // For now matching legacy exactly
0 commit comments