Skip to content

Clamp the siren duration to the Start warning field's range - #1069

Open
zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/clamp-siren-duration-to-uint16
Open

zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/clamp-siren-duration-to-uint16

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator

Summary

Severity: low (the audit's estimate)

Home Assistant's siren.turn_on accepts any non-negative duration, but the Start warning command's Warning Duration is a uint16, in seconds (ZCL R8 8.4.2.2.1.1 and 8.4.2.2.1.5). A duration above 65535 seconds made zigpy fail to serialize the command with a ValueError, so the siren never turned on. This clamps the duration to 65535 seconds.

Changes

  • zha/application/platforms/siren.py: a MAX_DURATION = 0xFFFF constant; AdvancedSiren.async_turn_on and BasicSiren.async_turn_on clamp the requested duration to it, for the command and the entity's off timer.
  • tests/test_siren.py: test_siren_duration_above_uint16, for the full and the basic siren, serializing the command for real and checking the sent Warning Duration.

Testing

  • The new test fails at 2da1a5b with ValueError: Failed to convert warning_duration=86400 … and passes with the fix.
  • tests/test_siren.py and tests/test_select.py pass; pre-commit (codespell, ruff, mypy) passes on the changed files.

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

Fixes #1068

Warning Duration is a uint16 (ZCL R8 8.4.2.2.1.1), but Home Assistant's
`siren.turn_on` accepts any non-negative duration. A duration above
65535 seconds failed to serialize with a ValueError, so the siren never
turned on. Clamp it to 65535 seconds, for the command and the entity's
off timer.
@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 24, 2026
@codecov

codecov Bot commented Nov 24, 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 (b214273).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1069   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          61       61           
  Lines       10870    10871    +1     
=======================================
+ Hits        10597    10598    +1     
  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.

@puddly

puddly commented Nov 24, 2026

Copy link
Copy Markdown
Member

I don't think someone is going to try to turn on a siren for 18 hours with an automation...

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator Author

Agreed, it's an edge case: any realistic duration works today, and only a duration above 65535 s (about 18 h) fails, with a ValueError from zigpy serializing the Start warning command, rather than being clamped. The audit rated it low severity for that reason.

If it isn't worth carrying, it can be closed together with #1068 — that's your call. If you'd rather keep it, it now conflicts with #1067 (the same lines in BasicSiren.async_turn_on); say so here and the next run pushes the resolution.

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.

Siren fails to turn on with a duration above 65535 seconds

2 participants