Skip to content

Commit c0ecf15

Browse files
Fix issue with friendly name overriding (#1001)
1 parent 799d694 commit c0ecf15

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

custom_components/battery_notes/coordinator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def last_replaced(self) -> datetime | None:
152152
"""Get the last replaced datetime."""
153153
device_entry = self.store.async_get_device(self.device_id)
154154
if device_entry:
155-
if LAST_REPLACED in device_entry:
155+
if LAST_REPLACED in device_entry and device_entry[LAST_REPLACED] is not None:
156156
last_replaced_date = datetime.fromisoformat(
157157
str(device_entry[LAST_REPLACED]) + "+00:00"
158158
)

custom_components/battery_notes/sensor.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,6 @@ async def _async_state_changed_listener(
457457
self.coordinator.wrapped_battery.entity_id, hidden_by=None
458458
)
459459

460-
def copy_custom_name(wrapped_battery: er.RegistryEntry) -> None:
461-
"""Copy the name set by user from the wrapped entity."""
462-
if wrapped_battery.name is None:
463-
return
464-
registry.async_update_entity(
465-
self.entity_id, name=wrapped_battery.name + "+"
466-
)
467-
468-
copy_custom_name(self.coordinator.wrapped_battery)
469-
470460
self.async_on_remove(
471461
self.coordinator.async_add_listener(self._handle_coordinator_update)
472462
)
@@ -639,7 +629,7 @@ def _set_native_value(self, log_on_error=True):
639629
# pylint: disable=unused-argument
640630
device_entry = self.coordinator.store.async_get_device(self._device_id)
641631
if device_entry:
642-
if LAST_REPLACED in device_entry:
632+
if LAST_REPLACED in device_entry and device_entry[LAST_REPLACED] is not None:
643633
last_replaced_date = datetime.fromisoformat(
644634
str(device_entry[LAST_REPLACED]) + "+00:00"
645635
)
@@ -654,7 +644,7 @@ def _handle_coordinator_update(self) -> None:
654644

655645
device_entry = self.coordinator.store.async_get_device(self._device_id)
656646
if device_entry:
657-
if LAST_REPLACED in device_entry:
647+
if LAST_REPLACED in device_entry and device_entry[LAST_REPLACED] is not None:
658648
last_replaced_date = datetime.fromisoformat(
659649
str(device_entry[LAST_REPLACED]) + "+00:00"
660650
)

0 commit comments

Comments
 (0)