Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve entity naming fallback #3083

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions custom_components/battery_notes/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_registry import RegistryEntry
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -96,11 +97,21 @@ def source_entity_name(self):

if self.source_entity_id:
entity_registry = er.async_get(self.hass)
device_registry = dr.async_get(self.hass)
registry_entry = entity_registry.async_get(self.source_entity_id)
device_entry = device_registry.async_get(self.device_id) if self.device_id else None
assert(registry_entry)
self._source_entity_name = (
registry_entry.name or registry_entry.original_name
)

if registry_entry.name is None and registry_entry.has_entity_name and device_entry:
self._source_entity_name = (
registry_entry.name or registry_entry.original_name or device_entry.name_by_user or device_entry.name or self.source_entity_id
)
else:
self._source_entity_name = (
registry_entry.name or registry_entry.original_name or self.source_entity_id
)

assert(self._source_entity_name)

return self._source_entity_name

Expand Down