mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Improve Shelly RPC device update progress (#114566)
Co-authored-by: Shay Levy <levyshay1@gmail.com> Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
31cd41adb8
commit
c8f282c8bc
@ -222,7 +222,7 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize update entity."""
|
"""Initialize update entity."""
|
||||||
super().__init__(coordinator, key, attribute, description)
|
super().__init__(coordinator, key, attribute, description)
|
||||||
self._ota_in_progress: bool = False
|
self._ota_in_progress: bool | int = False
|
||||||
self._attr_release_url = get_release_url(
|
self._attr_release_url = get_release_url(
|
||||||
coordinator.device.gen, coordinator.model, description.beta
|
coordinator.device.gen, coordinator.model, description.beta
|
||||||
)
|
)
|
||||||
@ -237,14 +237,13 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
|||||||
@callback
|
@callback
|
||||||
def _ota_progress_callback(self, event: dict[str, Any]) -> None:
|
def _ota_progress_callback(self, event: dict[str, Any]) -> None:
|
||||||
"""Handle device OTA progress."""
|
"""Handle device OTA progress."""
|
||||||
if self._ota_in_progress:
|
if self.in_progress is not False:
|
||||||
event_type = event["event"]
|
event_type = event["event"]
|
||||||
if event_type == OTA_BEGIN:
|
if event_type == OTA_BEGIN:
|
||||||
self._attr_in_progress = 0
|
self._ota_in_progress = 0
|
||||||
elif event_type == OTA_PROGRESS:
|
elif event_type == OTA_PROGRESS:
|
||||||
self._attr_in_progress = event["progress_percent"]
|
self._ota_in_progress = event["progress_percent"]
|
||||||
elif event_type in (OTA_ERROR, OTA_SUCCESS):
|
elif event_type in (OTA_ERROR, OTA_SUCCESS):
|
||||||
self._attr_in_progress = False
|
|
||||||
self._ota_in_progress = False
|
self._ota_in_progress = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@ -262,6 +261,11 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
|||||||
|
|
||||||
return self.installed_version
|
return self.installed_version
|
||||||
|
|
||||||
|
@property
|
||||||
|
def in_progress(self) -> bool | int:
|
||||||
|
"""Update installation in progress."""
|
||||||
|
return self._ota_in_progress
|
||||||
|
|
||||||
async def async_install(
|
async def async_install(
|
||||||
self, version: str | None, backup: bool, **kwargs: Any
|
self, version: str | None, backup: bool, **kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -292,7 +296,7 @@ class RpcUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
|||||||
await self.coordinator.async_shutdown_device_and_start_reauth()
|
await self.coordinator.async_shutdown_device_and_start_reauth()
|
||||||
else:
|
else:
|
||||||
self._ota_in_progress = True
|
self._ota_in_progress = True
|
||||||
LOGGER.debug("OTA update call successful")
|
LOGGER.info("OTA update call for %s successful", self.coordinator.name)
|
||||||
|
|
||||||
|
|
||||||
class RpcSleepingUpdateEntity(
|
class RpcSleepingUpdateEntity(
|
||||||
|
@ -255,6 +255,16 @@ async def test_rpc_update(
|
|||||||
{ATTR_ENTITY_ID: entity_id},
|
{ATTR_ENTITY_ID: entity_id},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert mock_rpc_device.trigger_ota_update.call_count == 1
|
||||||
|
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state.state == STATE_ON
|
||||||
|
assert state.attributes[ATTR_INSTALLED_VERSION] == "1"
|
||||||
|
assert state.attributes[ATTR_LATEST_VERSION] == "2"
|
||||||
|
assert state.attributes[ATTR_IN_PROGRESS] is True
|
||||||
|
assert state.attributes[ATTR_RELEASE_URL] == GEN2_RELEASE_URL
|
||||||
|
|
||||||
inject_rpc_device_event(
|
inject_rpc_device_event(
|
||||||
monkeypatch,
|
monkeypatch,
|
||||||
mock_rpc_device,
|
mock_rpc_device,
|
||||||
@ -270,14 +280,7 @@ async def test_rpc_update(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert mock_rpc_device.trigger_ota_update.call_count == 1
|
assert hass.states.get(entity_id).attributes[ATTR_IN_PROGRESS] == 0
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
|
||||||
assert state.state == STATE_ON
|
|
||||||
assert state.attributes[ATTR_INSTALLED_VERSION] == "1"
|
|
||||||
assert state.attributes[ATTR_LATEST_VERSION] == "2"
|
|
||||||
assert state.attributes[ATTR_IN_PROGRESS] == 0
|
|
||||||
assert state.attributes[ATTR_RELEASE_URL] == GEN2_RELEASE_URL
|
|
||||||
|
|
||||||
inject_rpc_device_event(
|
inject_rpc_device_event(
|
||||||
monkeypatch,
|
monkeypatch,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user