{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/smarthome/issues/2665","repository_url":"https://api.github.com/repos/eclipse/smarthome","labels_url":"https://api.github.com/repos/eclipse/smarthome/issues/2665/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/smarthome/issues/2665/comments","events_url":"https://api.github.com/repos/eclipse/smarthome/issues/2665/events","html_url":"https://github.com/eclipse/smarthome/pull/2665","id":196186990,"number":2665,"title":"Normalize configuration values when initializing thing handlers","user":{"login":"wborn","id":12213581,"avatar_url":"https://avatars.githubusercontent.com/u/12213581?v=3","gravatar_id":"","url":"https://api.github.com/users/wborn","html_url":"https://github.com/wborn","followers_url":"https://api.github.com/users/wborn/followers","following_url":"https://api.github.com/users/wborn/following{/other_user}","gists_url":"https://api.github.com/users/wborn/gists{/gist_id}","starred_url":"https://api.github.com/users/wborn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wborn/subscriptions","organizations_url":"https://api.github.com/users/wborn/orgs","repos_url":"https://api.github.com/users/wborn/repos","events_url":"https://api.github.com/users/wborn/events{/privacy}","received_events_url":"https://api.github.com/users/wborn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":33,"created_at":"2016-12-17T01:19:24Z","updated_at":"2016-12-21T14:35:23Z","closed_at":"2016-12-20T16:46:45Z","pull_request":{"url":"https://api.github.com/repos/eclipse/smarthome/pulls/2665","html_url":"https://github.com/eclipse/smarthome/pull/2665","diff_url":"https://github.com/eclipse/smarthome/pull/2665.diff","patch_url":"https://github.com/eclipse/smarthome/pull/2665.patch"},"body":"On startup stored integer configuration parameters are not normalized. As a result objects with decimals are returned when retrieving these `Configuration` values. This causes exceptions. \r\n\r\nE.g. with the LIFX binding the following warning is logged on startup:\r\n\r\n```\r\n18:52:28.940 [WARN ] [inding.lifx.handler.LifxLightHandler] - Invalid value '300.0' for transition time, using default instead.\r\n```\r\n\r\nThe definition of this parameter is:\r\n\r\n```\r\n    <parameter name=\"fadetime\" type=\"integer\" required=\"false\">\r\n        <label>Fade time</label>\r\n        <description>The time to fade to the new color value (in ms).</description>\r\n        <default>300</default>\r\n    </parameter>\r\n```\r\n\r\nIn this case the code is expecting a Long and not a BigDecimal:\r\n\r\n```\r\n    try {\r\n        return Long.parseLong(fadeCfg.toString());\r\n    } catch (NumberFormatException e) {\r\n        logger.warn(\"Invalid value '{}' for transition time, using default instead.\", fadeCfg.toString());\r\n        return FADE_TIME_DEFAULT;\r\n    }\r\n```\r\n\r\nOther people have reported similar issues on the [openHAB community forums](https://community.openhab.org/t/replacement-of-mapdb-by-jsondb/17498/30). In PR #2633 a workaround is created for the digitalSTROM binding.\r\n\r\nI also did a bit of [research](https://github.com/eclipse/smarthome/pull/2633#issuecomment-266820822) on this issue. The root cause I think is that `Gson` deserializes all integers in a Thing Configuration as a `BigDecimal`. Because this is done using reflection the configuration parameters are never validated/normalized.\r\n\r\nThis PR addresses the issue by normalizing the Configuration values at the same location where the Configuration defaults are also provided. I've tested it and for me it solves the issue with the LIFX binding. I think it should also fix the issues in other bindings.\r\n"},"comment":{"url":"https://api.github.com/repos/eclipse/smarthome/issues/comments/268537168","html_url":"https://github.com/eclipse/smarthome/pull/2665#issuecomment-268537168","issue_url":"https://api.github.com/repos/eclipse/smarthome/issues/2665","id":268537168,"user":{"login":"maggu2810","id":204670,"avatar_url":"https://avatars.githubusercontent.com/u/204670?v=3","gravatar_id":"","url":"https://api.github.com/users/maggu2810","html_url":"https://github.com/maggu2810","followers_url":"https://api.github.com/users/maggu2810/followers","following_url":"https://api.github.com/users/maggu2810/following{/other_user}","gists_url":"https://api.github.com/users/maggu2810/gists{/gist_id}","starred_url":"https://api.github.com/users/maggu2810/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maggu2810/subscriptions","organizations_url":"https://api.github.com/users/maggu2810/orgs","repos_url":"https://api.github.com/users/maggu2810/repos","events_url":"https://api.github.com/users/maggu2810/events{/privacy}","received_events_url":"https://api.github.com/users/maggu2810/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T14:35:23Z","updated_at":"2016-12-21T14:35:23Z","body":"Can a configuration hold a generic type? I assume the types a configuration can hold is very limited (Boolean, String, BigDecimal). Missed I something?"}}
{"actor":{"display_login":"maggu2810"}}