Skip to content

Commit d4afc12

Browse files
committed
Ensure compatibility with latest released zigpy version (#27)
1 parent fc81322 commit d4afc12

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

zigpy_znp/zigbee/application.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from zigpy.zdo.types import ZDOCmd, ZDOHeader, CLUSTERS as ZDO_CLUSTERS
1616

1717
from zigpy.zcl import clusters
18-
from zigpy.types import ExtendedPanId, deserialize as list_deserialize
18+
from zigpy.types import (
19+
ExtendedPanId,
20+
deserialize as list_deserialize,
21+
Struct as ZigpyStruct,
22+
)
1923
from zigpy.exceptions import DeliveryError
2024

2125
import zigpy_znp.config as conf
@@ -156,7 +160,23 @@ def _receive_zdo_message(
156160
field_names, field_types = ZDO_CLUSTERS[cluster]
157161
assert set(zdo_kwargs) == set(field_names)
158162

159-
zdo_args = [t(zdo_kwargs[n]) for n, t in zip(field_names, field_types)]
163+
# Type cast all of the field args and kwargs
164+
zdo_args = []
165+
166+
for name, field_type in zip(field_names, field_types):
167+
zdo_arg = zdo_kwargs[name]
168+
169+
if issubclass(field_type, ZigpyStruct) and hasattr(ZigpyStruct, "_fields"):
170+
# Old-style zigpy structs do not have "copy constructors"
171+
new_obj = field_type()
172+
173+
for field_name, _ in new_obj._fields:
174+
setattr(new_obj, field_name, getattr(zdo_arg, field_name))
175+
else:
176+
new_obj = field_type(zdo_arg)
177+
178+
zdo_args.append(zdo_arg)
179+
160180
message = t.serialize_list([t.uint8_t(tsn)] + zdo_args)
161181

162182
LOGGER.debug("Pretending we received a ZDO message: %s", message)

0 commit comments

Comments
 (0)