{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/113871073","pull_request_review_id":35290691,"id":113871073,"diff_hunk":"@@ -0,0 +1,309 @@\n+/**\n+ * Copyright (c) 2010-2016, openHAB.org and others.\n+ *\n+ * All rights reserved. This program and the accompanying materials\n+ * are made available under the terms of the Eclipse Public License v1.0\n+ * which accompanies this distribution, and is available at\n+ * http://www.eclipse.org/legal/epl-v10.html\n+ */\n+package org.openhab.binding.upb.internal;\n+\n+import java.util.Arrays;\n+import java.util.HashMap;\n+import java.util.Map.Entry;\n+\n+import javax.xml.bind.DatatypeConverter;\n+\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * Model for a message sent or received from a UPB modem.\n+ *\n+ * @author Chris Van Orman\n+ * @since 1.9.0\n+ */\n+public class UPBMessage {\n+\n+    /**\n+     * An enum of possible message priorities.\n+     * \n+     * @author Chris\n+     *\n+     */\n+    public enum Priority {\n+        LOW(0, 1000),\n+        NORMAL(1, 0);\n+\n+        private int value;\n+        private int delay;\n+\n+        private Priority(int value, int delay) {\n+            this.value = value;\n+            this.delay = delay;\n+        }\n+\n+        /**\n+         * @return the value\n+         */\n+        public int getValue() {\n+            return value;\n+        }\n+\n+        /**\n+         * @return the delay\n+         */\n+        public int getDelay() {\n+            return delay;\n+        }\n+    }\n+\n+    /**\n+     * An enum of possible commands.\n+     *\n+     * @author Chris Van Orman\n+     *\n+     */\n+    public enum Command {\n+        ACTIVATE,\n+        DEACTIVATE,\n+        GOTO,\n+        START_FADE,\n+        STOP_FADE,\n+        BLINK,\n+        REPORT_STATE,\n+        STORE_STATE,\n+        DEVICE_STATE,\n+        NONE;\n+\n+        /**\n+         * Gets the protocol byte code for this Command.\n+         *\n+         * @return the protocol byte code.\n+         */\n+        public byte toByte() {\n+            for (Entry<Integer, Command> e : commandMap.entrySet()) {\n+                if (e.getValue() == this) {\n+                    return e.getKey().byteValue();\n+                }\n+            }\n+\n+            return 0;\n+        }\n+\n+        /**\n+         * Converts a byte value into a Command.\n+         *\n+         * @param value\n+         *            the byte value.\n+         * @return the Command that is represented by the given byte value.\n+         */\n+        public static Command valueOf(byte value) {\n+            return commandMap.get(value);\n+        }\n+    }\n+\n+    /**\n+     * An enum of possible modem response types.\n+     *\n+     * @author Chris Van Orman\n+     *\n+     */\n+    public enum Type {\n+        ACCEPT,\n+        BUSY,\n+        ERROR,\n+        ACK,\n+        NAK,\n+        MESSAGE_REPORT,\n+        NONE;\n+    }\n+\n+    private static final Logger logger = LoggerFactory.getLogger(UPBMessage.class);\n+\n+    private static HashMap<Integer, Command> commandMap = new HashMap<>();\n+\n+    static {\n+        commandMap.put(0x20, Command.ACTIVATE);\n+        commandMap.put(0x21, Command.DEACTIVATE);\n+        commandMap.put(0x22, Command.GOTO);\n+        commandMap.put(0x23, Command.START_FADE);\n+        commandMap.put(0x24, Command.STOP_FADE);\n+        commandMap.put(0x25, Command.BLINK);\n+        commandMap.put(0x30, Command.REPORT_STATE);\n+        commandMap.put(0x31, Command.STORE_STATE);\n+        commandMap.put(0x86, Command.DEVICE_STATE);\n+    }\n+\n+    private static HashMap<String, Type> typeMap = new HashMap<>();\n+\n+    static {\n+        typeMap.put(\"PA\", Type.ACCEPT);\n+        typeMap.put(\"PB\", Type.BUSY);\n+        typeMap.put(\"PE\", Type.ERROR);\n+        typeMap.put(\"PK\", Type.ACK);\n+        typeMap.put(\"PN\", Type.NAK);\n+        typeMap.put(\"PU\", Type.MESSAGE_REPORT);\n+    }\n+\n+    /**\n+     * Converts a hex string into a {@link UPBMessage}.\n+     *\n+     * @param commandString\n+     *            the string as returned by the modem.\n+     * @return a new UPBMessage.\n+     */\n+    public static UPBMessage fromString(String commandString) {\n+        UPBMessage command = new UPBMessage();\n+\n+        String typeString = commandString.substring(0, 2);\n+        Type type = Type.NONE;\n+\n+        if (typeMap.containsKey(typeString)) {\n+            type = typeMap.get(typeString);\n+        }\n+\n+        command.setType(type);\n+\n+        try {\n+            if (commandString.length() > 2) {\n+                byte[] data = DatatypeConverter.parseHexBinary(commandString.substring(2));\n+                command.getControlWord().setBytes(data[1], data[0]);\n+                int index = 2;\n+                command.setNetwork(data[index++]);\n+                command.setDestination(data[index++]);\n+                command.setSource(data[index++]);\n+\n+                int commandCode = data[index++] & 0xFF;\n+\n+                if (commandMap.containsKey(commandCode)) {\n+                    command.setCommand(commandMap.get(commandCode));\n+                } else {\n+                    command.setCommand(Command.NONE);\n+                }\n+\n+                if (index < data.length - 1) {\n+                    command.setArguments(Arrays.copyOfRange(data, index, data.length - 1));\n+                }\n+            }\n+        } catch (Exception e) {","path":"addons/binding/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/UPBMessage.java","position":189,"original_position":189,"commit_id":"584deb4270b8e3d8901cb79987e2c0b96127acf7","original_commit_id":"584deb4270b8e3d8901cb79987e2c0b96127acf7","user":{"login":"martinvw","id":2625279,"avatar_url":"https://avatars0.githubusercontent.com/u/2625279?v=3","gravatar_id":"","url":"https://api.github.com/users/martinvw","html_url":"https://github.com/martinvw","followers_url":"https://api.github.com/users/martinvw/followers","following_url":"https://api.github.com/users/martinvw/following{/other_user}","gists_url":"https://api.github.com/users/martinvw/gists{/gist_id}","starred_url":"https://api.github.com/users/martinvw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinvw/subscriptions","organizations_url":"https://api.github.com/users/martinvw/orgs","repos_url":"https://api.github.com/users/martinvw/repos","events_url":"https://api.github.com/users/martinvw/events{/privacy}","received_events_url":"https://api.github.com/users/martinvw/received_events","type":"User","site_admin":false},"body":"Do you really need to catch the Exception-class or are there more specific exceptions you could catch like the IOException . The current code might 'hide' programming errors like NullPointerExceptions occurring.\r\n\r\nhttps://www.google.nl/search?q=java%20why%20not%20to%20catch%20exception","created_at":"2017-04-28T07:42:51Z","updated_at":"2017-04-28T07:58:47Z","html_url":"https://github.com/openhab/openhab2-addons/pull/1620#discussion_r113871073","pull_request_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/113871073"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1620#discussion_r113871073"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620","id":99528289,"html_url":"https://github.com/openhab/openhab2-addons/pull/1620","diff_url":"https://github.com/openhab/openhab2-addons/pull/1620.diff","patch_url":"https://github.com/openhab/openhab2-addons/pull/1620.patch","issue_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1620","number":1620,"state":"open","locked":false,"title":"Created UPB binding, Fixes #1619","user":{"login":"cvanorman","id":3903852,"avatar_url":"https://avatars0.githubusercontent.com/u/3903852?v=3","gravatar_id":"","url":"https://api.github.com/users/cvanorman","html_url":"https://github.com/cvanorman","followers_url":"https://api.github.com/users/cvanorman/followers","following_url":"https://api.github.com/users/cvanorman/following{/other_user}","gists_url":"https://api.github.com/users/cvanorman/gists{/gist_id}","starred_url":"https://api.github.com/users/cvanorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvanorman/subscriptions","organizations_url":"https://api.github.com/users/cvanorman/orgs","repos_url":"https://api.github.com/users/cvanorman/repos","events_url":"https://api.github.com/users/cvanorman/events{/privacy}","received_events_url":"https://api.github.com/users/cvanorman/received_events","type":"User","site_admin":false},"body":"Signed-off-by: Chris Van Orman <vanorman.chris@gmail.com>","created_at":"2016-12-28T09:41:30Z","updated_at":"2017-04-28T07:58:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0271b35e0bbb3c83f9488b566acaa00dbd570456","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1620/comments","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/584deb4270b8e3d8901cb79987e2c0b96127acf7","head":{"label":"cvanorman:1619-upb-binding","ref":"1619-upb-binding","sha":"584deb4270b8e3d8901cb79987e2c0b96127acf7","user":{"login":"cvanorman","id":3903852,"avatar_url":"https://avatars0.githubusercontent.com/u/3903852?v=3","gravatar_id":"","url":"https://api.github.com/users/cvanorman","html_url":"https://github.com/cvanorman","followers_url":"https://api.github.com/users/cvanorman/followers","following_url":"https://api.github.com/users/cvanorman/following{/other_user}","gists_url":"https://api.github.com/users/cvanorman/gists{/gist_id}","starred_url":"https://api.github.com/users/cvanorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvanorman/subscriptions","organizations_url":"https://api.github.com/users/cvanorman/orgs","repos_url":"https://api.github.com/users/cvanorman/repos","events_url":"https://api.github.com/users/cvanorman/events{/privacy}","received_events_url":"https://api.github.com/users/cvanorman/received_events","type":"User","site_admin":false},"repo":{"id":49494421,"name":"openhab2-addons","full_name":"cvanorman/openhab2-addons","owner":{"login":"cvanorman","id":3903852,"avatar_url":"https://avatars0.githubusercontent.com/u/3903852?v=3","gravatar_id":"","url":"https://api.github.com/users/cvanorman","html_url":"https://github.com/cvanorman","followers_url":"https://api.github.com/users/cvanorman/followers","following_url":"https://api.github.com/users/cvanorman/following{/other_user}","gists_url":"https://api.github.com/users/cvanorman/gists{/gist_id}","starred_url":"https://api.github.com/users/cvanorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvanorman/subscriptions","organizations_url":"https://api.github.com/users/cvanorman/orgs","repos_url":"https://api.github.com/users/cvanorman/repos","events_url":"https://api.github.com/users/cvanorman/events{/privacy}","received_events_url":"https://api.github.com/users/cvanorman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cvanorman/openhab2-addons","description":"The next-generation open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/cvanorman/openhab2-addons","forks_url":"https://api.github.com/repos/cvanorman/openhab2-addons/forks","keys_url":"https://api.github.com/repos/cvanorman/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cvanorman/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cvanorman/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/cvanorman/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/cvanorman/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/cvanorman/openhab2-addons/events","assignees_url":"https://api.github.com/repos/cvanorman/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/cvanorman/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/cvanorman/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/cvanorman/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cvanorman/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cvanorman/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/cvanorman/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cvanorman/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/cvanorman/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/cvanorman/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/cvanorman/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/cvanorman/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/cvanorman/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/cvanorman/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/cvanorman/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/cvanorman/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/cvanorman/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/cvanorman/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/cvanorman/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cvanorman/openhab2-addons/merges","archive_url":"https://api.github.com/repos/cvanorman/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cvanorman/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/cvanorman/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/cvanorman/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/cvanorman/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/cvanorman/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cvanorman/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/cvanorman/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/cvanorman/openhab2-addons/deployments","created_at":"2016-01-12T11:01:47Z","updated_at":"2016-01-12T11:01:49Z","pushed_at":"2017-01-12T04:14:51Z","git_url":"git://github.com/cvanorman/openhab2-addons.git","ssh_url":"git@github.com:cvanorman/openhab2-addons.git","clone_url":"https://github.com/cvanorman/openhab2-addons.git","svn_url":"https://github.com/cvanorman/openhab2-addons","homepage":null,"size":193413,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openhab:master","ref":"master","sha":"58ff3da94d5f76dc1f785cb6a3228efdc5d51066","user":{"login":"openhab","id":1007353,"avatar_url":"https://avatars3.githubusercontent.com/u/1007353?v=3","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"repo":{"id":19753195,"name":"openhab2-addons","full_name":"openhab/openhab2-addons","owner":{"login":"openhab","id":1007353,"avatar_url":"https://avatars3.githubusercontent.com/u/1007353?v=3","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openhab/openhab2-addons","description":"Add-ons for openHAB 2.x","fork":false,"url":"https://api.github.com/repos/openhab/openhab2-addons","forks_url":"https://api.github.com/repos/openhab/openhab2-addons/forks","keys_url":"https://api.github.com/repos/openhab/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openhab/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openhab/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/openhab/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/openhab/openhab2-addons/events","assignees_url":"https://api.github.com/repos/openhab/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/openhab/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/openhab/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/openhab/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openhab/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openhab/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/openhab/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/openhab/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/openhab/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/openhab/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/openhab/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/openhab/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/openhab/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/openhab/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/openhab/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/openhab/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/openhab/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openhab/openhab2-addons/merges","archive_url":"https://api.github.com/repos/openhab/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openhab/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/openhab/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/openhab/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/openhab/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openhab/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/openhab/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/openhab/openhab2-addons/deployments","created_at":"2014-05-13T19:41:58Z","updated_at":"2017-04-26T14:39:49Z","pushed_at":"2017-04-28T06:03:30Z","git_url":"git://github.com/openhab/openhab2-addons.git","ssh_url":"git@github.com:openhab/openhab2-addons.git","clone_url":"https://github.com/openhab/openhab2-addons.git","svn_url":"https://github.com/openhab/openhab2-addons","homepage":"","size":251873,"stargazers_count":569,"watchers_count":569,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":953,"mirror_url":null,"open_issues_count":327,"forks":953,"open_issues":327,"watchers":569,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1620"},"issue":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1620"},"comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1620/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1620/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab2-addons/statuses/584deb4270b8e3d8901cb79987e2c0b96127acf7"}}}}
{"actor":{"display_login":"martinvw"}}