From 7e9ff2e3aa3d215833b2d61e8c15cad62040bf2c Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 8 Jun 2026 11:06:30 +0200 Subject: [PATCH] fix(channels): drop hardcoded 0-7 limit on set-scope endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /api/channels//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 --- app/routes/api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/routes/api.py b/app/routes/api.py index 9e95eeb..b27ea9c 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -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: