Skip to content

Commit 3895b2a

Browse files
Note (#4574)
1 parent b46141f commit 3895b2a

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

custom_components/battery_notes/binary_sensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
ATTR_BATTERY_TYPE_AND_QUANTITY,
6666
ATTR_DEVICE_ID,
6767
ATTR_DEVICE_NAME,
68+
ATTR_NOTE,
6869
ATTR_SOURCE_ENTITY_ID,
6970
CONF_SOURCE_ENTITY_ID,
7071
DOMAIN,
@@ -231,6 +232,7 @@ def __init__(
231232
ATTR_BATTERY_QUANTITY,
232233
ATTR_BATTERY_TYPE,
233234
ATTR_BATTERY_TYPE_AND_QUANTITY,
235+
ATTR_NOTE,
234236
ATTR_BATTERY_LAST_REPLACED,
235237
ATTR_DEVICE_ID,
236238
ATTR_SOURCE_ENTITY_ID,
@@ -248,6 +250,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
248250
ATTR_BATTERY_QUANTITY: self.coordinator.battery_quantity,
249251
ATTR_BATTERY_TYPE: self.coordinator.battery_type,
250252
ATTR_BATTERY_TYPE_AND_QUANTITY: self.coordinator.battery_type_and_quantity,
253+
ATTR_NOTE: self.coordinator.battery_note,
251254
}
252255

253256
if self.enable_replaced:

custom_components/battery_notes/config_flow.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
CONF_MANUFACTURER,
4848
CONF_MODEL,
4949
CONF_MODEL_ID,
50+
CONF_NOTE,
5051
CONF_ROUND_BATTERY,
5152
CONF_SHOW_ALL_DEVICES,
5253
CONF_SOURCE_ENTITY_ID,
@@ -522,6 +523,14 @@ async def async_step_battery(
522523
min=1, max=100, mode=selector.NumberSelectorMode.BOX
523524
),
524525
),
526+
vol.Optional(
527+
CONF_NOTE,
528+
default=self.data.get(CONF_NOTE),
529+
): selector.TextSelector(
530+
selector.TextSelectorConfig(
531+
type=selector.TextSelectorType.TEXT
532+
),
533+
),
525534
vol.Required(
526535
CONF_BATTERY_LOW_THRESHOLD,
527536
default=0,
@@ -793,6 +802,7 @@ async def async_step_battery(
793802
if user_input is not None:
794803
self.data[CONF_BATTERY_TYPE] = user_input[CONF_BATTERY_TYPE]
795804
self.data[CONF_BATTERY_QUANTITY] = int(user_input[CONF_BATTERY_QUANTITY])
805+
self.data[CONF_NOTE] = user_input[CONF_NOTE]
796806
self.data[CONF_BATTERY_LOW_THRESHOLD] = int(
797807
user_input[CONF_BATTERY_LOW_THRESHOLD]
798808
)
@@ -856,6 +866,14 @@ async def async_step_battery(
856866
min=1, max=100, mode=selector.NumberSelectorMode.BOX
857867
),
858868
),
869+
vol.Optional(
870+
CONF_NOTE,
871+
default=self.data.get(CONF_NOTE),
872+
): selector.TextSelector(
873+
selector.TextSelectorConfig(
874+
type=selector.TextSelectorType.TEXT
875+
),
876+
),
859877
vol.Required(
860878
CONF_BATTERY_LOW_THRESHOLD,
861879
default=int(self.data.get(CONF_BATTERY_LOW_THRESHOLD, 0)),
@@ -894,6 +912,7 @@ async def async_step_reconfigure(
894912
if user_input is not None:
895913
self.data[CONF_BATTERY_TYPE] = user_input[CONF_BATTERY_TYPE]
896914
self.data[CONF_BATTERY_QUANTITY] = int(user_input[CONF_BATTERY_QUANTITY])
915+
self.data[CONF_NOTE] = user_input[CONF_NOTE]
897916
self.data[CONF_BATTERY_LOW_THRESHOLD] = int(
898917
user_input[CONF_BATTERY_LOW_THRESHOLD]
899918
)
@@ -974,6 +993,9 @@ async def async_step_reconfigure(
974993
min=1, max=100, mode=selector.NumberSelectorMode.BOX
975994
),
976995
),
996+
vol.Optional(CONF_NOTE): selector.TextSelector(
997+
selector.TextSelectorConfig(type=selector.TextSelectorType.TEXT),
998+
),
977999
vol.Required(
9781000
CONF_BATTERY_LOW_THRESHOLD,
9791001
): selector.NumberSelector(

custom_components/battery_notes/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
CONF_SOURCE_ENTITY_ID = "source_entity_id"
3030
CONF_BATTERY_TYPE = "battery_type"
3131
CONF_BATTERY_QUANTITY = "battery_quantity"
32+
CONF_NOTE = "note"
3233
CONF_BATTERY_LOW_THRESHOLD = "battery_low_threshold"
3334
CONF_SENSORS = "sensors"
3435
CONF_ENABLE_AUTODISCOVERY = "enable_autodiscovery"
@@ -79,6 +80,7 @@
7980
ATTR_REMOVE = "remove"
8081
ATTR_BATTERY_QUANTITY = "battery_quantity"
8182
ATTR_BATTERY_TYPE = "battery_type"
83+
ATTR_NOTE = "note"
8284
ATTR_BATTERY_TYPE_AND_QUANTITY = "battery_type_and_quantity"
8385
ATTR_BATTERY_LAST_REPLACED = "battery_last_replaced"
8486
ATTR_BATTERY_LOW = "battery_low"

custom_components/battery_notes/coordinator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ATTR_BATTERY_TYPE_AND_QUANTITY,
4242
ATTR_DEVICE_ID,
4343
ATTR_DEVICE_NAME,
44+
ATTR_NOTE,
4445
ATTR_PREVIOUS_BATTERY_LEVEL,
4546
ATTR_REMOVE,
4647
ATTR_SOURCE_ENTITY_ID,
@@ -51,6 +52,7 @@
5152
CONF_BATTERY_QUANTITY,
5253
CONF_BATTERY_TYPE,
5354
CONF_FILTER_OUTLIERS,
55+
CONF_NOTE,
5456
CONF_SOURCE_ENTITY_ID,
5557
DEFAULT_BATTERY_INCREASE_THRESHOLD,
5658
DEFAULT_BATTERY_LOW_THRESHOLD,
@@ -107,6 +109,7 @@ class BatteryNotesSubentryCoordinator(DataUpdateCoordinator[None]):
107109
device_name: str
108110
battery_type: str
109111
battery_quantity: int
112+
battery_note: str
110113
battery_low_threshold: int
111114
battery_low_template: str | None
112115
battery_percentage_template: str | None
@@ -148,6 +151,7 @@ def __init__( # noqa: PLR0912
148151
return
149152

150153
self.battery_type = cast(str, self.subentry.data.get(CONF_BATTERY_TYPE, ""))
154+
self.battery_note = cast(str, self.subentry.data.get(CONF_NOTE, ""))
151155
try:
152156
self.battery_quantity = cast(
153157
int, self.subentry.data.get(CONF_BATTERY_QUANTITY, 1)
@@ -412,6 +416,7 @@ def battery_low_template_state(self, value):
412416
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
413417
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
414418
ATTR_BATTERY_TYPE: self.battery_type,
419+
ATTR_NOTE: self.battery_note,
415420
ATTR_BATTERY_QUANTITY: self.battery_quantity,
416421
ATTR_BATTERY_LEVEL: 0,
417422
ATTR_PREVIOUS_BATTERY_LEVEL: 100,
@@ -444,6 +449,7 @@ def battery_low_template_state(self, value):
444449
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
445450
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
446451
ATTR_BATTERY_TYPE: self.battery_type,
452+
ATTR_NOTE: self.battery_note,
447453
ATTR_BATTERY_QUANTITY: self.battery_quantity,
448454
ATTR_BATTERY_LEVEL: 100,
449455
ATTR_PREVIOUS_BATTERY_LEVEL: 0,
@@ -478,6 +484,7 @@ def battery_low_binary_state(self, value):
478484
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
479485
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
480486
ATTR_BATTERY_TYPE: self.battery_type,
487+
ATTR_NOTE: self.battery_note,
481488
ATTR_BATTERY_QUANTITY: self.battery_quantity,
482489
ATTR_BATTERY_LEVEL: 0,
483490
ATTR_PREVIOUS_BATTERY_LEVEL: 100,
@@ -510,6 +517,7 @@ def battery_low_binary_state(self, value):
510517
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
511518
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
512519
ATTR_BATTERY_TYPE: self.battery_type,
520+
ATTR_NOTE: self.battery_note,
513521
ATTR_BATTERY_QUANTITY: self.battery_quantity,
514522
ATTR_BATTERY_LEVEL: 100,
515523
ATTR_PREVIOUS_BATTERY_LEVEL: 0,
@@ -562,6 +570,7 @@ def current_battery_level(self, value):
562570
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
563571
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
564572
ATTR_BATTERY_TYPE: self.battery_type,
573+
ATTR_NOTE: self.battery_note,
565574
ATTR_BATTERY_QUANTITY: self.battery_quantity,
566575
ATTR_BATTERY_LEVEL: self.rounded_battery_level,
567576
ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level,
@@ -597,6 +606,7 @@ def current_battery_level(self, value):
597606
ATTR_BATTERY_LOW_THRESHOLD: self.battery_low_threshold,
598607
ATTR_BATTERY_TYPE_AND_QUANTITY: self.battery_type_and_quantity,
599608
ATTR_BATTERY_TYPE: self.battery_type,
609+
ATTR_NOTE: self.battery_note,
600610
ATTR_BATTERY_QUANTITY: self.battery_quantity,
601611
ATTR_BATTERY_LEVEL: self.rounded_battery_level,
602612
ATTR_PREVIOUS_BATTERY_LEVEL: self.rounded_previous_battery_level,

custom_components/battery_notes/sensor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
ATTR_BATTERY_TYPE_AND_QUANTITY,
6767
ATTR_DEVICE_ID,
6868
ATTR_DEVICE_NAME,
69+
ATTR_NOTE,
6970
ATTR_SOURCE_ENTITY_ID,
7071
CONF_ADVANCED_SETTINGS,
7172
CONF_BATTERY_QUANTITY,
@@ -233,7 +234,13 @@ class BatteryNotesTypeSensor(BatteryNotesEntity, RestoreSensor):
233234

234235
_attr_should_poll = False
235236
entity_description: BatteryNotesSensorEntityDescription
236-
_unrecorded_attributes = frozenset({ATTR_BATTERY_QUANTITY, ATTR_BATTERY_TYPE})
237+
_unrecorded_attributes = frozenset(
238+
{
239+
ATTR_BATTERY_QUANTITY,
240+
ATTR_BATTERY_TYPE,
241+
ATTR_NOTE,
242+
}
243+
)
237244

238245
def __init__( # noqa: PLR0913
239246
self,
@@ -285,6 +292,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
285292
attrs = {
286293
ATTR_BATTERY_QUANTITY: self.coordinator.battery_quantity,
287294
ATTR_BATTERY_TYPE: self.coordinator.battery_type,
295+
ATTR_NOTE: self.coordinator.battery_note,
288296
}
289297

290298
super_attrs = super().extra_state_attributes
@@ -359,6 +367,7 @@ class BatteryNotesBatteryPlusBaseSensor(BatteryNotesEntity, RestoreSensor):
359367
ATTR_BATTERY_QUANTITY,
360368
ATTR_BATTERY_TYPE,
361369
ATTR_BATTERY_TYPE_AND_QUANTITY,
370+
ATTR_NOTE,
362371
ATTR_BATTERY_LOW,
363372
ATTR_BATTERY_LOW_THRESHOLD,
364373
ATTR_BATTERY_LAST_REPORTED,
@@ -418,6 +427,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
418427
ATTR_BATTERY_QUANTITY: self.coordinator.battery_quantity,
419428
ATTR_BATTERY_TYPE: self.coordinator.battery_type,
420429
ATTR_BATTERY_TYPE_AND_QUANTITY: self.coordinator.battery_type_and_quantity,
430+
ATTR_NOTE: self.coordinator.battery_note,
421431
ATTR_BATTERY_LOW: self.coordinator.battery_low,
422432
ATTR_BATTERY_LOW_THRESHOLD: self.coordinator.battery_low_threshold,
423433
ATTR_BATTERY_LAST_REPORTED: self.coordinator.last_reported,

custom_components/battery_notes/translations/en.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"data": {
1111
"battery_type": "Battery type",
1212
"battery_quantity": "Battery quantity",
13+
"note": "Note",
1314
"battery_low_threshold": "Battery low threshold"
1415
},
1516
"data_description": {
@@ -82,6 +83,7 @@
8283
"data": {
8384
"battery_type": "Battery type",
8485
"battery_quantity": "Battery quantity",
86+
"note": "Note",
8587
"battery_low_threshold": "Battery low threshold"
8688
},
8789
"data_description": {
@@ -113,6 +115,7 @@
113115
"name": "Name",
114116
"battery_type": "Battery type",
115117
"battery_quantity": "Battery quantity",
118+
"note": "Note",
116119
"battery_low_threshold": "Battery low threshold"
117120
},
118121
"data_description": {
@@ -214,6 +217,9 @@
214217
"battery_type_and_quantity": {
215218
"name": "Battery type and quantity"
216219
},
220+
"note": {
221+
"name": "Note"
222+
},
217223
"battery_last_replaced": {
218224
"name": "Battery last replaced"
219225
},
@@ -248,6 +254,9 @@
248254
},
249255
"battery_quantity": {
250256
"name": "Battery quantity"
257+
},
258+
"note": {
259+
"name": "Note"
251260
}
252261
}
253262
},

0 commit comments

Comments
 (0)