Skip to content

Report the arrival sensor's battery voltage within the device tracker keepalive - #1051

Draft
zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/report-arrival-sensor-voltage-within-keepalive
Draft

zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/report-arrival-sensor-voltage-within-keepalive

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator

Summary

Severity: medium (the audit's estimate)

The device tracker for the SmartThings arrival sensor (tagV4) treats the device as connected only when it was seen within the last 60 seconds, but it configured battery voltage reporting every one to three hours, so a tag that is home showed as away almost all of the time. The SmartThingsTagV4 quirk tries to set a 45 second report by overriding configure_reporting(), which ZHA never calls: it configures reporting through configure_reporting_multiple(). This PR configures the 45 second battery voltage report in the tracker entity itself.

Changes

  • DeviceScannerEntity now asks for battery_voltage reporting with min_interval=45, max_interval=45, reportable_change=1 (the quirk's intended values) instead of 3600/10800. The tracker only matches the 0x8000 device type that this quirk sets (or an endpoint a user's device_config override turns into a device_tracker, which needs the same heartbeat), and the cluster config aggregation merges non-override reporting configs to the tightest interval, so this config wins over the Battery sensor's for the same attribute and no other device changes.
  • The quirk's now redundant configure_reporting() override is left for zigpy/zha-device-handlers.

Open items

  • The bug and the fix follow from the code; neither was observed on a device.
  • A 45 second report against the 60 second keepalive leaves a 15 second margin, so one lost report can show the tag away until the next one arrives (when a 30–45 second refresh falls in the gap). Both values are the existing ones (the quirk's interval and the tracker's keepalive); Zigbee2MQTT uses a 60 second report with a 100 second timeout for this device.

Testing

  • New test_device_tracker_reporting_within_keepalive joins a device with the SmartThingsTagV4 quirk and checks that the maximum battery voltage reporting interval ZHA configures is within the tracker's keepalive interval. It fails at 2da1a5b (assert 10800 <= 60) and passes with the fix.
  • tests/test_device_tracker.py, tests/test_cluster_config.py, tests/test_sensor.py and tests/test_discover.py pass (1277 tests), as does the full suite (1782 tests); pre-commit (codespell, ruff, mypy) passes.

Opened by the scheduled code audit; not requested by a maintainer.

Fixes #1050

The device tracker is connected only while the device was seen within the
last 60 seconds, but it configured battery voltage reporting at 1-3 hours.
The SmartThings tagV4 quirk meant to raise this to 45 seconds by overriding
`configure_reporting`, which ZHA never calls (it configures reporting with
`configure_reporting_multiple`), so the tracker showed the device away almost
all the time. Configure the 45 second heartbeat in the tracker itself.
@zigpy-review-bot zigpy-review-bot added bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bugfix This PR fixes a bug bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) labels Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (2da1a5b) to head (fb209da).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1051   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          61       61           
  Lines       10870    10870           
=======================================
  Hits        10597    10597           
  Misses        273      273           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SmartThings arrival sensor device tracker shows away almost all the time

1 participant