Skip to content

Commit 8d81e1b

Browse files
belinea4071claude
andcommitted
Validate entity IDs and sensor values during config flow (#32)
Add state validation for optional entity IDs in the EV charger config step: entities that exist but report "unknown" or "unavailable" now trigger a warning log so the user is aware of potential issues at setup time. The config flow already validates: - Energy Dashboard completeness (abort if missing components) - Required EV sensors exist and are valid (via HardwareDetector) - Optional entity IDs exist in HA (entity_not_found error) Closes #32 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d3f7774 commit 8d81e1b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

config_flow.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,22 @@ async def async_step_ev_charger(
181181
errors.update(validation_errors)
182182
_LOGGER.error(f"EV validation failed: {validation_errors}")
183183

184-
# Validate optional entity IDs exist in HA
184+
# Validate optional entity IDs exist in HA and have usable state (#32)
185185
for entity_key in (
186186
"ev_charger_service_entity_id",
187187
"ev_current_sensor",
188188
"ev_total_energy_sensor",
189189
):
190190
entity_id = user_input.get(entity_key, "")
191-
if entity_id and not self.hass.states.get(entity_id):
192-
errors[entity_key] = "entity_not_found"
191+
if entity_id:
192+
state = self.hass.states.get(entity_id)
193+
if not state:
194+
errors[entity_key] = "entity_not_found"
195+
elif state.state in ("unknown", "unavailable"):
196+
_LOGGER.warning(
197+
"Entity %s exists but has state '%s' — may cause issues",
198+
entity_id, state.state,
199+
)
193200

194201
if not errors:
195202
# Store EV charger entities and continue to the hardware step

0 commit comments

Comments
 (0)