eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
865 stars 782 forks source link

[Tradfri] Bug in color space conversion #4349

Closed hreichert closed 7 years ago

hreichert commented 7 years ago

As reported in the OpenHAB community: https://community.openhab.org/t/ikea-tradfri-gateway/26135/126

when I change the color in the IKEA Trådfri iOS App to the darkest blue, I get the following error:

==> /var/log/openhab2/openhab.log <==
2017-09-26 19:17:37.493 [ERROR] [alifornium.core.network.CoapEndpoint] - Exception in protocol stage thread: Value must be between 0 and 100
java.lang.IllegalArgumentException: Value must be between 0 and 100
    at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:50) [98:org.eclipse.smarthome.core:0.9.0.201709260841]
    at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:35) [98:org.eclipse.smarthome.core:0.9.0.201709260841]
    at org.eclipse.smarthome.core.library.types.HSBType.fromRGB(HSBType.java:114) [98:org.eclipse.smarthome.core:0.9.0.201709260841]
    at org.eclipse.smarthome.binding.tradfri.internal.TradfriColor.constructHsbTypeFromRgbWithBrightnessPercent(TradfriColor.java:247) [186:org.eclipse.smarthome.binding.tradfri:0.9.0.201709260841]
    at org.eclipse.smarthome.binding.tradfri.internal.TradfriColor.fromCie(TradfriColor.java:133) [186:org.eclipse.smarthome.binding.tradfri:0.9.0.201709260841]
    at org.eclipse.smarthome.binding.tradfri.handler.TradfriLightHandler$LightData.getColor(TradfriLightHandler.java:423) [186:org.eclipse.smarthome.binding.tradfri:0.9.0.201709260841]
    at org.eclipse.smarthome.binding.tradfri.handler.TradfriLightHandler.onUpdate(TradfriLightHandler.java:140) [186:org.eclipse.smarthome.binding.tradfri:0.9.0.201709260841]
    at org.eclipse.smarthome.binding.tradfri.internal.TradfriCoapHandler.onLoad(TradfriCoapHandler.java:60) [186:org.eclipse.smarthome.binding.tradfri:0.9.0.201709260841]
    at org.eclipse.californium.core.CoapClient$ObserveMessageObserverImpl.deliver(CoapClient.java:1067) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.CoapClient$MessageObserverImpl.succeeded(CoapClient.java:995) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.CoapClient$MessageObserverImpl.onResponse(CoapClient.java:974) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.coap.Request.setResponse(Request.java:509) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.EndpointManager$ClientMessageDeliverer.deliverResponse(EndpointManager.java:267) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.CoapStack$StackTopAdapter.receiveResponse(CoapStack.java:193) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.AbstractLayer.receiveResponse(AbstractLayer.java:98) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.ObserveLayer.receiveResponse(ObserveLayer.java:137) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.AbstractLayer.receiveResponse(AbstractLayer.java:98) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.BlockwiseLayer.receiveResponse(BlockwiseLayer.java:321) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.AbstractLayer.receiveResponse(AbstractLayer.java:98) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.ReliabilityLayer.receiveResponse(ReliabilityLayer.java:269) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.AbstractLayer.receiveResponse(AbstractLayer.java:98) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.stack.CoapStack.receiveResponse(CoapStack.java:135) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.CoapEndpoint$InboxImpl.receiveMessage(CoapEndpoint.java:656) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.CoapEndpoint$InboxImpl.access$700(CoapEndpoint.java:562) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.CoapEndpoint$InboxImpl$1.run(CoapEndpoint.java:574) [175:californium-osgi:1.0.6]
    at org.eclipse.californium.core.network.CoapEndpoint$5.run(CoapEndpoint.java:721) [175:californium-osgi:1.0.6]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
    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) [?:?]
hreichert commented 7 years ago

Can reproduce it. Investigating.

hreichert commented 7 years ago

Fixed. In side-cases, the conversion from CIE-XY to RGB can output slightly negative numbers. PR #4351 ensures that the RGB values are always in the range from 0 to 255.