{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/94036573","pull_request_review_id":14563985,"id":94036573,"diff_hunk":"@@ -0,0 +1,871 @@\n+/**\n+ * Copyright (c) 2014-2016 by the respective copyright holders.\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.globalcache.handler;\n+\n+import static org.openhab.binding.globalcache.GlobalCacheBindingConstants.*;\n+\n+import java.io.BufferedReader;\n+import java.io.DataOutputStream;\n+import java.io.IOException;\n+import java.io.InputStreamReader;\n+import java.net.InetAddress;\n+import java.net.InetSocketAddress;\n+import java.net.NetworkInterface;\n+import java.net.Socket;\n+import java.net.SocketException;\n+import java.net.URLDecoder;\n+import java.util.concurrent.Executors;\n+import java.util.concurrent.LinkedBlockingQueue;\n+import java.util.concurrent.ScheduledExecutorService;\n+import java.util.concurrent.ScheduledFuture;\n+import java.util.concurrent.TimeUnit;\n+import java.util.concurrent.atomic.AtomicInteger;\n+import java.util.regex.Pattern;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.eclipse.smarthome.core.library.types.OnOffType;\n+import org.eclipse.smarthome.core.thing.Channel;\n+import org.eclipse.smarthome.core.thing.ChannelUID;\n+import org.eclipse.smarthome.core.thing.Thing;\n+import org.eclipse.smarthome.core.thing.ThingStatus;\n+import org.eclipse.smarthome.core.thing.ThingStatusDetail;\n+import org.eclipse.smarthome.core.thing.ThingTypeUID;\n+import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;\n+import org.eclipse.smarthome.core.transform.TransformationException;\n+import org.eclipse.smarthome.core.transform.TransformationHelper;\n+import org.eclipse.smarthome.core.transform.TransformationService;\n+import org.eclipse.smarthome.core.types.Command;\n+import org.eclipse.smarthome.core.types.RefreshType;\n+import org.openhab.binding.globalcache.GlobalCacheBindingConstants.CommandType;\n+import org.openhab.binding.globalcache.command.CommandGetstate;\n+import org.openhab.binding.globalcache.command.CommandGetversion;\n+import org.openhab.binding.globalcache.command.CommandSendir;\n+import org.openhab.binding.globalcache.command.CommandSendserial;\n+import org.openhab.binding.globalcache.command.CommandSetstate;\n+import org.openhab.binding.globalcache.command.RequestMessage;\n+import org.openhab.binding.globalcache.command.ResponseMessage;\n+import org.openhab.binding.globalcache.internal.util.NetworkUtil;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * The {@link GlobalCacheHandler} is responsible for handling commands, which are\n+ * sent to one of the channels.\n+ *\n+ * @author Mark Hilbush - Initial contribution\n+ */\n+public class GlobalCacheHandler extends BaseThingHandler {\n+    private Logger logger = LoggerFactory.getLogger(GlobalCacheHandler.class);\n+\n+    private InetAddress ifAddress;\n+    private CommandProcessor commandProcessor;\n+    ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(MAX_GC_DEVICES);\n+    ScheduledFuture<?> scheduledFuture;\n+\n+    private LinkedBlockingQueue<RequestMessage> sendQueue = null;\n+\n+    // IR transaction counter\n+    private AtomicInteger irCounter;\n+\n+    public GlobalCacheHandler(Thing gcDevice) {\n+        super(gcDevice);\n+        irCounter = new AtomicInteger(1);\n+        commandProcessor = new CommandProcessor();\n+        scheduledFuture = null;\n+    }\n+\n+    @Override\n+    public void initialize() {\n+        logger.debug(\"Initializing thing {}\", thingID());\n+        try {\n+            ifAddress = NetworkUtil.getNetworkInterface();\n+            logger.trace(\"Handler using address {} on network interface {}\", ifAddress.getHostAddress(),\n+                    NetworkInterface.getByInetAddress(ifAddress).getName());\n+        } catch (SocketException e) {\n+            logger.error(\"Handler got Socket exception creating multicast socket: {}\", e.getMessage());\n+            markThingOfflineWithError(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, \"No suitable network interface\");\n+            return;\n+        }\n+        scheduledFuture = scheduledExecutorService.schedule(commandProcessor, 2, TimeUnit.SECONDS);\n+    }\n+\n+    @Override\n+    public void dispose() {\n+        logger.debug(\"Disposing thing {}\", thingID());\n+        commandProcessor.terminate();\n+        if (scheduledFuture != null) {\n+            scheduledFuture.cancel(false);\n+        }\n+    }\n+\n+    @Override\n+    public void handleCommand(ChannelUID channelUID, Command command) {\n+        if (command == null) {\n+            logger.warn(\"Command passed to handler for thing {} is null\");\n+            return;\n+        }\n+\n+        // Don't try to send command if the device is not online\n+        if (!isOnline()) {\n+            logger.warn(\"Can't handle command {} because handler for thing {} is not ONLINE\", command, thingID());","path":"addons/binding/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/handler/GlobalCacheHandler.java","position":116,"original_position":116,"commit_id":"49540c786a7dc90193f877597acb065f2983b2a4","original_commit_id":"49540c786a7dc90193f877597acb065f2983b2a4","user":{"login":"kaikreuzer","id":3244965,"avatar_url":"https://avatars.githubusercontent.com/u/3244965?v=3","gravatar_id":"","url":"https://api.github.com/users/kaikreuzer","html_url":"https://github.com/kaikreuzer","followers_url":"https://api.github.com/users/kaikreuzer/followers","following_url":"https://api.github.com/users/kaikreuzer/following{/other_user}","gists_url":"https://api.github.com/users/kaikreuzer/gists{/gist_id}","starred_url":"https://api.github.com/users/kaikreuzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaikreuzer/subscriptions","organizations_url":"https://api.github.com/users/kaikreuzer/orgs","repos_url":"https://api.github.com/users/kaikreuzer/repos","events_url":"https://api.github.com/users/kaikreuzer/events{/privacy}","received_events_url":"https://api.github.com/users/kaikreuzer/received_events","type":"User","site_admin":false},"body":"reduce to debug","created_at":"2016-12-28T14:13:21Z","updated_at":"2016-12-28T14:20:46Z","html_url":"https://github.com/openhab/openhab2-addons/pull/1267#discussion_r94036573","pull_request_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/94036573"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1267#discussion_r94036573"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267","id":87293719,"html_url":"https://github.com/openhab/openhab2-addons/pull/1267","diff_url":"https://github.com/openhab/openhab2-addons/pull/1267.diff","patch_url":"https://github.com/openhab/openhab2-addons/pull/1267.patch","issue_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1267","number":1267,"state":"open","locked":false,"title":"Add Global Cache binding","user":{"login":"mhilbush","id":19286354,"avatar_url":"https://avatars.githubusercontent.com/u/19286354?v=3","gravatar_id":"","url":"https://api.github.com/users/mhilbush","html_url":"https://github.com/mhilbush","followers_url":"https://api.github.com/users/mhilbush/followers","following_url":"https://api.github.com/users/mhilbush/following{/other_user}","gists_url":"https://api.github.com/users/mhilbush/gists{/gist_id}","starred_url":"https://api.github.com/users/mhilbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhilbush/subscriptions","organizations_url":"https://api.github.com/users/mhilbush/orgs","repos_url":"https://api.github.com/users/mhilbush/repos","events_url":"https://api.github.com/users/mhilbush/events{/privacy}","received_events_url":"https://api.github.com/users/mhilbush/received_events","type":"User","site_admin":false},"body":"Initial contribution of Global Cache binding.\nSigned-off-by: Mark Hilbush mark@hilbush.com\n- Supports IR, serial, and contact closure operations on iTach IR, SL, CC, and Flex devices, as well as GC-100-6 and GC-100-12 devices;\n- auto-discovers devices; and\n- IR and serial codes are specified in map file(s).\n\nShould also resolve the following (although this binding requires OH2):\nhttps://github.com/openhab/openhab/issues/4481\nhttps://github.com/openhab/openhab/issues/4173\n","created_at":"2016-09-29T11:24:32Z","updated_at":"2016-12-28T14:20:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"720c136272ddaabb341328034a6d1272c5bcdf95","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267/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/1267/comments","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/49540c786a7dc90193f877597acb065f2983b2a4","head":{"label":"mhilbush:globalcache-binding","ref":"globalcache-binding","sha":"49540c786a7dc90193f877597acb065f2983b2a4","user":{"login":"mhilbush","id":19286354,"avatar_url":"https://avatars.githubusercontent.com/u/19286354?v=3","gravatar_id":"","url":"https://api.github.com/users/mhilbush","html_url":"https://github.com/mhilbush","followers_url":"https://api.github.com/users/mhilbush/followers","following_url":"https://api.github.com/users/mhilbush/following{/other_user}","gists_url":"https://api.github.com/users/mhilbush/gists{/gist_id}","starred_url":"https://api.github.com/users/mhilbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhilbush/subscriptions","organizations_url":"https://api.github.com/users/mhilbush/orgs","repos_url":"https://api.github.com/users/mhilbush/repos","events_url":"https://api.github.com/users/mhilbush/events{/privacy}","received_events_url":"https://api.github.com/users/mhilbush/received_events","type":"User","site_admin":false},"repo":{"id":65158647,"name":"openhab2-addons","full_name":"mhilbush/openhab2-addons","owner":{"login":"mhilbush","id":19286354,"avatar_url":"https://avatars.githubusercontent.com/u/19286354?v=3","gravatar_id":"","url":"https://api.github.com/users/mhilbush","html_url":"https://github.com/mhilbush","followers_url":"https://api.github.com/users/mhilbush/followers","following_url":"https://api.github.com/users/mhilbush/following{/other_user}","gists_url":"https://api.github.com/users/mhilbush/gists{/gist_id}","starred_url":"https://api.github.com/users/mhilbush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhilbush/subscriptions","organizations_url":"https://api.github.com/users/mhilbush/orgs","repos_url":"https://api.github.com/users/mhilbush/repos","events_url":"https://api.github.com/users/mhilbush/events{/privacy}","received_events_url":"https://api.github.com/users/mhilbush/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mhilbush/openhab2-addons","description":"The next-generation open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/mhilbush/openhab2-addons","forks_url":"https://api.github.com/repos/mhilbush/openhab2-addons/forks","keys_url":"https://api.github.com/repos/mhilbush/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mhilbush/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mhilbush/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/mhilbush/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/mhilbush/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/mhilbush/openhab2-addons/events","assignees_url":"https://api.github.com/repos/mhilbush/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/mhilbush/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/mhilbush/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/mhilbush/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mhilbush/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mhilbush/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/mhilbush/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mhilbush/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/mhilbush/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/mhilbush/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/mhilbush/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/mhilbush/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/mhilbush/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/mhilbush/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/mhilbush/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/mhilbush/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/mhilbush/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/mhilbush/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/mhilbush/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mhilbush/openhab2-addons/merges","archive_url":"https://api.github.com/repos/mhilbush/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mhilbush/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/mhilbush/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/mhilbush/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/mhilbush/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/mhilbush/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mhilbush/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/mhilbush/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/mhilbush/openhab2-addons/deployments","created_at":"2016-08-07T23:23:22Z","updated_at":"2016-08-07T23:23:26Z","pushed_at":"2016-12-28T13:33:45Z","git_url":"git://github.com/mhilbush/openhab2-addons.git","ssh_url":"git@github.com:mhilbush/openhab2-addons.git","clone_url":"https://github.com/mhilbush/openhab2-addons.git","svn_url":"https://github.com/mhilbush/openhab2-addons","homepage":null,"size":58510,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"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":"46f4d0baf4da4c1cdc0cb12f4363a017ecc894a9","user":{"login":"openhab","id":1007353,"avatar_url":"https://avatars.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://avatars.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":"The next-generation open Home Automation Bus (openHAB)","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":"2016-12-27T18:29:40Z","pushed_at":"2016-12-28T13:11:37Z","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":null,"size":58491,"stargazers_count":461,"watchers_count":461,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":733,"mirror_url":null,"open_issues_count":185,"forks":733,"open_issues":185,"watchers":461,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1267"},"issue":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1267"},"comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1267/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1267/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/1267/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab2-addons/statuses/49540c786a7dc90193f877597acb065f2983b2a4"}}}}
{"actor":{"display_login":"kaikreuzer"}}