Skip to content

Commit

Permalink
Parse Hue SBL images properly (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Feb 9, 2023
1 parent 142c39c commit de9b462
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"click",
"coloredlogs",
"scapy",
"zigpy>=0.48.1",
"zigpy>=0.53.0",
"bellows>=0.34.3",
"zigpy-deconz>=0.18.0",
"zigpy-znp>=0.8.0",
Expand Down
21 changes: 14 additions & 7 deletions zigpy_cli/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib

import click
from zigpy.ota.image import ElementTagId, parse_ota_image
from zigpy.ota.image import ElementTagId, HueSBLOTAImage, parse_ota_image
from zigpy.ota.validators import validate_ota_image

from zigpy_cli.cli import cli
Expand Down Expand Up @@ -33,8 +33,12 @@ def info(files):
if rest:
LOGGER.warning("Image has trailing data %s: %r", f, rest)

print(f)
print(f"Type: {type(image)}")
print(f"Header: {image.header}")
print(f"Number of subelements: {len(image.subelements)}")

if hasattr(image, "subelements"):
print(f"Number of subelements: {len(image.subelements)}")

try:
result = validate_ota_image(image)
Expand All @@ -52,9 +56,12 @@ def info(files):
def dump_firmware(input, output):
image, _ = parse_ota_image(input.read())

for subelement in image.subelements:
if subelement.tag_id == ElementTagId.UPGRADE_IMAGE:
output.write(subelement.data)
break
if isinstance(image, HueSBLOTAImage):
output.write(image.data)
else:
LOGGER.warning("Image has no UPGRADE_IMAGE subelements")
for subelement in image.subelements:
if subelement.tag_id == ElementTagId.UPGRADE_IMAGE:
output.write(subelement.data)
break
else:
LOGGER.warning("Image has no UPGRADE_IMAGE subelements")

0 comments on commit de9b462

Please sign in to comment.