Skip to content

Don't append redundant palette_colors param to URLs#41

Draft
balloob with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-color-palette-url
Draft

Don't append redundant palette_colors param to URLs#41
balloob with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-color-palette-url

Conversation

Copilot AI commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

The frontend appends palette_colors to screenshot URLs even when it's redundant, creating unnecessarily long URLs since the backend defaults palette_colors to colors when empty (http.js:165-168).

Changes

Modified buildUrl() in puppet/ha-puppet/html/index.html to skip palette_colors parameter in multiple redundant scenarios:

Device mode:

// Only add palette_colors if all conditions are met:
// 1. palette_colors is set
// 2. palette_colors differs from device's palette_colors config
// 3. palette_colors differs from colors param (backend defaults palette_colors to colors)
// 4. Either colors param is being added OR palette_colors differs from device's colors
//    (if colors matches device and is omitted, don't add palette_colors if it also matches device colors)
if (palette_colors && 
    palette_colors !== (currentDeviceConfig.palette_colors || "") && 
    palette_colors !== colors &&
    (colors || palette_colors !== (currentDeviceConfig.colors || ""))) {
  params.append("palette_colors", palette_colors);
}

Non-device mode:

// Only add palette_colors if it's different from colors
if (palette_colors && palette_colors !== colors) {
  params.append("palette_colors", palette_colors);
}

Result

The palette_colors parameter is now omitted when:

  1. It equals colors parameter
  2. It equals device's palette_colors config
  3. It equals device's colors AND colors param is not being added

Examples:

Before: ?colors=000000,FFFFFF&palette_colors=000000,FFFFFF
After: ?colors=000000,FFFFFF

Before (device mode, both match device): ?viewport=800x600&palette_colors=FF0000,00FF00
After (device mode, both match device): ?viewport=800x600

URLs are shorter and backend behavior is unchanged.

Testing

Test Results

All test cases passed including edge cases for device mode configurations.

Original prompt

In frontend, don't append color pallette param to the generated URL when it is equal to colors, as it is treated the same in the backend. (verify that)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix URL generation by excluding color palette when equal to colors Don't append palette_colors param when it equals colors Nov 21, 2025
Copilot AI requested a review from balloob November 21, 2025 16:06
Comment thread puppet/ha-puppet/html/index.html Outdated

if (palette_colors && palette_colors !== (currentDeviceConfig.palette_colors || "")) {
// Only add palette_colors if it's different from colors (backend defaults palette_colors to colors when empty)
if (palette_colors && palette_colors !== (currentDeviceConfig.palette_colors || "") && palette_colors !== colors) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot we should also not add palette_colors if it's the same as currentDeviceConfig.colors and there is no colors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in a408c86. Added check (colors || palette_colors !== (currentDeviceConfig.colors || "")) to skip palette_colors when it equals device's colors and colors param is not being added.

Test Results

Copilot AI and others added 2 commits November 21, 2025 19:33
…m is not added

Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Copilot AI changed the title Don't append palette_colors param when it equals colors Don't append redundant palette_colors param to URLs Nov 21, 2025
Copilot AI requested a review from balloob November 21, 2025 19:36
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