Skip to content

fix: ensure names match Klipper format#1749

Merged
pedrolamas merged 2 commits intofluidd-core:developfrom
pedrolamas:pedrolamas/fix-1748
Nov 24, 2025
Merged

fix: ensure names match Klipper format#1749
pedrolamas merged 2 commits intofluidd-core:developfrom
pedrolamas:pedrolamas/fix-1748

Conversation

@pedrolamas
Copy link
Member

@pedrolamas pedrolamas commented Nov 24, 2025

The differences in output of the Python split function and the Javascript equivalent one caused some issues when names have one or more spaces.

This attempts to fix that by making the behavior more approximate of what Klipper is using.

Fixes #1748

Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
@pedrolamas pedrolamas added this to the 1.35.1 milestone Nov 24, 2025
@pedrolamas pedrolamas requested a review from Copilot November 24, 2025 22:15
@pedrolamas pedrolamas added the GH - Bug Something isn't working label Nov 24, 2025
Copy link
Contributor

Copilot AI left a comment

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 attempts to fix name extraction issues caused by differences between Python's split() and JavaScript's split() methods, particularly when Klipper object names contain multiple consecutive spaces. The changes update string splitting logic across multiple getters and components to better match Klipper's naming format.

Key Changes:

  • Replace simple space splitting (split(' ')) with regex-based whitespace splitting (split(/\s+/)) to handle multiple consecutive spaces
  • Simplify MCU and mesh profile name extraction using substring() instead of split operations
  • Add trim() calls before splitting to handle leading/trailing whitespace

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/store/printer/getters.ts Updates name extraction for MCUs, steppers, sensors, heaters, and pins to handle multiple spaces
src/store/mesh/getters.ts Simplifies bed mesh profile name extraction using substring
src/store/macros/getters.ts Updates gcode_macro name extraction to use whitespace regex
src/store/helpers.ts Updates Trinamic driver name extraction for overheating warnings
src/components/widgets/thermals/ThermalChart.vue Updates thermal sensor name extraction in chart tooltips

))
.map(key => {
const name = key.split(' ', 2).pop() || ''
const name = key.trim().split(/\s+/).pop() || ''
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The sensor name extraction is incorrect for names containing multiple spaces. Using .pop() only returns the last word instead of the full name after the type prefix.

For example, if key is 'filament_switch_sensor my sensor':

  • key.trim().split(/\s+/) produces ['filament_switch_sensor', 'my', 'sensor']
  • .pop() returns only 'sensor' instead of 'my sensor'

The correct approach is to extract everything after the first space:

const name = key.substring(key.indexOf(' ') + 1).trim()

Or split with a limit and take the second part:

const name = key.trim().split(/\s+/, 2)[1] || ''
Suggested change
const name = key.trim().split(/\s+/).pop() || ''
const name = key.substring(key.indexOf(' ') + 1).trim()

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as it currently is.

state.config.uiSettings.warnings.warnOnStepperDriverOverheating
) {
const name = item.split(' ', 2).pop() || ''
const name = item.trim().split(/\s+/).pop() || ''
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The TMC driver name extraction uses .pop() which only returns the last word. While Klipper typically uses single-word stepper identifiers, using .pop() is less robust than extracting everything after the first space.

For consistency with the fix at line 731 and to handle potential edge cases, this should be:

const name = item.trim().split(/\s+/, 2)[1] || ''

This splits into at most 2 parts and takes the second part (everything after the first whitespace).

Suggested change
const name = item.trim().split(/\s+/).pop() || ''
const name = item.trim().split(/\s+/, 2)[1] || ''

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as is.

param.value[param.seriesName] != null
) {
const name = param.seriesName.split(' ', 2).pop()
const name = param.seriesName.trim().split(/\s+/).pop() || ''
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The thermal sensor name extraction is incorrect for names containing multiple spaces. Using .pop() only returns the last word instead of the full name after the type prefix.

For example, if param.seriesName is 'temperature_sensor my sensor':

  • .trim().split(/\s+/) produces ['temperature_sensor', 'my', 'sensor']
  • .pop() returns only 'sensor' instead of 'my sensor'

For consistency with the pattern used elsewhere, this should split with a limit:

const name = param.seriesName.trim().split(/\s+/, 2)[1] || ''

Or extract everything after the first space:

const spaceIndex = param.seriesName.trim().indexOf(' ')
const name = spaceIndex > 0 ? param.seriesName.substring(spaceIndex + 1).trim() : ''
Suggested change
const name = param.seriesName.trim().split(/\s+/).pop() || ''
const spaceIndex = param.seriesName.trim().indexOf(' ')
const name = spaceIndex > 0 ? param.seriesName.trim().substring(spaceIndex + 1).trim() : ''

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as is.

Comment on lines +360 to +362
const name = key.length > 4
? key.substring(4)
: 'mcu'
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The MCU name extraction doesn't handle multiple consecutive spaces correctly. If key is 'mcu secondary' (with two spaces), key.substring(4) returns ' secondary' with a leading space.

To match Klipper's Python split() behavior (which strips whitespace), the logic should be:

const name = key === 'mcu'
  ? 'mcu'
  : key.substring(4).trim()

This also makes the intent clearer than checking key.length > 4.

Suggested change
const name = key.length > 4
? key.substring(4)
: 'mcu'
const name = key === 'mcu'
? 'mcu'
: key.substring(4).trim()

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as is.

Comment on lines +592 to +594
const [type, ...restSplit] = key.trim().split(/\s+/)
const nameFromSplit = restSplit.pop()
const name = nameFromSplit || key
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The heater name extraction logic is incorrect for names containing multiple spaces.

For example, if key is 'heater_generic my hot bed':

  • key.trim().split(/\s+/) produces ['heater_generic', 'my', 'hot', 'bed']
  • restSplit becomes ['my', 'hot', 'bed']
  • restSplit.pop() returns only 'bed' instead of 'my hot bed'

This should be:

const [type, ...restSplit] = key.trim().split(/\s+/)
const name = restSplit.length > 0 ? restSplit.join(' ') : key

Or more concisely, follow the pattern used elsewhere:

const spaceIndex = key.trim().indexOf(' ')
const type = spaceIndex > 0 ? key.substring(0, spaceIndex) : key
const name = spaceIndex > 0 ? key.substring(spaceIndex + 1).trim() : key
Suggested change
const [type, ...restSplit] = key.trim().split(/\s+/)
const nameFromSplit = restSplit.pop()
const name = nameFromSplit || key
const spaceIndex = key.trim().indexOf(' ')
const type = spaceIndex > 0 ? key.substring(0, spaceIndex) : key
const name = spaceIndex > 0 ? key.substring(spaceIndex + 1).trim() : key

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as is.

const name = key.startsWith('stepper_')
? key.substring(8)
: key.split(' ', 2).pop() || ''
: key.trim().split(/\s+/).pop() || ''
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The stepper name extraction is incorrect for names containing multiple spaces. Using .pop() only returns the last word instead of the full name after the type prefix.

For example, if key is 'extruder_stepper my stepper':

  • key.trim().split(/\s+/) produces ['extruder_stepper', 'my', 'stepper']
  • .pop() returns only 'stepper' instead of 'my stepper'

Since steppers starting with 'stepper_' are already handled by the first branch, the else branch should extract everything after the first space:

const name = key.startsWith('stepper_')
  ? key.substring(8)
  : key.substring(key.indexOf(' ') + 1).trim()
Suggested change
: key.trim().split(/\s+/).pop() || ''
: key.substring(key.indexOf(' ') + 1).trim()

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior in Klipper, so we will keep this as is.

Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
@pedrolamas pedrolamas merged commit d2f8c95 into fluidd-core:develop Nov 24, 2025
4 checks passed
@pedrolamas pedrolamas deleted the pedrolamas/fix-1748 branch November 24, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GH - Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Macros starting with underscore not hidden

1 participant