|
1 | 1 | import esphome.codegen as cg |
2 | 2 | import esphome.config_validation as cv |
| 3 | +import esphome.final_validate as fv |
3 | 4 | from esphome.components import tigo_monitor, light, sensor, ble_client, esp32_ble_tracker |
4 | 5 | from esphome.const import CONF_ID, CONF_PORT |
5 | 6 | from pathlib import Path |
@@ -43,7 +44,39 @@ def _validate_cca_source(config): |
43 | 44 | return config |
44 | 45 |
|
45 | 46 |
|
| 47 | +def _require_psram(config): |
| 48 | + """Refuse to build the web server on a board with no PSRAM. |
| 49 | +
|
| 50 | + tigo_server builds whole HTML pages and JSON API responses in memory from |
| 51 | + the httpd task; PSRAMString and the psram_* containers assume 8MB of |
| 52 | + external RAM. Without a `psram:` block ESPHome never sets CONFIG_SPIRAM, so |
| 53 | + psram_malloc() resolves to the internal heap — the build succeeds, then |
| 54 | + fragments ~130KB of internal RAM to OOM under dashboard polling. That is a |
| 55 | + crash hours later on someone's roof, not a compile error, so catch it here. |
| 56 | +
|
| 57 | + tigo_monitor itself is unaffected and needs no PSRAM: its device and node |
| 58 | + tables are a few KB. A board without PSRAM runs a sensors-only build that |
| 59 | + feeds Home Assistant over the native API. |
| 60 | + """ |
| 61 | + if "psram" not in fv.full_config.get(): |
| 62 | + raise cv.Invalid( |
| 63 | + "tigo_server requires PSRAM, and this configuration has no `psram:` " |
| 64 | + "block.\n\n" |
| 65 | + "It builds whole HTML pages and JSON responses in memory, so on a " |
| 66 | + "board with only internal RAM it compiles and then runs out of heap " |
| 67 | + "under load. Either:\n" |
| 68 | + " * add a `psram:` block, if your board actually has PSRAM, or\n" |
| 69 | + " * remove `tigo_server:` and run sensors-only to Home Assistant " |
| 70 | + "over the native API. tigo_monitor needs no PSRAM.\n\n" |
| 71 | + "boards/esp32-lilygo-t-can485.yaml is a worked sensors-only example; " |
| 72 | + "panel discovery there uses the \"Generate YAML Config\" button " |
| 73 | + "instead of the web UI." |
| 74 | + ) |
| 75 | + return config |
| 76 | + |
| 77 | + |
46 | 78 | def _final_validate(config): |
| 79 | + _require_psram(config) |
47 | 80 | # ESPHome disables mbedtls SHA-384/512 on IDF >= 6.0 to save flash. Both of our |
48 | 81 | # crypto paths need them back: |
49 | 82 | # * cloud_import: everything above the leaf in Tigo's cert chain is SHA-384-signed |
|
0 commit comments