Skip to content

Commit

Permalink
Merge pull request #182 from mdeweerd/dev
Browse files Browse the repository at this point in the history
Fix default exceptions for retry
  • Loading branch information
mdeweerd authored Jul 15, 2023
2 parents 9ac2bc1 + 88d21e7 commit d2c4b2d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions STATS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Badges showing number of downloads per version

- ![badge latest](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/latest/total.svg)
- ![badge v0.9.5](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.9.5/total.svg)
- ![badge v0.9.4](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.9.4/total.svg)
- ![badge v0.9.3](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.9.3/total.svg)
- ![badge v0.9.2](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.9.2/total.svg)
Expand Down
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
11 changes: 8 additions & 3 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, tries=tries
)
LOGGER.debug("Configured reporting: %s", ret)

ret = None
Expand All @@ -220,7 +225,7 @@ async def ota_notify(
0, # cmd_id
*cmd_args,
# expect_reply = True,
tries=params[p.TRIES],
tries=tries,
)

LOGGER.debug("Sent image notify command to 0x%04x: %s", device.nwk, ret)
Expand Down
10 changes: 4 additions & 6 deletions custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,10 @@ async def retry(
if retry_exceptions is None:
# Default list
retry_exceptions = (
(
DeliveryError,
ControllerException,
asyncio.CancelledError,
asyncio.TimeoutError,
),
DeliveryError,
ControllerException,
asyncio.CancelledError,
asyncio.TimeoutError,
)

while True:
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
2 changes: 1 addition & 1 deletion examples/service_call_read_basic_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#
service: script.1645121662206
data:
entity_name: button.tz3000_dbou1ap4_ts0505a_9afc91fe_identify
entity_name: button.bureau_identify
csv: ../www/lidl_basic_cluster.csv

0 comments on commit d2c4b2d

Please sign in to comment.