[SOLVED] Switch case error

Hello,
what is here the error??

rule "set hue group2 scene"
when
        Item HTEST changed
    then
        val String bridgeURL = "http://philips-hue.fritz.box/api/7hRzVEDbaoXMoVEPkHyAGSD1hudeIBy5pFq2zLjS/"
        var String scene_id = "lnb0VJ9Bf0wgwh4"
        val String scene_group = "2"

        switch(HTEST.state.toString) {
            case "1":
                scene_id = "lnb0VJ9Bf0wgwh4" //Sonnenuntergang Savanne
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "2":
                scene_id = "bXMhkkAzPfgP9E0" //Tropendämmerung
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "3":
                scene_id = "pdmTm9aVlo5c4KR" //Nordlichter
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "4":
                scene_id = "9wYcn1skY602ZF0" //Entspannen
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "5":
                scene_id = "DHdqsIokbYaW3KH" //Lesen
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "6":
                scene_id = "xzUNyRhvl3-2L4F" //FrĂĽhlingsblĂĽten
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "7":
                scene_id = "lqy8bsZ55T-45FR" //Konzentration
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "8":
                scene_id = "oG4a2vBIL-Mf4gT" //Aktivieren
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "9":
                scene_id = "aocu7QdLfPawkYj" //Hell
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "10":
                scene_id = "f1UuvnOp5F8xzC2" //Gedimmt
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            case "11":
                scene_id = "cb3IC7hAgW-URnm" //Nachtlicht
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')*/
        }
        logInfo("set hue group2 scene", HTEST.state.toString)
end

Error:

2019-01-06 09:54:39.834 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'hue.rules' has errors, therefore ignoring it: [14,35]: no viable alternative at input '('
[14,46]: mismatched input '+' expecting ')'
[14,48]: missing '}' at '"groups/"'
[14,83]: mismatched input ',' expecting 'end'

That is, it should be sendHttpPutRequest(bridgeURL)

I haven’t checked for other potential issues though, I’m not at a computer right now.
Oh and the */ at the end of the sendHttpPutRequest of case 11 probably won’t help either.

OK I deleted the “*/”

but this error is still there if I delete the “scene_id” in each case everything is fine. So somthing must be wrong with the variable decleration but i don’t know what???

Do you use VSCode?

1 Like

Disregard my first comment on the opening/closing brackets, I clearly wasn’t awake yet… :slight_smile:
I now realized that we are dealing with Xtend syntax here, so you will need to use curly brackets if you want to have multiline case statements, like so:

            case "1": {
                scene_id = "lnb0VJ9Bf0wgwh4" //Sonnenuntergang Savanne
                sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
            }

I have but always got this error

[Error - 11:12:21 AM] Server initialization failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: URI has an authority component
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
	at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
	at org.eclipse.xtext.ide.server.concurrent.WriteRequest.run(WriteRequest.java:44)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: URI has an authority component
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:53)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at org.eclipse.smarthome.model.lsp.internal.MappingUriExtensions.toPathAsInXtext212(MappingUriExtensions.java:209)
	at org.eclipse.smarthome.model.lsp.internal.MappingUriExtensions.mapToClientPath(MappingUriExtensions.java:119)
	at org.eclipse.smarthome.model.lsp.internal.MappingUriExtensions.toUriString(MappingUriExtensions.java:110)
	at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$publishDiagnostics$26(LanguageServerImpl.java:447)
	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
	at org.eclipse.xtext.ide.server.LanguageServerImpl.publishDiagnostics(LanguageServerImpl.java:457)
	at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$null$9(LanguageServerImpl.java:293)
	at org.eclipse.xtext.ide.server.ProjectManager.lambda$null$3(ProjectManager.java:135)
	at org.eclipse.xtext.build.IncrementalBuilder$InternalStatefulIncrementalBuilder.validate(IncrementalBuilder.java:267)
	at org.eclipse.xtext.build.IncrementalBuilder$InternalStatefulIncrementalBuilder.lambda$launch$6(IncrementalBuilder.java:244)
	at org.eclipse.xtext.build.ClusteringStorageAwareResourceLoader.lambda$executeClustered$1(ClusteringStorageAwareResourceLoader.java:77)
	at org.eclipse.xtext.xbase.lib.internal.FunctionDelegate.apply(FunctionDelegate.java:42)
	at com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:617)
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
	at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
	at java.util.ArrayList.addAll(ArrayList.java:581)
	at com.google.common.collect.Iterables.addAll(Iterables.java:352)
	at org.eclipse.xtext.build.ClusteringStorageAwareResourceLoader.executeClustered(ClusteringStorageAwareResourceLoader.java:80)
	at org.eclipse.xtext.build.BuildContext.executeClustered(BuildContext.java:55)
	at org.eclipse.xtext.build.IncrementalBuilder$InternalStatefulIncrementalBuilder.launch(IncrementalBuilder.java:251)
	at org.eclipse.xtext.build.IncrementalBuilder.build(IncrementalBuilder.java:399)
	at org.eclipse.xtext.build.IncrementalBuilder.build(IncrementalBuilder.java:384)
	at org.eclipse.xtext.ide.server.ProjectManager.doBuild(ProjectManager.java:115)
	at org.eclipse.xtext.ide.server.ProjectManager.doInitialBuild(ProjectManager.java:107)
	at org.eclipse.xtext.ide.server.BuildManager.doInitialBuild(BuildManager.java:148)
	at org.eclipse.xtext.ide.server.WorkspaceManager.refreshWorkspaceConfig(WorkspaceManager.java:148)
	at org.eclipse.xtext.ide.server.WorkspaceManager.initialize(WorkspaceManager.java:117)
	at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$initialize$10(LanguageServerImpl.java:295)
	at org.eclipse.xtext.ide.server.concurrent.WriteRequest.run(WriteRequest.java:38)
	... 5 more

but my server is correctly set

That sounds like your URL is wrong, which is hard to debug from our end.

As the Request is always the same, the rule can be much simpler.

rule "hue group2 scene"
when
    Item HTEST changed
then
    val String bridgeURL = "http://philips-hue.fritz.box/api/7hRzVEDbaoXMoVEPkHyAGSD1hudeIBy5pFq2zLjS/"
    val String scene_group = "2"
    var String scene_id = "lnb0VJ9Bf0wgwh4"
    switch(HTEST.state.toString) {
        case "1"  : scene_id = "lnb0VJ9Bf0wgwh4" //Sonnenuntergang Savanne
        case "2"  : scene_id = "bXMhkkAzPfgP9E0" //Tropendämmerung
        case "3"  : scene_id = "pdmTm9aVlo5c4KR" //Nordlichter
        case "4"  : scene_id = "9wYcn1skY602ZF0" //Entspannen
        case "5"  : scene_id = "DHdqsIokbYaW3KH" //Lesen
        case "6"  : scene_id = "xzUNyRhvl3-2L4F" //FrĂĽhlingsblĂĽten
        case "7"  : scene_id = "lqy8bsZ55T-45FR" //Konzentration
        case "8"  : scene_id = "oG4a2vBIL-Mf4gT" //Aktivieren
        case "9"  : scene_id = "aocu7QdLfPawkYj" //Hell
        case "10" : scene_id = "f1UuvnOp5F8xzC2" //Gedimmt
        case "11" : scene_id = "cb3IC7hAgW-URnm" //Nachtlicht
    }
    sendHttpPutRequest(bridgeURL + "groups/" + scene_group + "/action", "application/json", '{"scene": "' + scene_id + '"}')
    logInfo("set hue group2 scene", HTEST.state.toString)
end

In fact, this doesn’t solve the problem with the URL.