Fix entity names for HA hardware firmware update entities (#142029)

* Fix entity names for HA hardware firmware update entities

* Fix unit tests
This commit is contained in:
puddly 2025-04-01 18:43:01 -04:00 committed by Franck Nijhof
parent f29444002e
commit d888c70ff0
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
6 changed files with 18 additions and 13 deletions

View File

@ -95,8 +95,7 @@ class BaseFirmwareUpdateEntity(
_attr_supported_features = (
UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
)
# Until this entity can be associated with a device, we must manually name it
_attr_has_entity_name = False
_attr_has_entity_name = True
def __init__(
self,
@ -195,10 +194,6 @@ class BaseFirmwareUpdateEntity(
def _update_attributes(self) -> None:
"""Recompute the attributes of the entity."""
# This entity is not currently associated with a device so we must manually
# give it a name
self._attr_name = f"{self._config_entry.title} Update"
self._attr_title = self.entity_description.firmware_name or "Unknown"
if (

View File

@ -168,7 +168,6 @@ class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
"""SkyConnect firmware update entity."""
bootloader_reset_type = None
_attr_has_entity_name = True
def __init__(
self,

View File

@ -152,7 +152,7 @@
},
"entity": {
"update": {
"firmware": {
"radio_firmware": {
"name": "Radio firmware"
}
}

View File

@ -44,6 +44,7 @@ FIRMWARE_ENTITY_DESCRIPTIONS: dict[
] = {
ApplicationType.EZSP: FirmwareUpdateEntityDescription(
key="radio_firmware",
translation_key="radio_firmware",
display_precision=0,
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.CONFIG,
@ -55,6 +56,7 @@ FIRMWARE_ENTITY_DESCRIPTIONS: dict[
),
ApplicationType.SPINEL: FirmwareUpdateEntityDescription(
key="radio_firmware",
translation_key="radio_firmware",
display_precision=0,
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.CONFIG,
@ -65,7 +67,8 @@ FIRMWARE_ENTITY_DESCRIPTIONS: dict[
firmware_name="OpenThread RCP",
),
ApplicationType.CPC: FirmwareUpdateEntityDescription(
key="firmware",
key="radio_firmware",
translation_key="radio_firmware",
display_precision=0,
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.CONFIG,
@ -76,7 +79,8 @@ FIRMWARE_ENTITY_DESCRIPTIONS: dict[
firmware_name="Multiprotocol",
),
ApplicationType.GECKO_BOOTLOADER: FirmwareUpdateEntityDescription(
key="firmware",
key="radio_firmware",
translation_key="radio_firmware",
display_precision=0,
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.CONFIG,
@ -88,6 +92,7 @@ FIRMWARE_ENTITY_DESCRIPTIONS: dict[
),
None: FirmwareUpdateEntityDescription(
key="radio_firmware",
translation_key="radio_firmware",
display_precision=0,
device_class=UpdateDeviceClass.FIRMWARE,
entity_category=EntityCategory.CONFIG,
@ -168,7 +173,6 @@ class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
"""Yellow firmware update entity."""
bootloader_reset_type = "yellow" # Triggers a GPIO reset
_attr_has_entity_name = True
def __init__(
self,

View File

@ -43,6 +43,7 @@ from homeassistant.core import (
)
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
@ -61,7 +62,7 @@ from tests.common import (
TEST_DOMAIN = "test"
TEST_DEVICE = "/dev/serial/by-id/some-unique-serial-device-12345"
TEST_FIRMWARE_RELEASES_URL = "https://example.org/firmware"
TEST_UPDATE_ENTITY_ID = "update.test_firmware"
TEST_UPDATE_ENTITY_ID = "update.mock_name_firmware"
TEST_MANIFEST = FirmwareManifest(
url=URL("https://example.org/firmware"),
html_url=URL("https://example.org/release_notes"),
@ -205,6 +206,12 @@ class MockFirmwareUpdateEntity(BaseFirmwareUpdateEntity):
"""Initialize the mock SkyConnect firmware update entity."""
super().__init__(device, config_entry, update_coordinator, entity_description)
self._attr_unique_id = self.entity_description.key
self._attr_device_info = DeviceInfo(
identifiers={(TEST_DOMAIN, "yellow")},
name="Mock Name",
model="Mock Model",
manufacturer="Mock Manufacturer",
)
# Use the cached firmware info if it exists
if self._config_entry.data["firmware"] is not None:

View File

@ -17,7 +17,7 @@ from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
UPDATE_ENTITY_ID = "update.home_assistant_yellow_firmware"
UPDATE_ENTITY_ID = "update.home_assistant_yellow_radio_firmware"
async def test_yellow_update_entity(hass: HomeAssistant) -> None: