4242)
4343from homeassistant .helpers .event import (
4444 EventStateChangedData ,
45+ EventStateReportedData ,
4546 async_track_entity_registry_updated_event ,
4647 async_track_state_change_event ,
48+ async_track_state_report_event ,
4749)
4850from homeassistant .helpers .reload import async_setup_reload_service
4951from homeassistant .helpers .typing import StateType
@@ -385,6 +387,25 @@ async def async_state_changed_listener(
385387
386388 self .async_write_ha_state ()
387389
390+ @callback
391+ async def async_state_reported_listener (
392+ self , event : Event [EventStateChangedData ] | None = None
393+ ) -> None :
394+ # pylint: disable=unused-argument
395+ """Handle child updates."""
396+
397+ if not self .coordinator .wrapped_battery :
398+ return
399+
400+ self .coordinator .last_reported = datetime .utcnow ()
401+
402+ _LOGGER .debug (
403+ "Entity id %s has been reported." ,
404+ self .coordinator .wrapped_battery .entity_id ,
405+ )
406+
407+ await self .coordinator .async_request_refresh ()
408+
388409 async def _register_entity_id_change_listener (
389410 self ,
390411 entity_id : str ,
@@ -425,6 +446,14 @@ async def _entity_rename_listener(event: Event[er.EventEntityRegistryUpdatedData
425446 )
426447 )
427448
449+ self .async_on_remove (
450+ async_track_state_report_event (
451+ self .hass ,
452+ [self .coordinator .wrapped_battery .entity_id ],
453+ self .async_state_reported_listener ,
454+ )
455+ )
456+
428457 @callback
429458 def _filter_entity_id (event_data : Mapping [str , Any ]) -> bool :
430459 """Only dispatch the listener for update events concerning the source entity."""
@@ -451,6 +480,13 @@ async def _async_state_changed_listener(
451480 """Handle child updates."""
452481 await self .async_state_changed_listener (event )
453482
483+ @callback
484+ async def _async_state_reported_listener (
485+ event : Event [EventStateReportedData ] | None = None ,
486+ ) -> None :
487+ """Handle child updates."""
488+ await self .async_state_reported_listener (event )
489+
454490 if self .coordinator .wrapped_battery :
455491 self .async_on_remove (
456492 async_track_state_change_event (
@@ -460,6 +496,14 @@ async def _async_state_changed_listener(
460496 )
461497 )
462498
499+ self .async_on_remove (
500+ async_track_state_report_event (
501+ self .hass ,
502+ [self .coordinator .wrapped_battery .entity_id ],
503+ _async_state_reported_listener ,
504+ )
505+ )
506+
463507 await self ._register_entity_id_change_listener (
464508 self .entity_id ,
465509 self .coordinator .wrapped_battery .entity_id ,
0 commit comments