Widget expressions: (Partly) Fix handling of Item name being `undefined` (#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 <florianh_dev@icloud.com>
pull/2303/head
Florian Hotze 2024-02-02 22:43:12 +01:00 committed by GitHub
parent 287009e119
commit 1e1ef59ea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -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
})