2323
2424from homeassistant .components .select import SelectEntity
2525from homeassistant .helpers .device_registry import DeviceInfo
26+ from homeassistant .helpers .event import async_track_state_change_event
2627
27- from .const import DOMAIN , WALLBOX_MODE_MAP
28+ from .const import DOMAIN , WALLBOX_LEGACY_MODE_MAP , WALLBOX_MODE_MAP
2829from .wallbox_api import WallboxApiClient
2930
3031_LOGGER = logging .getLogger (__name__ )
@@ -63,7 +64,21 @@ def __init__(self, hass, api_client: WallboxApiClient):
6364 self ._current_option = None
6465 self ._pending_change = None
6566
66-
67+ async def async_added_to_hass (self ):
68+ """Register state change listener when entity is added."""
69+ async_track_state_change_event (
70+ self ._hass ,
71+ "sensor.wallbox_lademodus" ,
72+ self ._handle_mode_change
73+ )
74+ await self .async_update ()
75+
76+ async def _handle_mode_change (self , event ):
77+ """React to sensor.wallbox_lademodus state changes."""
78+ _LOGGER .debug ("[Enpal] Detected state change for wallbox_lademodus: %s" , event .data )
79+ await self .async_update ()
80+ self .async_write_ha_state ()
81+
6782 @property
6883 def current_option (self ) -> str | None :
6984 return self ._pending_change or self ._current_option or "Nicht verfügbar"
@@ -85,6 +100,7 @@ async def async_update(self):
85100 return
86101
87102 mode = mode_entity .state .lower ()
103+ mode = WALLBOX_LEGACY_MODE_MAP .get (mode , mode )
88104 new_option = WALLBOX_MODE_MAP .get (mode )
89105
90106 if not new_option :
0 commit comments