Optimize entity creation by storing device name as data in NUT (#141147)

This commit is contained in:
tdfountain 2025-03-22 14:11:48 -07:00 committed by GitHub
parent 4e2dfba45f
commit a9df341abf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -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:

View File

@ -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))