Skip to content

Commit

Permalink
Use supported_features_compat in update.install service (home-assista…
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jan 5, 2024
1 parent 2641e40 commit 6da82cf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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.
Expand Down
72 changes: 72 additions & 0 deletions tests/components/update/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 6da82cf

Please sign in to comment.