Skip to content

Commit de9b462

Browse files
authored
Parse Hue SBL images properly (#23)
1 parent 142c39c commit de9b462

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies = [
1717
"click",
1818
"coloredlogs",
1919
"scapy",
20-
"zigpy>=0.48.1",
20+
"zigpy>=0.53.0",
2121
"bellows>=0.34.3",
2222
"zigpy-deconz>=0.18.0",
2323
"zigpy-znp>=0.8.0",

zigpy_cli/ota.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pathlib
55

66
import click
7-
from zigpy.ota.image import ElementTagId, parse_ota_image
7+
from zigpy.ota.image import ElementTagId, HueSBLOTAImage, parse_ota_image
88
from zigpy.ota.validators import validate_ota_image
99

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

36+
print(f)
37+
print(f"Type: {type(image)}")
3638
print(f"Header: {image.header}")
37-
print(f"Number of subelements: {len(image.subelements)}")
39+
40+
if hasattr(image, "subelements"):
41+
print(f"Number of subelements: {len(image.subelements)}")
3842

3943
try:
4044
result = validate_ota_image(image)
@@ -52,9 +56,12 @@ def info(files):
5256
def dump_firmware(input, output):
5357
image, _ = parse_ota_image(input.read())
5458

55-
for subelement in image.subelements:
56-
if subelement.tag_id == ElementTagId.UPGRADE_IMAGE:
57-
output.write(subelement.data)
58-
break
59+
if isinstance(image, HueSBLOTAImage):
60+
output.write(image.data)
5961
else:
60-
LOGGER.warning("Image has no UPGRADE_IMAGE subelements")
62+
for subelement in image.subelements:
63+
if subelement.tag_id == ElementTagId.UPGRADE_IMAGE:
64+
output.write(subelement.data)
65+
break
66+
else:
67+
LOGGER.warning("Image has no UPGRADE_IMAGE subelements")

0 commit comments

Comments
 (0)