Skip to content

Commit 54ba842

Browse files
committed
fix(sensor): reject a per-panel entry that selects no measurements
Reported in #48: a config with 25 panel entries carrying only address and name produced four entities total. address/name say which panel and what to call it; the entities come from the sub-keys, so to_code()'s loop had nothing to create and skipped each entry without a word. The reporter read that as a heap limit on a no-PSRAM ESP32 and went looking for a memory bug. Validation now names the entry, its address, and the available sub-keys. Shipped board files and the config builder all emit sub-keys already, so nothing in-tree changes; verified example-t-can485 and test-p4-ble still validate clean.
1 parent b62b9ce commit 54ba842

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **A per-panel sensor entry that lists no measurements is now a config error instead of a silent no-op.** `address` and `name` say which panel and what to call it; the entities come from the sub-keys (`power: {}`, `voltage_in: {}`, ...). An entry with none produced nothing at all, with no warning — which reads as "my panels never appeared in Home Assistant" and sends people looking at heap limits and device counts ([#48](https://github.com/RAR/esphome-tigomonitor/issues/48)). Validation now names the offending entry and lists the available sub-keys.
12+
1013
## [2.0.0] - 2026-08-14
1114

1215
Same firmware as [2.0.0-rc.2] — no code changed. What changed is the answer to

components/tigo_monitor/sensor.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,40 @@ def _auto_template_sensor_config(config):
148148

149149
return config
150150

151+
# Every measurement a per-device entry can ask for. An entry that names none of
152+
# these creates no entities at all, so validation rejects it (see
153+
# _require_device_sub_sensor below).
154+
_DEVICE_SUB_SENSOR_KEYS = (
155+
CONF_POWER_IN, CONF_POWER, CONF_PEAK_POWER, CONF_POWER_OUT,
156+
CONF_VOLTAGE_IN, CONF_VOLTAGE_OUT, CONF_CURRENT_IN, CONF_CURRENT_OUT,
157+
CONF_DUTY_CYCLE, CONF_TEMPERATURE, CONF_RSSI,
158+
CONF_BARCODE, CONF_FIRMWARE_VERSION, CONF_DEVICE_INFO,
159+
CONF_EFFICIENCY, CONF_POWER_FACTOR, CONF_LOAD_FACTOR,
160+
)
161+
162+
163+
def _require_device_sub_sensor(config):
164+
"""Reject a per-device entry that selects no measurements.
165+
166+
`address` + `name` only say *which* panel and what to call it — the
167+
entities come from the sub-keys. Without one, to_code() has nothing to
168+
create and the entry is a silent no-op, which reads as "my panels never
169+
showed up in Home Assistant" (issue #48).
170+
"""
171+
if not any(key in config for key in _DEVICE_SUB_SENSOR_KEYS):
172+
raise cv.Invalid(
173+
f"Device sensor '{config[CONF_NAME]}' (address "
174+
f"'{config[CONF_ADDRESS]}') selects no measurements, so it would "
175+
"create no entities. Add at least one sub-key, e.g.:\n"
176+
" power: {}\n"
177+
" voltage_in: {}\n"
178+
" current_in: {}\n"
179+
" temperature: {}\n"
180+
"Available: " + ", ".join(_DEVICE_SUB_SENSOR_KEYS)
181+
)
182+
return config
183+
184+
151185
# Schema for individual device sensors
152186
DEVICE_CONFIG_SCHEMA = cv.All(
153187
cv.Schema({
@@ -241,6 +275,7 @@ def _auto_template_sensor_config(config):
241275
state_class=STATE_CLASS_MEASUREMENT,
242276
),
243277
}).extend(cv.COMPONENT_SCHEMA),
278+
_require_device_sub_sensor,
244279
_auto_template_sensor_config,
245280
)
246281

site/src/content/docs/guides/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ sensor:
334334
load_factor: {}
335335
```
336336

337+
`address` and `name` only say *which* panel and what to call it — the entities
338+
come from the sub-keys, so list at least one. An entry with none creates no
339+
entities, and is rejected at validation time rather than silently skipped.
340+
337341
### Grouping panels into HA sub-devices
338342

339343
ESPHome's [sub-devices feature](https://esphome.io/components/esphome/#esphome-devices)

0 commit comments

Comments
 (0)