1010 SwitchEntity ,
1111 SwitchEntityDescription ,
1212)
13+ from homeassistant .core import callback
1314
1415from .const import DOMAIN , LOGGER
1516from .entity import StromerEntity
@@ -48,8 +49,6 @@ class StromerSwitch(StromerEntity, SwitchEntity):
4849 """Representation of a Switch."""
4950
5051 _attr_has_entity_name = True
51- _attr_name = None
52- _attr_translation_key = DOMAIN
5352
5453 entity_description : SwitchEntityDescription
5554
@@ -68,23 +67,28 @@ def __init__(
6867 device_id = coordinator .data .bike_id
6968
7069 self .entity_description = description
71- self ._attr_unique_id = f"{ device_id } -{ description .key } "
70+ self ._attr_unique_id = f"{ device_id } -{ description .key } -sw "
7271
73- @property
74- def is_on (self ) -> bool :
75- """Return True if entity is on."""
76- return self ._coordinator .data .bikedata .get (self ._ent )
72+ @callback
73+ def _handle_coordinator_update (self ) -> None :
74+ """Handle updated data from the coordinator."""
75+ self ._attr_is_on = self ._coordinator .data .bikedata .get (self ._ent )
76+ self .async_write_ha_state ()
7777
7878 async def async_turn_on (self , ** kwargs : Any ) -> None :
7979 """Turn the device on."""
8080 if self .entity_description .key == "lock_flag" :
8181 await self ._coordinator .stromer .stromer_call_lock (True )
8282 if self .entity_description .key == "light_on" :
8383 await self ._coordinator .stromer .stromer_call_light ("on" )
84+ # Call update on the bike so `is_on` correctly reflects status
85+ await self ._coordinator .async_request_refresh ()
8486
8587 async def async_turn_off (self , ** kwargs : Any ) -> None :
8688 """Turn the device off."""
8789 if self .entity_description .key == "lock_flag" :
8890 await self ._coordinator .stromer .stromer_call_lock (False )
8991 if self .entity_description .key == "light_on" :
9092 await self ._coordinator .stromer .stromer_call_light ("off" )
93+ # Call update on the bike so `is_on` correctly reflects status
94+ await self ._coordinator .async_request_refresh ()
0 commit comments