Skip to content

Commit 87bbeba

Browse files
Replace battery threshold attribute on battery low
1 parent 4e9373a commit 87bbeba

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

custom_components/battery_notes/binary_sensor.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,12 @@ def handle_result(
328328
self.on_update(validated)
329329
return
330330

331-
class BatteryNotesBatteryLowBaseSensor(BinarySensorEntity, CoordinatorEntity[BatteryNotesCoordinator]):
331+
332+
class BatteryNotesBatteryLowBaseSensor(
333+
BinarySensorEntity, CoordinatorEntity[BatteryNotesCoordinator]
334+
):
332335
"""Low battery binary sensor base."""
336+
333337
_unrecorded_attributes = frozenset(
334338
{
335339
ATTR_BATTERY_LOW_THRESHOLD,
@@ -345,6 +349,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
345349

346350
# Battery related attributes
347351
attrs = {
352+
ATTR_BATTERY_LOW_THRESHOLD: self.coordinator.battery_low_threshold,
348353
ATTR_BATTERY_QUANTITY: self.coordinator.battery_quantity,
349354
ATTR_BATTERY_TYPE: self.coordinator.battery_type,
350355
ATTR_BATTERY_TYPE_AND_QUANTITY: self.coordinator.battery_type_and_quantity,
@@ -355,6 +360,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
355360
attrs.update(super_attrs)
356361
return attrs
357362

363+
358364
class BatteryNotesBatteryLowTemplateSensor(
359365
BatteryNotesBatteryLowBaseSensor, RestoreEntity
360366
):
@@ -746,7 +752,9 @@ async def async_state_changed_listener(
746752
self.async_write_ha_state()
747753
return
748754

749-
self.coordinator.battery_low_binary_state = wrapped_battery_low_state.state == "on"
755+
self.coordinator.battery_low_binary_state = (
756+
wrapped_battery_low_state.state == "on"
757+
)
750758

751759
await self.coordinator.async_request_refresh()
752760

@@ -764,7 +772,9 @@ async def _register_entity_id_change_listener(
764772
"""Listen for battery entity_id changes and update battery_plus."""
765773

766774
@callback
767-
async def _entity_rename_listener(event: Event[er.EventEntityRegistryUpdatedData]) -> None:
775+
async def _entity_rename_listener(
776+
event: Event[er.EventEntityRegistryUpdatedData],
777+
) -> None:
768778
"""Handle renaming of the entity."""
769779
new_entity_id = event.data["entity_id"]
770780
old_entity_id = event.data.get("old_entity_id", None)

docs/entities.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ The last time the battery of the device was replaced.
7171
A button to set the battery_last_replaced entity to now.
7272

7373
## Battery Low
74-
`sensor.{{device_name}}_battery_plus_low`
74+
`binary_sensor.{{device_name}}_battery_plus_low`
7575

7676
A boolean sensor indicating if the battery is low, true when the battery is below the device or global threshold.
7777

7878
| Attribute | Type | Description |
7979
|-----------|------|-------------|
80-
| `battery_low_threshold` | `int` | The device or global threshold for when the battery is low. |
80+
| `battery_low_threshold` | `int` | The device or global threshold for when the battery is low |
81+
| `battery_quantity` | `int` | The quantity of batteries |
82+
| `battery_type` | `string` | The type of batteries |
83+
| `battery_type_and_quantity` | `string` | The type of batteries with the quantity if more than 1 |

0 commit comments

Comments
 (0)