You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make entity naming and entity_id independent of pet name (#80)
## Summary
- Entity friendly names were built as `f"{pet_name} {suffix}"` (e.g.
"Fluffy Battery Level"). With `has_entity_name` unset, HA slugged that
combined string into the `entity_id` at first creation — so renaming the
pet later left the `entity_id` permanently stuck on the old name (e.g.
`sensor.fluffy_battery_level`), even though `unique_id` was already
correctly keyed on `device.id`.
- Sets `_attr_has_entity_name = True` on all sensor, binary sensor, and
device tracker entities, with per-entity suffix names (e.g. `"Battery
Level"`, `"At Home"`, `"Charging"`). HA now composes the displayed
friendly name from the device name (still the pet's name, pulled live
from `device.details.name` on every coordinator refresh) + the entity's
own name.
- Pins `_attr_suggested_object_id` to a `device.id`-based slug (e.g.
`pettracer_12345_battery_level`) so newly created entities get an
`entity_id` that's stable regardless of pet renames.
- The device tracker entity (which represents the pet itself) sets
`_attr_name = None` so its friendly name is exactly the device name,
matching prior behavior.
- This only affects **newly created** entities going forward — existing
installs keep their current `entity_id`s untouched (HA doesn't
auto-migrate `entity_id`, and neither does this change, to avoid
silently breaking dashboards/automations that reference the old ids).
## Test plan
- [x] Updated `tests/test_sensor.py`, `tests/test_binary_sensor.py`,
`tests/test_device_tracker.py` to assert the new
`name`/`_attr_suggested_object_id`/`_attr_has_entity_name` values.
- [x] Full suite passes: 74 passed, 98% coverage (`pytest
--cov=custom_components.pettracer --cov-report=term -v`), above the CI
90% gate.
- [x] `ruff check` clean on the three modified platform files.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments