Skip to content

Commit

Permalink
Widget expressions: Fix handling of Item name being undefined & Ali…
Browse files Browse the repository at this point in the history
…gn behaviour for @ and @@ shorthands in that case (#2965)

Fixes #2956.
This fix creates the limitation that an Item must not be named
`undefined` - for an Item with this name, state tracking won't work.

---------

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Jan 4, 2025
1 parent 4380671 commit f1c3896
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import jsepTemplate from '@jsep-plugin/template'
expr.jsep.plugins.register(jsepRegex, jsepArrow, jsepObject, jsepTemplate)

expr.addUnaryOp('@', (itemName) => {
if (itemName === undefined) return undefined
if (itemName === undefined) return '-'
const item = store.getters.trackedItems[itemName]
return (item.displayState !== undefined) ? item.displayState : item.state
})
expr.addUnaryOp('@@', (itemName) => {
if (itemName === undefined) return undefined
if (itemName === undefined) return '-'
return store.getters.trackedItems[itemName].state
})
expr.addUnaryOp('#', (itemName) => {
Expand Down
1 change: 1 addition & 0 deletions bundles/org.openhab.ui/web/src/js/store/modules/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const handler = (context) => {
if (typeof prop !== 'string') return {}

const itemName = prop
if (itemName === 'undefined') return { state: '-' }
if (!context.getters.isItemTracked(itemName)) {
context.commit('addToTrackingList', itemName.toString())

Expand Down

0 comments on commit f1c3896

Please sign in to comment.