Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Ledvance OTA image versions to pick only the latest images #964

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_ota_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,29 @@ async def test_ledvance_refresh_list(
"salesRegion": "us",
"length": 170800,
},
# Old version but shows up after the new version in the OTA list
{
"blob": None,
"identity": {
"company": 4489,
"product": 13,
"version": {
"major": 0,
"minor": 2,
"build": 428,
"revision": 40,
},
},
"releaseNotes": "",
"shA256": sha_2,
"name": "A19_TW_10_year_IMG000D_00102428-encrypted.ota",
"productName": "A19 TW 10 year",
"fullName": fn_2,
"extension": ".ota",
"released": "2015-02-28T16:42:50",
"salesRegion": "us",
"length": 170800,
},
]
}
]
Expand Down
25 changes: 21 additions & 4 deletions zigpy/ota/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,21 @@ class LedvanceImage:
@classmethod
def new(cls, data):
identity = data["identity"]
ver = identity["version"]
version_parts = identity["version"]

# This matches the OTA file's `image_version` for every image
version = (
(version_parts["major"] << 24)
| (version_parts["minor"] << 16)
| (version_parts["build"] << 8)
| (version_parts["revision"] << 0)
)

res = cls(manufacturer_id=identity["company"], image_type=identity["product"])
res = cls(
manufacturer_id=identity["company"],
image_type=identity["product"],
version=version,
)
res.file_version = int(data["fullName"].split("/")[1], 16)
res.image_size = data["length"]
res.url = (
Expand All @@ -206,8 +218,8 @@ def new(cls, data):
"Company": identity["company"],
"Product": identity["product"],
"Version": (
f"{ver['major']}.{ver['minor']}"
f".{ver['build']}.{ver['revision']}"
f"{version_parts['major']}.{version_parts['minor']}"
f".{version_parts['build']}.{version_parts['revision']}"
),
}
)
Expand Down Expand Up @@ -280,6 +292,11 @@ async def refresh_firmware_list(self) -> None:
self._cache.clear()
for fw in fw_lst["firmwares"]:
img = LedvanceImage.new(fw)

# Ignore earlier images
if img.key in self._cache and self._cache[img.key].version > img.version:
continue

self._cache[img.key] = img
self.update_expiration()

Expand Down