Skip to content

Commit

Permalink
Update some zdo_request calls that used tries
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Jul 14, 2023
1 parent cfe0915 commit 04db9d6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
16 changes: 12 additions & 4 deletions custom_components/zha_toolkit/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ async def rejoin(app, listener, ieee, cmd, data, service, params, event_data):

if method == 0:
# Works on HA 2021.12.10 & ZNP - rejoin is 1:
res = await src.zdo.request(0x0034, src.ieee, 0x01, params[p.TRIES])
res = await u.retry_wrapper(
src.zdo.request, 0x0034, src.ieee, 0x01, params[p.TRIES]
)
elif method == 1:
# Works on ZNP but apparently not on bellows:
triesToGo = params[p.TRIES]
Expand Down Expand Up @@ -181,15 +183,21 @@ async def rejoin(app, listener, ieee, cmd, data, service, params, event_data):
elif method == 2:
# Results in rejoin bit 0 on ZNP
LOGGER.debug("Using Method 2 for Leave")
res = await src.zdo.request(0x0034, src.ieee, 0x80, params[p.TRIES])
res = await u.retry_wrapper(
src.zdo.request, 0x0034, src.ieee, 0x80, params[p.TRIES]
)
elif method == 3:
# Results in rejoin and leave children bit set on ZNP
LOGGER.debug("Using Method 3 for Leave")
res = await src.zdo.request(0x0034, src.ieee, 0xFF, params[p.TRIES])
res = await u.retry_wrapper(
src.zdo.request, 0x0034, src.ieee, 0xFF, params[p.TRIES]
)
elif method == 4:
# Results in rejoin and leave children bit set on ZNP
LOGGER.debug("Using Method 4 for Leave")
res = await src.zdo.request(0x0034, src.ieee, 0x83, params[p.TRIES])
res = await u.retry_wrapper(
src.zdo.request, 0x0034, src.ieee, 0x83, params[p.TRIES]
)
else:
res = "Not executed, no valid 'method' defined in code"

Expand Down
9 changes: 7 additions & 2 deletions custom_components/zha_toolkit/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ async def ota_notify(
await download_koenkk_ota(listener, ota_dir)
await download_sonoff_ota(listener, ota_dir)

# Get tries
tries = params[p.TRIES]

# Update internal image database
await ota_update_images(
app, listener, ieee, cmd, data, service, params, event_data
Expand All @@ -206,8 +209,10 @@ async def ota_notify(
LOGGER.debug("No OTA cluster found")
return
basic = device.endpoints[cluster.endpoint.endpoint_id].basic
await basic.bind()
ret = await basic.configure_reporting("sw_build_id", 0, 1800, 1)
await u.retry_wrapper(basic.bind, tries=tries)
ret = await u.retry_wrapper(
basic.configure_reporting, "sw_build_id", 0, 1800, 1
)
LOGGER.debug("Configured reporting: %s", ret)

ret = None
Expand Down
19 changes: 17 additions & 2 deletions custom_components/zha_toolkit/zdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ async def leave(app, listener, ieee, cmd, data, service, params, event_data):

parent = await u.get_device(app, listener, data)

res = await parent.zdo.request(zdo_t.ZDOCmd.Mgmt_Leave_req, ieee, 0x02)
# Get tries
tries = params[p.TRIES]

res = await u.retry_wrapper(
parent.zdo.request,
zdo_t.ZDOCmd.Mgmt_Leave_req,
ieee,
0x02,
tries=tries,
)
event_data["result_leave"] = res
LOGGER.debug("0x%04x: Mgmt_Leave_req: %s", parent.nwk, res)

Expand All @@ -42,13 +51,18 @@ async def ieee_ping(
# The device is the parent device
dev = app.get_device(ieee)

# Get tries
tries = params[p.TRIES]

LOGGER.debug("running 'ieee_ping' command to 0x%s", dev.nwk)

res = await dev.zdo.request(
res = await u.retry_wrapper(
dev.zdo.request,
zdo_t.ZDOCmd.IEEE_addr_req,
dev.nwk, # nwk_addr_of_interest
0x00, # request_type (0=single device response)
0x00, # Start index
tries=tries,
)
event_data["result_ping"] = res
LOGGER.debug("0x%04x: IEEE_addr_req: %s", dev.nwk, res)
Expand All @@ -68,6 +82,7 @@ async def zdo_join_with_code(
# + b"\xD7\x76\x0D\x5C\xAD\x63\x7F\x69\xCC"
# )
code = params[p.CODE]
# Note: Router is awake, there is no need for "tries"
res = await app.permit_with_key(node, code, 60)
link_key = bt.EmberKeyData(b"ZigBeeAlliance09")
res = await app._ezsp.addTransientLinkKey(node, link_key)
Expand Down

0 comments on commit 04db9d6

Please sign in to comment.