Skip to content

oh-input: Fix parts of value appended as unit for complex formatted states#4122

Open
Copilot wants to merge 9 commits intomainfrom
copilot/fix-api-400-oh-input-card
Open

oh-input: Fix parts of value appended as unit for complex formatted states#4122
Copilot wants to merge 9 commits intomainfrom
copilot/fix-api-400-oh-input-card

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 22, 2026

Fixes #4027.

Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix API responding 400 with oh-input-card Prevent oh-input-card from appending pseudo-units for Number:Time display formats Apr 22, 2026
Copilot AI requested a review from florian-h05 April 22, 2026 05:41
@florian-h05 florian-h05 force-pushed the copilot/fix-api-400-oh-input-card branch from 448b727 to 4352c27 Compare April 22, 2026 13:25
@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 22, 2026

#5367 Bundle Size — 13.84MiB (~-0.01%).

e41c88e(current) vs 6f9bab9 main#5359(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  no changes
                 Current
#5367
     Baseline
#5359
No change  Initial JS 1.41MiB 1.41MiB
No change  Initial CSS 0B 0B
No change  Cache Invalidation 16.18% 16.18%
No change  Chunks 697 697
No change  Assets 816 816
No change  Modules 2818 2818
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 126 126
No change  Duplicate Packages 1 1
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#5367
     Baseline
#5359
Improvement  JS 11.53MiB (~-0.01%) 11.53MiB
No change  CSS 902.12KiB 902.12KiB
No change  IMG 638.41KiB 638.41KiB
No change  Fonts 526.1KiB 526.1KiB
No change  Media 295.6KiB 295.6KiB
No change  Other 847B 847B

Bundle analysis reportBranch copilot/fix-api-400-oh-input-car...Project dashboard


Generated by RelativeCIDocumentationReport issue

Signed-off-by: Florian Hotze <dev@florianhotze.com>
Signed-off-by: Florian Hotze <dev@florianhotze.com>
Signed-off-by: Florian Hotze <dev@florianhotze.com>
Copy link
Copy Markdown
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

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

LGTM!

@florian-h05 florian-h05 changed the title Prevent oh-input-card from appending pseudo-units for Number:Time display formats oh-input: Fix parts of value appended as unit for complex formatted states Apr 22, 2026
@florian-h05 florian-h05 added bug Something isn't working main ui Main UI labels Apr 22, 2026
@florian-h05 florian-h05 marked this pull request as ready for review April 22, 2026 13:56
@florian-h05
Copy link
Copy Markdown
Contributor

@jsjames Can you please review this PR? My approval doesn't "count" as I contributed to that PR and Copilot acted on my behalf.

Comment thread bundles/org.openhab.ui/web/src/components/widgets/system/oh-input.vue Outdated
Signed-off-by: Florian Hotze <dev@florianhotze.com>
Comment thread bundles/org.openhab.ui/web/src/components/widgets/system/oh-input.test.ts Outdated
Signed-off-by: Florian Hotze <dev@florianhotze.com>
@mherwege
Copy link
Copy Markdown
Contributor

I am still not sure we solve all cases. I didn't test it, but look at the followign examples.

This is a valid pattern: %.0f kW is the power. Reading the code, I believe we will have power as the unit, while it should be kW.
I am not even sure %.0f %unit% is the power will correctly extract %unit%.

This is tricky, but in general text after the last pattern is allowed and would be shown verbatim. And you should assume the unit is always following the value.

…t, not last token

Agent-Logs-Url: https://github.com/openhab/openhab-webui/sessions/7cd78c01-d244-4e21-9102-94a2fed71b67

Co-authored-by: florian-h05 <73423173+florian-h05@users.noreply.github.com>
@florian-h05
Copy link
Copy Markdown
Contributor

Better now @mherwege?

@mherwege
Copy link
Copy Markdown
Contributor

Better now @mherwege?

Yes. LGTM now. I think there still is one case where it would fail: if there is no unit in the pattern, but some text behind the value. But the only way to avoid that would be to check if the position after the value is %unit or a valid unit pattern. Having a definitive check on that would be very difficult (there is some code already for the UI unit validation, but it still allows any string as it is difficult to cover all possible allowed combinations).

@jsjames
Copy link
Copy Markdown
Contributor

jsjames commented Apr 24, 2026

I added one additional test case / fix and had copilot suggest the fix.

Also, I had to modify vitest in order to run due to localStorage.getItem. Did this work correctly for you without that?

@jsjames jsjames force-pushed the copilot/fix-api-400-oh-input-card branch from 84a8b0f to 291fff9 Compare April 24, 2026 14:48
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.

I didn't need that and also wonder why this should be needed.

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.

CI also didn't need it.

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.

this is the error I get without that code:

(node:98844) Warning: `--localstorage-file` was provided without a valid path
(Use `node --trace-warnings ...` to show where the warning was created)
 ❯ src/components/widgets/system/oh-input.test.ts (0 test)

⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/components/widgets/system/oh-input.test.ts [ src/components/widgets/system/oh-input.test.ts ]
TypeError: localStorage.getItem is not a function
 ❯ getTimelineLayersStateFromStorage node_modules/@vue/devtools-kit/dist/index.js:2272:30
 ❯ initStateFactory node_modules/@vue/devtools-kit/dist/index.js:2565:26
 ❯ node_modules/@vue/devtools-kit/dist/index.js:2569:68
 ❯ src/js/stores/useUserStore.ts:1:1
      1| import { defineStore } from 'pinia'
       | ^
      2| import { ref } from 'vue'

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.

I was using node@25. Once I backed down to node@24, things work. I'll update.

expect(value).toBe('20')
})

it('does not strip a unit that only matches mid-string', () => {
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.

I don't understand that test case.
How should s be extracted as a unit from 125 ms? In that case, ms should be extracted as unit.

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.

correct "ms" should be the right unit, but the current logic returns "m"

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.

Why does the current logic return s as unit when it’s ms?
Display state vs state?!

In that case the issue imo is in the unit extraction and not the value extraction.

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.

agree - i wasn't following the logic (and relied too much on copilot). I'll revert the change.

@florian-h05
Copy link
Copy Markdown
Contributor

Please no force pushes!!
A “clean” commit history doesn’t matter in PRs since it is squashed anyway, but force pushing deletes the review progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working main ui Main UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API responds 400 with oh-input-card

4 participants