mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Optimize entity creation by storing device name as data in NUT (#141147)
This commit is contained in:
parent
4e2dfba45f
commit
a9df341abf
@ -240,6 +240,7 @@ class PyNUTData:
|
||||
|
||||
self._client = AIONUTClient(self._host, port, username, password, 5, persistent)
|
||||
self.ups_list: dict[str, str] | None = None
|
||||
self.device_name: str | None = None
|
||||
self._status: dict[str, str] | None = None
|
||||
self._device_info: NUTDeviceInfo | None = None
|
||||
|
||||
@ -250,7 +251,7 @@ class PyNUTData:
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the ups."""
|
||||
"""Return the name of the NUT device."""
|
||||
return self._alias or f"Nut-{self._host}"
|
||||
|
||||
@property
|
||||
@ -294,6 +295,8 @@ class PyNUTData:
|
||||
self._status = await self._async_get_status()
|
||||
if self._device_info is None:
|
||||
self._device_info = self._get_device_info()
|
||||
if self.device_name is None:
|
||||
self.device_name = self.name.title()
|
||||
return self._status
|
||||
|
||||
async def async_run_command(self, command_name: str) -> None:
|
||||
|
@ -42,10 +42,10 @@ class NUTBaseEntity(CoordinatorEntity[DataUpdateCoordinator]):
|
||||
"""Initialize the entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
device_name = data.name.title()
|
||||
self.pynut_data = data
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
name=device_name,
|
||||
name=self.pynut_data.device_name,
|
||||
)
|
||||
self._attr_device_info.update(_get_nut_device_info(data))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user