mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-06-22 19:15:19 +02:00
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:
+10
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user