Skip to content

Fix for gateway with single inverter, web UI fixes - #2742

Merged
springfall2008 merged 6 commits into
mainfrom
fixes
Oct 9, 2025
Merged

springfall2008 merged 6 commits into
mainfrom
fixes

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Fix entity search in web UI
Fix for gateway with single inverter
Fix component light mode in web UI

Fix entity search in web UI
Fix component light mode in web UI
@springfall2008
springfall2008 requested a review from Copilot October 9, 2025 08:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/predbat/gecloud.py
Comment on lines +661 to +662
if not devices["ems"] and devices["gateway"] and len(batteries) > 1:
# Only use gateway as main control if we have multiple batteries

Copilot AI Oct 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread apps/predbat/gecloud.py

gateway_device = None
if devices_dict["gateway"]:
if not ems_device and devices_dict["gateway"] and len(device_list) > 1:

Copilot AI Oct 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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:

Copilot uses AI. Check for mistakes.
throw new Error('Failed to load entities');
}
allEntities = await response.json();

Copilot AI Oct 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string escaping approach is vulnerable to injection attacks. Consider using proper JSON encoding instead of manual string replacement for safer entity ID handling.

Copilot uses AI. Check for mistakes.

Object.keys(groups).forEach(groupName => {
html += '<div class="entity-group-header">' + groupName + '</div>';
groups[groupName].forEach((entity, index) => {

Copilot AI Oct 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@springfall2008
springfall2008 merged commit 636dacf into main Oct 9, 2025
1 check passed
@springfall2008
springfall2008 deleted the fixes branch October 9, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants