mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Report update_percentage in shelly update entity (#129382)
Co-authored-by: Shay Levy <levyshay1@gmail.com>
This commit is contained in:
parent
df16e6d022
commit
2d2f55a4df
@ -238,7 +238,8 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
||||
) -> None:
|
||||
"""Initialize update entity."""
|
||||
super().__init__(coordinator, key, attribute, description)
|
||||
self._ota_in_progress: bool | int = False
|
||||
self._ota_in_progress = False
|
||||
self._ota_progress_percentage: int | None = None
|
||||
self._attr_release_url = get_release_url(
|
||||
coordinator.device.gen, coordinator.model, description.beta
|
||||
)
|
||||
@ -256,11 +257,12 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
||||
if self.in_progress is not False:
|
||||
event_type = event["event"]
|
||||
if event_type == OTA_BEGIN:
|
||||
self._ota_in_progress = 0
|
||||
self._ota_progress_percentage = 0
|
||||
elif event_type == OTA_PROGRESS:
|
||||
self._ota_in_progress = event["progress_percent"]
|
||||
self._ota_progress_percentage = event["progress_percent"]
|
||||
elif event_type in (OTA_ERROR, OTA_SUCCESS):
|
||||
self._ota_in_progress = False
|
||||
self._ota_progress_percentage = None
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
@ -278,10 +280,15 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
||||
return self.installed_version
|
||||
|
||||
@property
|
||||
def in_progress(self) -> bool | int:
|
||||
def in_progress(self) -> bool:
|
||||
"""Update installation in progress."""
|
||||
return self._ota_in_progress
|
||||
|
||||
@property
|
||||
def update_percentage(self) -> int | None:
|
||||
"""Update installation progress."""
|
||||
return self._ota_progress_percentage
|
||||
|
||||
async def async_install(
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
@ -310,6 +317,7 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
||||
await self.coordinator.async_shutdown_device_and_start_reauth()
|
||||
else:
|
||||
self._ota_in_progress = True
|
||||
self._ota_progress_percentage = None
|
||||
LOGGER.debug("OTA update call for %s successful", self.coordinator.name)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user