Clean up default ZHA entity names (#91841)

* Always use `Light` for lights, including subclasses

* Clean up other platforms

* Add a unit test to ensure all future entity classes have names

* Remove stale `_name`

* Address review feedback and rename `Open` to `Opening`
This commit is contained in:
puddly 2023-04-25 19:51:39 -04:00 committed by GitHub
parent da05763a5c
commit 6842cdcb65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 180 additions and 79 deletions

View file

@ -52,7 +52,6 @@ class BaseZhaEntity(LogMixin, entity.Entity):
def __init__(self, unique_id: str, zha_device: ZHADevice, **kwargs: Any) -> None:
"""Init ZHA entity."""
self._name: str = ""
self._unique_id: str = unique_id
if self.unique_id_suffix:
self._unique_id += f"-{self.unique_id_suffix}"
@ -62,13 +61,6 @@ class BaseZhaEntity(LogMixin, entity.Entity):
self._unsubs: list[Callable[[], None]] = []
self.remove_future: asyncio.Future[Any] = asyncio.Future()
@property
def name(self) -> str:
"""Return Entity's default name."""
if hasattr(self, "_attr_name") and self._attr_name is not None:
return self._attr_name
return self._name
@property
def unique_id(self) -> str:
"""Return a unique ID."""
@ -167,13 +159,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
) -> None:
"""Init ZHA entity."""
super().__init__(unique_id, zha_device, **kwargs)
self._name: str = (
self.__class__.__name__.lower()
.replace("zha", "")
.replace("entity", "")
.replace("sensor", "")
.capitalize()
)
self.cluster_handlers: dict[str, ClusterHandler] = {}
for cluster_handler in cluster_handlers:
self.cluster_handlers[cluster_handler.name] = cluster_handler
@ -249,6 +235,9 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
class ZhaGroupEntity(BaseZhaEntity):
"""A base class for ZHA group entities."""
# The group name is set in the initializer
_attr_name: str
def __init__(
self,
entity_ids: list[str],
@ -261,9 +250,6 @@ class ZhaGroupEntity(BaseZhaEntity):
super().__init__(unique_id, zha_device, **kwargs)
self._available = False
self._group = zha_device.gateway.groups.get(group_id)
self._name = (
f"{self._group.name}_zha_group_0x{group_id:04x}".lower().capitalize()
)
self._group_id: int = group_id
self._entity_ids: list[str] = entity_ids
self._async_unsub_state_changed: CALLBACK_TYPE | None = None
@ -271,6 +257,8 @@ class ZhaGroupEntity(BaseZhaEntity):
self._change_listener_debouncer: Debouncer | None = None
self._update_group_from_child_delay = DEFAULT_UPDATE_GROUP_FROM_CHILD_DELAY
self._attr_name = self._group.name
@property
def available(self) -> bool:
"""Return entity availability."""