openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
220 stars 240 forks source link

Check for null in widget yaml #1400

Open proggprod opened 2 years ago

proggprod commented 2 years ago

The problem

Can not check for NULL in widget yaml.

When creating dynamic / intelligent widgets that interact with a range of similar items it should be possible to check for NULL without throwing an error in the log. eg a light control widget that responds slightly differently depending on whether the light in question is a switch on/off only, dimmable, CCT, RGB, some with motion sensors, some with motion sensors and light sensors.

I have 13 lights, a combination of different types, and when I load the page with 13 widgets there is a significant delay while all these errors happen, then everything functions as normally, except for the dirty log.

image

I started a discussion on the forum about this https://community.openhab.org/t/widget-check-if-item-exists/134910/10

Your suggestion

It should be possible to check for a null by coding something like this in widget yaml visible: '=(items[props.lightItem + "_Brightness"].state != null) ? true: false'

if the item Hall_Light is the light in question, it will look for Hall_Light_Brightness (to check if it is a dimmable light), if it doesn't exist, it should not throw an error to the log.

Your environment

runtimeInfo:
  version: 3.3.0.M4
  buildString: Milestone Build
locale: en-IE
systemInfo:
  configFolder: /openhab/conf
  userdataFolder: /openhab/userdata
  logFolder: /openhab/userdata/logs
  javaVersion: 11.0.15
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.56+19-CA
  osName: Linux
  osVersion: 5.15.32-v8+
  osArchitecture: aarch64
  availableProcessors: 4
  freeMemory: 69687920
  totalMemory: 405798912
  startLevel: 70
bindings:
  - deconz
  - icalendar
  - icloud
  - lifx
  - network
  - openweathermap
  - samsungtv
  - shelly
  - sonoff
  - sonos
  - tado
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1.3300000429153442
    prefersColorScheme: dark
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: 2
    language: en
    languages:
      - en
      - en-US
    onLine: true
    platform: Win32
  screen:
    width: 3850
    height: 1083
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: dark
    filled: true
    pageTransitionAnimation: default
    bars: light
    homeNavbar: default
    homeBackground: standard
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
timestamp: 2022-05-25T07:59:04.548Z

Additional information

ghys commented 2 years ago

Similar to https://github.com/openhab/openhab-core/issues/2000. I would argue the severity of this log message should be lowered to DEBUG maybe.

petero-dk commented 1 year ago

+1

I have the same issue, an oh-repeater that lists the different lights, some as switches, some with dimming channels, some with colortemp etc. They are strickly named so the widget checks for existence via naming conventions.