Skip to content

Commit

Permalink
Widget expressions: (Partly) Fix handling of Item name being `undefin…
Browse files Browse the repository at this point in the history
…ed` (openhab#2301)

When using the `@` and `@@` shortcuts for Item displayState and state in
widget expressions, properly handle cases where the Item name is
`undefined`.
Unfortunately I did not find a way to improve that for `items[itemName]`
expressions.

Requesting the Item state from the server when the Item name is
undefined leads to warnings in the log (which might cause some confusion
for the users):
```
[WARN ] [se.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: undefined
```

---------

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Feb 2, 2024
1 parent 287009e commit 1e1ef59
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import jsepTemplate from '@jsep-plugin/template'
expr.jsep.plugins.register(jsepRegex, jsepArrow, jsepObject, jsepTemplate)

expr.addUnaryOp('@', (itemName) => {
if (itemName === undefined) return undefined
const itemState = store.getters.trackedItems[itemName]
if (itemState.displayState === undefined) return itemState.state
return itemState.displayState
return itemState.displayState || itemState.state
})
expr.addUnaryOp('@@', (itemName) => {
if (itemName === undefined) return undefined
return store.getters.trackedItems[itemName].state
})

Expand Down

0 comments on commit 1e1ef59

Please sign in to comment.