66
66
from . import PLATFORMS
67
67
from .common import validate_is_float
68
68
from .const import (
69
+ ATTR_BATTERY_LAST_REPLACED ,
69
70
ATTR_BATTERY_LOW_THRESHOLD ,
70
71
ATTR_BATTERY_QUANTITY ,
71
72
ATTR_BATTERY_TYPE ,
72
73
ATTR_BATTERY_TYPE_AND_QUANTITY ,
74
+ ATTR_DEVICE_ID ,
75
+ ATTR_DEVICE_NAME ,
76
+ ATTR_SOURCE_ENTITY_ID ,
73
77
CONF_SOURCE_ENTITY_ID ,
74
78
DOMAIN ,
75
79
)
@@ -330,12 +334,27 @@ class BatteryNotesBatteryLowBaseSensor(
330
334
):
331
335
"""Low battery binary sensor base."""
332
336
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
+
333
348
_unrecorded_attributes = frozenset (
334
349
{
335
350
ATTR_BATTERY_LOW_THRESHOLD ,
336
351
ATTR_BATTERY_QUANTITY ,
337
352
ATTR_BATTERY_TYPE ,
338
353
ATTR_BATTERY_TYPE_AND_QUANTITY ,
354
+ ATTR_BATTERY_LAST_REPLACED ,
355
+ ATTR_DEVICE_ID ,
356
+ ATTR_SOURCE_ENTITY_ID ,
357
+ ATTR_DEVICE_NAME ,
339
358
}
340
359
)
341
360
@@ -351,6 +370,14 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
351
370
ATTR_BATTERY_TYPE_AND_QUANTITY : self .coordinator .battery_type_and_quantity ,
352
371
}
353
372
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
+
354
381
super_attrs = super ().extra_state_attributes
355
382
if super_attrs :
356
383
attrs .update (super_attrs )
@@ -382,7 +409,7 @@ def __init__(
382
409
self ._attr_unique_id = unique_id
383
410
self ._template_attrs : dict [Template , list [_TemplateAttribute ]] = {}
384
411
385
- super ().__init__ (coordinator = coordinator )
412
+ super ().__init__ (hass = hass , coordinator = coordinator )
386
413
387
414
if coordinator .device_id and (
388
415
device_entry := device_registry .async_get (coordinator .device_id )
@@ -612,7 +639,7 @@ def __init__(
612
639
self .entity_description = description
613
640
self ._attr_unique_id = unique_id
614
641
615
- super ().__init__ (coordinator = coordinator )
642
+ super ().__init__ (hass = hass , coordinator = coordinator )
616
643
617
644
if coordinator .device_id and (
618
645
device_entry := device_registry .async_get (coordinator .device_id )
@@ -707,7 +734,7 @@ def __init__(
707
734
self .entity_description = description
708
735
self ._attr_unique_id = unique_id
709
736
710
- super ().__init__ (coordinator = coordinator )
737
+ super ().__init__ (hass = hass , coordinator = coordinator )
711
738
712
739
if coordinator .device_id and (
713
740
device_entry := device_registry .async_get (coordinator .device_id )
0 commit comments