Skip to content

Commit c043a96

Browse files
Add battery last replaced attribute to events (#3142)
1 parent cd9ff7d commit c043a96

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

custom_components/battery_notes/coordinator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from .common import validate_is_float
2121
from .const import (
22+
ATTR_BATTERY_LAST_REPLACED,
2223
ATTR_BATTERY_LEVEL,
2324
ATTR_BATTERY_LOW,
2425
ATTR_BATTERY_QUANTITY,
@@ -147,6 +148,7 @@ def battery_low_template_state(self, value):
147148
ATTR_BATTERY_QUANTITY: self.battery_quantity,
148149
ATTR_BATTERY_LEVEL: 0,
149150
ATTR_PREVIOUS_BATTERY_LEVEL: 100,
151+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
150152
ATTR_BATTERY_THRESHOLD_REMINDER: False,
151153
},
152154
)
@@ -171,6 +173,7 @@ def battery_low_template_state(self, value):
171173
ATTR_BATTERY_QUANTITY: self.battery_quantity,
172174
ATTR_BATTERY_LEVEL: 100,
173175
ATTR_PREVIOUS_BATTERY_LEVEL: 0,
176+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
174177
},
175178
)
176179

@@ -200,6 +203,7 @@ def battery_low_binary_state(self, value):
200203
ATTR_BATTERY_QUANTITY: self.battery_quantity,
201204
ATTR_BATTERY_LEVEL: 0,
202205
ATTR_PREVIOUS_BATTERY_LEVEL: 100,
206+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
203207
ATTR_BATTERY_THRESHOLD_REMINDER: False,
204208
},
205209
)
@@ -225,6 +229,7 @@ def battery_low_binary_state(self, value):
225229
ATTR_BATTERY_QUANTITY: self.battery_quantity,
226230
ATTR_BATTERY_LEVEL: 100,
227231
ATTR_PREVIOUS_BATTERY_LEVEL: 0,
232+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
228233
},
229234
)
230235

@@ -273,6 +278,7 @@ def current_battery_level(self, value):
273278
ATTR_BATTERY_QUANTITY: self.battery_quantity,
274279
ATTR_BATTERY_LEVEL: self.rounded_battery_level,
275280
ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level,
281+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
276282
ATTR_BATTERY_THRESHOLD_REMINDER: False,
277283
},
278284
)
@@ -306,6 +312,7 @@ def current_battery_level(self, value):
306312
ATTR_BATTERY_QUANTITY: self.battery_quantity,
307313
ATTR_BATTERY_LEVEL: self.rounded_battery_level,
308314
ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level,
315+
ATTR_BATTERY_LAST_REPLACED: self.last_replaced,
309316
},
310317
)
311318

custom_components/battery_notes/services.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from homeassistant.util import dt as dt_util
1515

1616
from .const import (
17+
ATTR_BATTERY_LAST_REPLACED,
1718
ATTR_BATTERY_LAST_REPORTED,
1819
ATTR_BATTERY_LAST_REPORTED_DAYS,
1920
ATTR_BATTERY_LAST_REPORTED_LEVEL,
@@ -194,6 +195,7 @@ async def handle_battery_last_reported(call: ServiceCall) -> ServiceResponse:
194195
ATTR_BATTERY_LAST_REPORTED: device.coordinator.last_reported,
195196
ATTR_BATTERY_LAST_REPORTED_DAYS: time_since_lastreported.days,
196197
ATTR_BATTERY_LAST_REPORTED_LEVEL: device.coordinator.last_reported_level,
198+
ATTR_BATTERY_LAST_REPLACED: device.coordinator.last_replaced,
197199
},
198200
)
199201

@@ -223,6 +225,7 @@ async def handle_battery_low(call: ServiceCall) -> ServiceResponse:
223225
ATTR_BATTERY_QUANTITY: device.coordinator.battery_quantity,
224226
ATTR_BATTERY_LEVEL: device.coordinator.rounded_battery_level,
225227
ATTR_PREVIOUS_BATTERY_LEVEL: device.coordinator.rounded_previous_battery_level,
228+
ATTR_BATTERY_LAST_REPLACED: device.coordinator.last_replaced,
226229
ATTR_BATTERY_THRESHOLD_REMINDER: True,
227230
},
228231
)

0 commit comments

Comments
 (0)