Remove deprecated supported features warning in Update (#132667)

This commit is contained in:
epenet 2024-12-09 11:25:18 +01:00 committed by GitHub
parent ee8f720253
commit 6cf10cd0b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 112 deletions

View File

@ -136,7 +136,7 @@ async def async_install(entity: UpdateEntity, service_call: ServiceCall) -> None
# If version is specified, but not supported by the entity.
if (
version is not None
and UpdateEntityFeature.SPECIFIC_VERSION not in entity.supported_features_compat
and UpdateEntityFeature.SPECIFIC_VERSION not in entity.supported_features
):
raise HomeAssistantError(
f"Installing a specific version is not supported for {entity.entity_id}"
@ -145,7 +145,7 @@ async def async_install(entity: UpdateEntity, service_call: ServiceCall) -> None
# If backup is requested, but not supported by the entity.
if (
backup := service_call.data[ATTR_BACKUP]
) and UpdateEntityFeature.BACKUP not in entity.supported_features_compat:
) and UpdateEntityFeature.BACKUP not in entity.supported_features:
raise HomeAssistantError(f"Backup is not supported for {entity.entity_id}")
# Update is already in progress.
@ -279,7 +279,7 @@ class UpdateEntity(
return self._attr_entity_category
if hasattr(self, "entity_description"):
return self.entity_description.entity_category
if UpdateEntityFeature.INSTALL in self.supported_features_compat:
if UpdateEntityFeature.INSTALL in self.supported_features:
return EntityCategory.CONFIG
return EntityCategory.DIAGNOSTIC
@ -337,19 +337,6 @@ class UpdateEntity(
"""
return self._attr_title
@property
def supported_features_compat(self) -> UpdateEntityFeature:
"""Return the supported features as UpdateEntityFeature.
Remove this compatibility shim in 2025.1 or later.
"""
features = self.supported_features
if type(features) is int: # noqa: E721
new_features = UpdateEntityFeature(features)
self._report_deprecated_supported_features_values(new_features)
return new_features
return features
@cached_property
def update_percentage(self) -> int | float | None:
"""Update installation progress.
@ -451,7 +438,7 @@ class UpdateEntity(
# If entity supports progress, return the in_progress value.
# Otherwise, we use the internal progress value.
if UpdateEntityFeature.PROGRESS in self.supported_features_compat:
if UpdateEntityFeature.PROGRESS in self.supported_features:
in_progress = self.in_progress
update_percentage = self.update_percentage if in_progress else None
if type(in_progress) is not bool and isinstance(in_progress, int):
@ -494,7 +481,7 @@ class UpdateEntity(
Handles setting the in_progress state in case the entity doesn't
support it natively.
"""
if UpdateEntityFeature.PROGRESS not in self.supported_features_compat:
if UpdateEntityFeature.PROGRESS not in self.supported_features:
self.__in_progress = True
self.async_write_ha_state()
@ -539,7 +526,7 @@ async def websocket_release_notes(
)
return
if UpdateEntityFeature.RELEASE_NOTES not in entity.supported_features_compat:
if UpdateEntityFeature.RELEASE_NOTES not in entity.supported_features:
connection.send_error(
msg["id"],
websocket_api.ERR_NOT_SUPPORTED,

View File

@ -896,98 +896,6 @@ async def test_name(hass: HomeAssistant) -> None:
assert expected.items() <= state.attributes.items()
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecated supported features ints."""
class MockUpdateEntity(UpdateEntity):
@property
def supported_features(self) -> int:
"""Return supported features."""
return 1
entity = MockUpdateEntity()
assert entity.supported_features_compat is UpdateEntityFeature(1)
assert "MockUpdateEntity" in caplog.text
assert "is using deprecated supported features values" in caplog.text
assert "Instead it should use" in caplog.text
assert "UpdateEntityFeature.INSTALL" in caplog.text
caplog.clear()
assert entity.supported_features_compat is UpdateEntityFeature(1)
assert "is using deprecated supported features values" not in caplog.text
async def test_deprecated_supported_features_ints_with_service_call(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test deprecated supported features ints with install service."""
async def async_setup_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
return True
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")
mock_integration(
hass,
MockModule(
TEST_DOMAIN,
async_setup_entry=async_setup_entry_init,
),
)
class MockUpdateEntity(UpdateEntity):
_attr_supported_features = 1 | 2
def install(self, version: str | None = None, backup: bool = False) -> None:
"""Install an update."""
entity = MockUpdateEntity()
entity.entity_id = (
"update.test_deprecated_supported_features_ints_with_service_call"
)
async def async_setup_entry_platform(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up test update platform via config entry."""
async_add_entities([entity])
mock_platform(
hass,
f"{TEST_DOMAIN}.{DOMAIN}",
MockPlatform(async_setup_entry=async_setup_entry_platform),
)
config_entry = MockConfigEntry(domain=TEST_DOMAIN)
config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert "is using deprecated supported features values" in caplog.text
assert isinstance(entity.supported_features, int)
with pytest.raises(
HomeAssistantError,
match="Backup is not supported for update.test_deprecated_supported_features_ints_with_service_call",
):
await hass.services.async_call(
DOMAIN,
SERVICE_INSTALL,
{
ATTR_VERSION: "0.9.9",
ATTR_BACKUP: True,
ATTR_ENTITY_ID: "update.test_deprecated_supported_features_ints_with_service_call",
},
blocking=True,
)
async def test_custom_version_is_newer(hass: HomeAssistant) -> None:
"""Test UpdateEntity with overridden version_is_newer method."""
@ -1032,7 +940,7 @@ async def test_custom_version_is_newer(hass: HomeAssistant) -> None:
("supported_features", "extra_expected_attributes"),
[
(
0,
UpdateEntityFeature(0),
[
{},
{},