Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot assign stateDescription metadata in Item creation from textual definition #1112

Open
shutterfreak opened this issue Jun 22, 2021 · 1 comment
Labels
bug Something isn't working main ui Main UI

Comments

@shutterfreak
Copy link

shutterfreak commented Jun 22, 2021

The problem

Although it is possible to define Items from their textual definition (openHAB2 .items files), there is an issue when adding the stateDescription metadata entry. This has been reported to be working, see e.g.:
https://community.openhab.org/t/oh3-add-metadata-to-items-via-configuration-files/112843

An example Item definition that partially succeeds:

Number:Length OneCallAPIweatherandforecast_ForecastToday_Rain "Today's rain" <rain> (gWeatherForecast_Today)
  ["Rain", "Today", "Forecast", "Point_Measurement", "Property_Rain"] {
  channel="openweathermap:onecall:4afe5c0d:local:forecastToday#rain",
  stateDescription=""[
    readOnly="true",
    pattern="%.2f mm"
  ],
  listWidget="rain_amount_list"[
    show_badge="true",
    show_group_members="false"
  ]
}

In this example, I'm using a custom list widget. The same error occurs when only assigning the stateDescription metadata.

The UI shows the following error:

An error occurred while creating the links and metadata: Server Error

The Item is created (albeit without the offending metadata, i.e., without the stateDescription metadata).

The openHAB logs show:

==> /var/log/openhab/events.log <==
2021-06-22 12:17:38.145 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'OneCallAPIweatherandforecast_ForecastToday_Rain' changed from NULL to 4.46 mm

==> /var/log/openhab/openhab.log <==
2021-06-22 12:17:38.144 [ERROR] [internal.JSONResponseExceptionMapper] - Unexpected exception occurred while processing REST request.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 11 path $.value
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224) ~[?:?]
	at com.google.gson.Gson.fromJson(Gson.java:888) ~[?:?]
	at com.google.gson.Gson.fromJson(Gson.java:826) ~[?:?]
	at org.openhab.core.io.rest.core.internal.GsonMessageBodyReader.readFrom(GsonMessageBodyReader.java:58) ~[?:?]
	at org.openhab.core.io.rest.core.internal.MediaTypeExtension.readFrom(MediaTypeExtension.java:103) ~[?:?]
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1409) ~[bundleFile:1.0.9]
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1361) ~[bundleFile:1.0.9]
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processRequestBodyParameter(JAXRSUtils.java:877) ~[bundleFile:1.0.9]
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:822) [bundleFile:1.0.9]
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:214) [bundleFile:1.0.9]
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78) [bundleFile:1.0.9]
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [bundleFile:1.0.9]
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [bundleFile:1.0.9]
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) [bundleFile:1.0.9]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:237) [bundleFile:1.0.9]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) [bundleFile:3.1.0]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) [bundleFile:1.0.9]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [bundleFile:?]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813]
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]
	at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 11 path $.value
	at com.google.gson.stream.JsonReader.nextString(JsonReader.java:825) ~[?:?]
	at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:401) ~[?:?]
	at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:389) ~[?:?]
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) ~[?:?]
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) ~[?:?]
	... 54 more

Expected behavior

The Item should have been created without problems, with all metadata definitions provided.

Steps to reproduce

See example provided.

I suspect that the language parser has a problem when it encounters an empty string after the metadata name, as in stateDescription=""[...

Your environment

Platform information: Raspbian Buster on Raspberry Pi 3B+

runtimeInfo:
  version: 3.0.2
  buildString: Release Build
locale: en-BE
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.11
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.48+21-CA
  osName: Linux
  osVersion: 5.10.17-v7+
  osArchitecture: arm
  availableProcessors: 4
  freeMemory: 46704992
  totalMemory: 247332864
bindings:
  - astro
  - buienradar
  - exec
  - gpstracker
  - openweathermap
  - sonos
  - telegram
  - tradfri
  - zwave
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: true
    windows: false
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: macos
    pixelRatio: 2
    prefersColorScheme: dark
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: N/A
    language: en-gb
    languages:
      - en-gb
    onLine: true
    platform: MacIntel
  screen:
    width: 3360
    height: 1890
    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: default
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
timestamp: 2021-06-22T10:28:28.042Z

Browser console

JavaScript Console in Safari:

[Debug] PUT /rest/links/OneCallAPIweatherandforecast_ForecastToday_Rain/openweathermap%3Aonecall%3A4afe5c0d%3Alocal%3AforecastToday%23rain: {"itemName":"OneCallAPIweatherandforecast_ForecastToday_Rain","channelUID":"openweathermap:onecall:4afe5c0d:local:forecastToday#rain","configuration":{}} (app.js, line 32)
[Debug] PUT /rest/items/OneCallAPIweatherandforecast_ForecastToday_Rain/metadata/stateDescription{"value":{"value":"","config":[{"key":"readOnly","value":"true"},{"key":"pattern","value":"%.2f mm"}]},"config":{"readOnly":"true","pattern":"%.2f mm"}} (app.js, line 32)
[Debug] PUT /rest/items/OneCallAPIweatherandforecast_ForecastToday_Rain/metadata/listWidget{"value":"rain_amount_list","config":{"show_badge":"true","show_group_members":"false"}} (app.js, line 32)
[Error] Failed to load resource: the server responded with a status of 500 (Server Error) (stateDescription, line 0)
[Error] Server Error
	(anonymous function) (app.js:32:233850)
	promiseReactionJob

Browser network traffic

Additional information

See also:
https://community.openhab.org/t/oh3-add-metadata-to-items-via-configuration-files/112843/29?u=shutterfreak

@shutterfreak shutterfreak added bug Something isn't working main ui Main UI labels Jun 22, 2021
@shutterfreak shutterfreak changed the title Cannot assign readOnly property of stateDescription metadata in Item creation from textual definition Cannot assign stateDescription metadata in Item creation from textual definition Jun 22, 2021
@shutterfreak
Copy link
Author

shutterfreak commented Jun 23, 2021

Apparently this is a know problem, see:
https://community.openhab.org/t/how-to-add-item-pattern-format-via-add-items-via-textual-definition-migrate-from-items-files/111172

It should work with a single space in the double quotes.

Confirmed to work when adding a single space in the double quote pair

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working main ui Main UI
Projects
None yet
Development

No branches or pull requests

1 participant