6666from . import PLATFORMS
6767from .common import validate_is_float
6868from .const import (
69+ ATTR_BATTERY_LAST_REPLACED ,
6970 ATTR_BATTERY_LOW_THRESHOLD ,
7071 ATTR_BATTERY_QUANTITY ,
7172 ATTR_BATTERY_TYPE ,
7273 ATTR_BATTERY_TYPE_AND_QUANTITY ,
74+ ATTR_DEVICE_ID ,
75+ ATTR_DEVICE_NAME ,
76+ ATTR_SOURCE_ENTITY_ID ,
7377 CONF_SOURCE_ENTITY_ID ,
7478 DOMAIN ,
7579)
@@ -330,12 +334,27 @@ class BatteryNotesBatteryLowBaseSensor(
330334):
331335 """Low battery binary sensor base."""
332336
337+ def __init__ (
338+ self ,
339+ hass : HomeAssistant ,
340+ coordinator : BatteryNotesCoordinator ,
341+ ):
342+ """Initialize the low battery binary sensor."""
343+
344+ super ().__init__ (coordinator = coordinator )
345+
346+ self .enable_replaced = hass .data [MY_KEY ].enable_replaced
347+
333348 _unrecorded_attributes = frozenset (
334349 {
335350 ATTR_BATTERY_LOW_THRESHOLD ,
336351 ATTR_BATTERY_QUANTITY ,
337352 ATTR_BATTERY_TYPE ,
338353 ATTR_BATTERY_TYPE_AND_QUANTITY ,
354+ ATTR_BATTERY_LAST_REPLACED ,
355+ ATTR_DEVICE_ID ,
356+ ATTR_SOURCE_ENTITY_ID ,
357+ ATTR_DEVICE_NAME ,
339358 }
340359 )
341360
@@ -351,6 +370,14 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
351370 ATTR_BATTERY_TYPE_AND_QUANTITY : self .coordinator .battery_type_and_quantity ,
352371 }
353372
373+ if self .enable_replaced :
374+ attrs [ATTR_BATTERY_LAST_REPLACED ] = self .coordinator .last_replaced
375+
376+ # Other attributes that should follow battery, attribute list is unsorted
377+ attrs [ATTR_DEVICE_ID ] = self .coordinator .device_id or ""
378+ attrs [ATTR_SOURCE_ENTITY_ID ] = self .coordinator .source_entity_id or ""
379+ attrs [ATTR_DEVICE_NAME ] = self .coordinator .device_name
380+
354381 super_attrs = super ().extra_state_attributes
355382 if super_attrs :
356383 attrs .update (super_attrs )
@@ -382,7 +409,7 @@ def __init__(
382409 self ._attr_unique_id = unique_id
383410 self ._template_attrs : dict [Template , list [_TemplateAttribute ]] = {}
384411
385- super ().__init__ (coordinator = coordinator )
412+ super ().__init__ (hass = hass , coordinator = coordinator )
386413
387414 if coordinator .device_id and (
388415 device_entry := device_registry .async_get (coordinator .device_id )
@@ -612,7 +639,7 @@ def __init__(
612639 self .entity_description = description
613640 self ._attr_unique_id = unique_id
614641
615- super ().__init__ (coordinator = coordinator )
642+ super ().__init__ (hass = hass , coordinator = coordinator )
616643
617644 if coordinator .device_id and (
618645 device_entry := device_registry .async_get (coordinator .device_id )
@@ -707,7 +734,7 @@ def __init__(
707734 self .entity_description = description
708735 self ._attr_unique_id = unique_id
709736
710- super ().__init__ (coordinator = coordinator )
737+ super ().__init__ (hass = hass , coordinator = coordinator )
711738
712739 if coordinator .device_id and (
713740 device_entry := device_registry .async_get (coordinator .device_id )
0 commit comments