diff --git a/homeassistant/components/update/__init__.py b/homeassistant/components/update/__init__.py index 40431332aafedf..8ec14b6e3a89f1 100644 --- a/homeassistant/components/update/__init__.py +++ b/homeassistant/components/update/__init__.py @@ -140,7 +140,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 + and UpdateEntityFeature.SPECIFIC_VERSION not in entity.supported_features_compat ): raise HomeAssistantError( f"Installing a specific version is not supported for {entity.entity_id}" @@ -149,7 +149,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: + ) and UpdateEntityFeature.BACKUP not in entity.supported_features_compat: raise HomeAssistantError(f"Backup is not supported for {entity.entity_id}") # Update is already in progress. diff --git a/tests/components/update/test_init.py b/tests/components/update/test_init.py index 92e63af4b6f9a7..67661d6936efa6 100644 --- a/tests/components/update/test_init.py +++ b/tests/components/update/test_init.py @@ -885,3 +885,75 @@ def supported_features(self) -> int: 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_setup(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, + )