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
parent
287009e119
commit
1e1ef59ea5
|
@ -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
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue