Repository navigation
Fix for gateway with single inverter, web UI fixes - #2742
Conversation
Fix entity search in web UI Fix component light mode in web UI
There was a problem hiding this comment.
Pull Request Overview
This PR implements fixes for both backend gateway logic and frontend web UI components. The changes address issues with single inverter gateway configurations and improve the web UI search functionality and component display.
- Fixed gateway logic to only use gateway device when multiple batteries are present
- Added entity search functionality with improved autocomplete dropdown
- Enhanced component styling for better light/dark mode compatibility
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| apps/predbat/web_helper.py | Added new entity search JavaScript and CSS functions for improved entity selection UI |
| apps/predbat/web.py | Refactored entity selection to use new search functionality instead of dropdown |
| apps/predbat/gecloud.py | Fixed gateway device selection logic to only use gateway with multiple batteries |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if not devices["ems"] and devices["gateway"] and len(batteries) > 1: | ||
| # Only use gateway as main control if we have multiple batteries |
There was a problem hiding this comment.
The condition checks len(batteries) but batteries is used before this check on line 659. If devices["ems"] exists, this condition will be False and batteries will remain as devices["battery"], but if devices["ems"] doesn't exist and there's only one battery, the gateway logic won't trigger, which appears correct. However, the logic flow could be clearer.
|
|
||
| gateway_device = None | ||
| if devices_dict["gateway"]: | ||
| if not ems_device and devices_dict["gateway"] and len(device_list) > 1: |
There was a problem hiding this comment.
The condition checks len(device_list) > 1 but device_list may not include all battery devices at this point. The logic should check the original battery count like len(devices_dict.get('battery', [])) to be consistent with the previous fix.
| if not ems_device and devices_dict["gateway"] and len(device_list) > 1: | |
| if not ems_device and devices_dict["gateway"] and len(devices_dict.get('battery', [])) > 1: |
| throw new Error('Failed to load entities'); | ||
| } | ||
| allEntities = await response.json(); | ||
|
|
There was a problem hiding this comment.
The string escaping approach is vulnerable to injection attacks. Consider using proper JSON encoding instead of manual string replacement for safer entity ID handling.
|
|
||
| Object.keys(groups).forEach(groupName => { | ||
| html += '<div class="entity-group-header">' + groupName + '</div>'; | ||
| groups[groupName].forEach((entity, index) => { |
There was a problem hiding this comment.
The entity ID is directly injected into the onclick handler without proper escaping, which could lead to XSS vulnerabilities. Use proper event listeners instead of inline onclick handlers.
Fix entity search in web UI
Fix for gateway with single inverter
Fix component light mode in web UI