Add option to disable channel-number auto-detection#579
Merged
Conversation
Some Dahua firmwares respond to HTTP snapshot at index 0 but only stream RTSP on channel=1. The existing heuristic in _async_update_data assumes that a successful snapshot(0) means the camera is 0-indexed and resets _channel_number = _channel (e.g. 0), which then produces RTSP URLs with channel=0 and HTTP 404 from the camera. Add a new options-flow toggle "auto_detect_channel" (default True, so existing setups are unaffected). When disabled, the channel-reset block is skipped and _channel_number stays at channel + 1, letting users recover when the heuristic misfires on their model. - const.py: new CONF_AUTO_DETECT_CHANNEL constant - __init__.py: gate the snapshot reset on the option, log its state - config_flow.py: surface the toggle in the OptionsFlow alongside the platform enable/disable switches
Without this entry the new checkbox renders as the raw snake_case key in the English UI. Other locales fall back to en.json so a single translation update is enough.
Contributor
Author
|
N.B. Prepared with Claude Code usage (opus 4.7 model). |
rroller
approved these changes
May 31, 2026
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add option to disable channel-number auto-detection
Closes #578.
Problem
The coordinator's
_async_update_dataprobesasync_get_snapshot(0)and, on success, resetsself._channel_number = self._channel(line ~272 in__init__.py). The heuristic exists because some Dahua firmwares index channels from 0 instead of 1, and the camera's HTTP CGI endpoint reveals which family it belongs to.On some cameras (full details in the linked issue) the HTTP snapshot endpoint cheerfully returns a JPEG at index 0 even though RTSP only streams on
channel=1. The heuristic then mis-classifies the camera as 0-indexed and the resultingrtsp://.../cam/realmonitor?channel=0&subtype=0returns HTTP 404 forever after.There's currently no way for affected users to opt out.
Change
Add an
auto_detect_channeloption to the integration's OptionsFlow (defaultTrue, identical to current behavior). When disabled, the snapshot probe and channel reset are skipped, and_channel_numberstays atchannel + 1.Existing installs are not affected — the new key isn't present in their
optionsdict, sooptions.get(CONF_AUTO_DETECT_CHANNEL, True)returns the defaultTrueand the original code path runs.Files
const.py— newCONF_AUTO_DETECT_CHANNELconstant.__init__.py— gate the snapshot reset on the new option, mention the toggle in the DEBUG log.config_flow.py— surface the toggle in the existingDahuaOptionsFlowHandlerschema alongside the platform booleans.How to use
After updating, Settings → Devices & services → Dahua (the affected camera) → Configure → uncheck "auto_detect_channel". The change takes effect on the next coordinator refresh (or immediately if the entry is reloaded).
Testing
Verified on a real install: with the toggle off,
_channel_numberstays at 1, RTSP stream comes up,camera.recordproduces a valid MP4. Other cameras in the same install (which rely on the heuristic) keep the option on and are unaffected.python -c "import ast; ast.parse(open(f).read())"clean on the three changed files.