Skip to content

quick fix

Choose a tag to compare

@sathia-musso sathia-musso released this 23 Oct 13:01

fix: Handle legacy config entry key formats (v1.4.1 hotfix)

The migration and sensor initialization were failing with KeyError when
encountering config entries created with older versions that used different
key naming conventions.

Problem

Config entries created before const.py standardization used keys like:

  • "pod: IT1234567890" instead of "pod"
  • "numero utente" instead of "user_number"

This caused migration to fail with:

KeyError: 'pod'
File "/config/custom_components/enelgrid/__init__.py", line 39

Solution

Added _get_config_value() helper function in both init.py and sensor.py
that tries multiple key formats:

  1. New standardized key (e.g., "pod")
  2. Legacy exact match (e.g., "numero utente")
  3. Legacy prefix match (e.g., keys starting with "pod:")

This ensures backward compatibility with all config entry formats.

Changes

  • init.py: Add helper and use it in migration
  • sensor.py: Add helper and use it in setup + sensor init
  • manifest.json: Bump to v1.4.1

Fixes migration failure reported in production systems.