Skip to content

Commit

Permalink
Fix firmware update failure (#103277)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored and frenck committed Nov 3, 2023
1 parent 1a82337 commit 910654b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions homeassistant/components/zwave_js/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import asyncio
from collections import Counter
from collections.abc import Callable
from dataclasses import asdict, dataclass
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import Any, Final

Expand Down Expand Up @@ -54,7 +54,7 @@ class ZWaveNodeFirmwareUpdateExtraStoredData(ExtraStoredData):
def as_dict(self) -> dict[str, Any]:
"""Return a dict representation of the extra data."""
return {
ATTR_LATEST_VERSION_FIRMWARE: asdict(self.latest_version_firmware)
ATTR_LATEST_VERSION_FIRMWARE: self.latest_version_firmware.to_dict()
if self.latest_version_firmware
else None
}
Expand Down Expand Up @@ -339,19 +339,25 @@ async def async_added_to_hass(self) -> None:
and (latest_version := state.attributes.get(ATTR_LATEST_VERSION))
is not None
and (extra_data := await self.async_get_last_extra_data())
):
self._attr_latest_version = latest_version
self._latest_version_firmware = (
ZWaveNodeFirmwareUpdateExtraStoredData.from_dict(
and (
latest_version_firmware := ZWaveNodeFirmwareUpdateExtraStoredData.from_dict(
extra_data.as_dict()
).latest_version_firmware
)
# If we have no state or latest version to restore, we can set the latest
):
self._attr_latest_version = latest_version
self._latest_version_firmware = latest_version_firmware
# If we have no state or latest version to restore, or the latest version is
# the same as the installed version, we can set the latest
# version to installed so that the entity starts as off. If we have partial
# restore data due to an upgrade to an HA version where this feature is released
# from one that is not the entity will start in an unknown state until we can
# correct on next update
elif not state or not latest_version:
elif (
not state
or not latest_version
or latest_version == self._attr_installed_version
):
self._attr_latest_version = self._attr_installed_version

# Spread updates out in 5 minute increments to avoid flooding the network
Expand Down

0 comments on commit 910654b

Please sign in to comment.