Suppress update entity's update_percentage when update not in progress (#129397)

This commit is contained in:
Erik Montnemery 2024-10-29 17:56:09 +01:00 committed by GitHub
parent ecbb417736
commit 45fb21e32d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -453,7 +453,7 @@ class UpdateEntity(
# Otherwise, we use the internal progress value. # Otherwise, we use the internal progress value.
if UpdateEntityFeature.PROGRESS in self.supported_features_compat: if UpdateEntityFeature.PROGRESS in self.supported_features_compat:
in_progress = self.in_progress in_progress = self.in_progress
update_percentage = self.update_percentage update_percentage = self.update_percentage if in_progress else None
if type(in_progress) is not bool and isinstance(in_progress, int): if type(in_progress) is not bool and isinstance(in_progress, int):
update_percentage = in_progress update_percentage = in_progress
in_progress = True in_progress = True

View file

@ -589,6 +589,16 @@ async def test_entity_already_in_progress(
blocking=True, blocking=True,
) )
# Check update percentage is suppressed when in_progress is False
entity = next(
entity for entity in mock_update_entities if entity.entity_id == entity_id
)
entity._attr_in_progress = False
entity.async_write_ha_state()
state = hass.states.get(entity_id)
assert state.attributes[ATTR_IN_PROGRESS] is False
assert state.attributes[ATTR_UPDATE_PERCENTAGE] is None
async def test_entity_without_progress_support( async def test_entity_without_progress_support(
hass: HomeAssistant, hass: HomeAssistant,