fix(channels): drop hardcoded 0-7 limit on set-scope endpoint

The /api/channels/<idx>/scope route rejected idx>=8 with "Channel index
out of range (0-7)" even though current firmwares expose up to 40 slots
(send_device_query reports max_channels=40 in our logs). Users couldn't
set a region scope on channels like #ubot (idx 8) or #swietokrzyskie
(idx 15) — the UI showed the modal but Save returned 400.

Use device_manager._max_channels (set from send_device_query at connect)
as the upper bound, with 8 as a safe fallback if the DM is unreachable.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-06-08 11:06:30 +02:00
parent fef6845c03
commit 7e9ff2e3aa
+10 -2
View File
@@ -4087,8 +4087,16 @@ def set_channel_scope_api(index):
Body: {"region_id": int | null}. null removes the mapping (firmware default applies).
"""
try:
if index < 0 or index > 7:
return jsonify({'success': False, 'error': 'Channel index out of range (0-7)'}), 400
# Use the device-reported max so we don't reject valid slots on
# firmwares that expose more than 8 channels (current firmware reports
# max_channels=40). Fall back to 8 when the DM isn't reachable.
dm = _get_dm()
max_channels = getattr(dm, '_max_channels', 8) if dm else 8
if index < 0 or index >= max_channels:
return jsonify({
'success': False,
'error': f'Channel index out of range (0-{max_channels - 1})',
}), 400
data = request.get_json() or {}
if 'region_id' not in data: