{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab/pulls/comments/27385445","id":27385445,"diff_hunk":"@@ -0,0 +1,238 @@\n+/**\n+ * Copyright (c) 2010-2013, 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.panasonictv.internal;\n+\n+import java.io.BufferedReader;\n+import java.io.BufferedWriter;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.io.InputStreamReader;\n+import java.io.OutputStreamWriter;\n+import java.net.Socket;\n+import java.util.Dictionary;\n+import java.util.Enumeration;\n+import java.util.HashMap;\n+import java.util.Map;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.openhab.binding.panasonictv.PanasonicTVBindingConfig;\n+import org.openhab.binding.panasonictv.PanasonicTVBindingProvider;\n+import org.openhab.core.binding.AbstractActiveBinding;\n+import org.openhab.core.library.types.OnOffType;\n+import org.openhab.core.types.Command;\n+import org.openhab.core.types.State;\n+import org.osgi.service.cm.ConfigurationException;\n+import org.osgi.service.cm.ManagedService;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * Implement this class if you are going create an actively polling service like\n+ * querying a Website/Device.\n+ * \n+ * @author André Heuer\n+ * @since 1.7.0\n+ */\n+public class PanasonicTVBinding extends\n+\t\tAbstractActiveBinding<PanasonicTVBindingProvider> implements\n+\t\tManagedService {\n+\n+\tprivate Map<String, String> registeredTVs = new HashMap<String, String>();\n+\n+\tprivate static final Logger logger = LoggerFactory\n+\t\t\t.getLogger(PanasonicTVBinding.class);\n+\n+\t/**\n+\t * the refresh interval which is used to poll values from the PanansonicTV\n+\t * server (optional, defaults to 60000ms)\n+\t */\n+\tprivate long refreshInterval = 60000;\n+\n+\tpublic PanasonicTVBinding() {\n+\t}\n+\n+\tpublic void activate() {\n+\t}\n+\n+\tpublic void deactivate() {\n+\t\t// deallocate resources here that are no longer needed and\n+\t\t// should be reset when activating this binding again\n+\t}\n+\n+\t/**\n+\t * @{inheritDoc\n+\t */\n+\t@Override\n+\tprotected long getRefreshInterval() {\n+\t\treturn refreshInterval;\n+\t}\n+\n+\t/**\n+\t * @{inheritDoc\n+\t */\n+\t@Override\n+\tprotected String getName() {\n+\t\treturn \"PanansonicTV Binding\";\n+\t}\n+\n+\t/**\n+\t * @{inheritDoc\n+\t */\n+\t@Override\n+\tprotected void internalReceiveCommand(String itemName, Command command) {\n+\t\t// the code being executed when a command was sent on the openHAB\n+\t\t// event bus goes here. This method is only called if one of the\n+\t\t// BindingProviders provide a binding for the given 'itemName'.\n+\t\tlogger.debug(\"internalReceiveCommand() for item: \" + itemName\n+\t\t\t\t+ \" with command: \" + command.toString());\n+\n+\t\tif (this.providers.isEmpty()) {\n+\t\t\tlogger.error(\"Binding is properly configured or loaded. No provider was found.\");\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tfor (PanasonicTVBindingProvider provider : this.providers) {\n+\t\t\tPanasonicTVBindingConfig config = provider\n+\t\t\t\t\t.getBindingConfigForItem(itemName);\n+\t\t\tif (config == null)\n+\t\t\t\tcontinue;\n+\t\t\tint response = sendCommand(config);\n+\t\t\tif (response != 200) {\n+\t\t\t\tlogger.warn(\"Command \" + config.getCommand()\n+\t\t\t\t\t\t+ \" to TV with IP \" + registeredTVs.get(config.getTv())\n+\t\t\t\t\t\t+ \" failed with HTTP Reponse Code \" + response);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\teventPublisher.postUpdate(itemName, OnOffType.OFF);\n+\t\t}\n+\n+\t}\n+\n+\t/**\n+\t * @{inheritDoc\n+\t */\n+\t@Override\n+\tprotected void internalReceiveUpdate(String itemName, State newState) {\n+\t\tlogger.debug(\"internalReceiveUpdate() for item: \" + itemName\n+\t\t\t\t+ \" with state: \" + newState.toString());\n+\t}\n+\n+\t/**\n+\t * @{inheritDoc\n+\t */\n+\t@Override\n+\tpublic void updated(Dictionary<String, ?> config)\n+\t\t\tthrows ConfigurationException {\n+\n+\t\tif (config != null) {\n+\n+\t\t\t// to override the default refresh interval one has to add a\n+\t\t\t// parameter to openhab.cfg like\n+\t\t\t// <bindingName>:refresh=<intervalInMs>\n+\t\t\tString refreshIntervalString = (String) config.get(\"refresh\");\n+\t\t\tif (StringUtils.isNotBlank(refreshIntervalString)) {\n+\t\t\t\trefreshInterval = Long.parseLong(refreshIntervalString);\n+\t\t\t}\n+\n+\t\t\tfor (Enumeration<?> e = config.keys(); e.hasMoreElements();) {\n+\t\t\t\tString tv = (String) e.nextElement();\n+\t\t\t\tif (tv.equalsIgnoreCase(\"service.pid\")\n+\t\t\t\t\t\t|| tv.equalsIgnoreCase(\"refresh\"))\n+\t\t\t\t\tcontinue;\n+\t\t\t\tlogger.info(\"TV registered '\" + tv + \"' with IP '\"\n+\t\t\t\t\t\t+ config.get(tv) + \"'\");\n+\t\t\t\tregisteredTVs.put(tv, config.get(tv).toString());\n+\t\t\t}\n+\n+\t\t\tif (registeredTVs.isEmpty()) {\n+\t\t\t\tsetProperlyConfigured(true);\n+\t\t\t\tlogger.debug(\"No TV was registered in config file\");\n+\t\t\t} else\n+\t\t\t\tsetProperlyConfigured(true);\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * @author André Heuer\n+\t *\n+\t * This methods sends the command to the TV\n+\t * \n+\t * @return HTTP response code from the TV (should be 200)\n+\t */\n+\tint sendCommand(PanasonicTVBindingConfig config) {\n+\t\tString command = config.getCommand().toUpperCase();\n+\n+\t\tString soaprequest = \"\";\n+\n+\t\tif (config.getCommand().toUpperCase().startsWith(\"HDMI\"))\n+\t\t\tsoaprequest = \"<s:Envelope xmlns:s=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\"><s:Body><u:X_SendKey xmlns:u=\\\"urn:panasonic-com:service:p00NetworkControl:1\\\"><X_KeyEvent>NRC_\"\n+\t\t\t\t\t+ command\n+\t\t\t\t\t+ \"</X_KeyEvent></u:X_SendKey></s:Body></s:Envelope>\\r\";\n+\t\telse\n+\t\t\tsoaprequest = \"<s:Envelope xmlns:s=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\"><s:Body><u:X_SendKey xmlns:u=\\\"urn:panasonic-com:service:p00NetworkControl:1\\\"><X_KeyEvent>NRC_\"\n+\t\t\t\t\t+ command\n+\t\t\t\t\t+ \"-ONOFF</X_KeyEvent></u:X_SendKey></s:Body></s:Envelope>\\r\";","path":"bundles/binding/org.openhab.binding.panasonictv/src/main/java/org/openhab/binding/panasonictv/internal/PanasonicTVBinding.java","position":180,"original_position":180,"commit_id":"7afa43057bea8ce3e13bf067e453084f2bb048e5","original_commit_id":"7afa43057bea8ce3e13bf067e453084f2bb048e5","user":{"login":"teichsta","id":2108636,"avatar_url":"https://avatars.githubusercontent.com/u/2108636?v=3","gravatar_id":"","url":"https://api.github.com/users/teichsta","html_url":"https://github.com/teichsta","followers_url":"https://api.github.com/users/teichsta/followers","following_url":"https://api.github.com/users/teichsta/following{/other_user}","gists_url":"https://api.github.com/users/teichsta/gists{/gist_id}","starred_url":"https://api.github.com/users/teichsta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teichsta/subscriptions","organizations_url":"https://api.github.com/users/teichsta/orgs","repos_url":"https://api.github.com/users/teichsta/repos","events_url":"https://api.github.com/users/teichsta/events{/privacy}","received_events_url":"https://api.github.com/users/teichsta/received_events","type":"User","site_admin":false},"body":"please use curly braces even if you handle just Oneliners","created_at":"2015-03-30T12:28:14Z","updated_at":"2015-03-30T12:28:14Z","html_url":"https://github.com/openhab/openhab/pull/1987#discussion_r27385445","pull_request_url":"https://api.github.com/repos/openhab/openhab/pulls/1987","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments/27385445"},"html":{"href":"https://github.com/openhab/openhab/pull/1987#discussion_r27385445"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1987"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab/pulls/1987","id":27414624,"html_url":"https://github.com/openhab/openhab/pull/1987","diff_url":"https://github.com/openhab/openhab/pull/1987.diff","patch_url":"https://github.com/openhab/openhab/pull/1987.patch","issue_url":"https://api.github.com/repos/openhab/openhab/issues/1987","number":1987,"state":"open","locked":false,"title":"Initial version of a Panasonic TV binding","user":{"login":"andreheuer","id":10393020,"avatar_url":"https://avatars.githubusercontent.com/u/10393020?v=3","gravatar_id":"","url":"https://api.github.com/users/andreheuer","html_url":"https://github.com/andreheuer","followers_url":"https://api.github.com/users/andreheuer/followers","following_url":"https://api.github.com/users/andreheuer/following{/other_user}","gists_url":"https://api.github.com/users/andreheuer/gists{/gist_id}","starred_url":"https://api.github.com/users/andreheuer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreheuer/subscriptions","organizations_url":"https://api.github.com/users/andreheuer/orgs","repos_url":"https://api.github.com/users/andreheuer/repos","events_url":"https://api.github.com/users/andreheuer/events{/privacy}","received_events_url":"https://api.github.com/users/andreheuer/received_events","type":"User","site_admin":false},"body":"This binding allows to control multiple Panasonic Viera TVs by openhab. It uses SOAP requests that are sent to the TV. The http return code is used for checking if an error occured (HTTP 200 --> OK).\r\n\r\nCurrently, the binding supports only to send commands. The current volume, for example, could also be processed but this is no implemented yet.\r\n\r\nI posted futher information here: https://groups.google.com/forum/#!searchin/openhab/panasonic/openhab/v8NO2QbvURk/R2GcFIWgmkYJ","created_at":"2015-01-15T09:15:56Z","updated_at":"2015-03-30T12:28:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2028ca2ee370a663409838ad196ad394bd034f8a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab/pulls/1987/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab/pulls/1987/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab/issues/1987/comments","statuses_url":"https://api.github.com/repos/openhab/openhab/statuses/7afa43057bea8ce3e13bf067e453084f2bb048e5","head":{"label":"andreheuer:master","ref":"master","sha":"7afa43057bea8ce3e13bf067e453084f2bb048e5","user":{"login":"andreheuer","id":10393020,"avatar_url":"https://avatars.githubusercontent.com/u/10393020?v=3","gravatar_id":"","url":"https://api.github.com/users/andreheuer","html_url":"https://github.com/andreheuer","followers_url":"https://api.github.com/users/andreheuer/followers","following_url":"https://api.github.com/users/andreheuer/following{/other_user}","gists_url":"https://api.github.com/users/andreheuer/gists{/gist_id}","starred_url":"https://api.github.com/users/andreheuer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreheuer/subscriptions","organizations_url":"https://api.github.com/users/andreheuer/orgs","repos_url":"https://api.github.com/users/andreheuer/repos","events_url":"https://api.github.com/users/andreheuer/events{/privacy}","received_events_url":"https://api.github.com/users/andreheuer/received_events","type":"User","site_admin":false},"repo":{"id":28787080,"name":"openhab","full_name":"andreheuer/openhab","owner":{"login":"andreheuer","id":10393020,"avatar_url":"https://avatars.githubusercontent.com/u/10393020?v=3","gravatar_id":"","url":"https://api.github.com/users/andreheuer","html_url":"https://github.com/andreheuer","followers_url":"https://api.github.com/users/andreheuer/followers","following_url":"https://api.github.com/users/andreheuer/following{/other_user}","gists_url":"https://api.github.com/users/andreheuer/gists{/gist_id}","starred_url":"https://api.github.com/users/andreheuer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreheuer/subscriptions","organizations_url":"https://api.github.com/users/andreheuer/orgs","repos_url":"https://api.github.com/users/andreheuer/repos","events_url":"https://api.github.com/users/andreheuer/events{/privacy}","received_events_url":"https://api.github.com/users/andreheuer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andreheuer/openhab","description":"Source code of the open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/andreheuer/openhab","forks_url":"https://api.github.com/repos/andreheuer/openhab/forks","keys_url":"https://api.github.com/repos/andreheuer/openhab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andreheuer/openhab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andreheuer/openhab/teams","hooks_url":"https://api.github.com/repos/andreheuer/openhab/hooks","issue_events_url":"https://api.github.com/repos/andreheuer/openhab/issues/events{/number}","events_url":"https://api.github.com/repos/andreheuer/openhab/events","assignees_url":"https://api.github.com/repos/andreheuer/openhab/assignees{/user}","branches_url":"https://api.github.com/repos/andreheuer/openhab/branches{/branch}","tags_url":"https://api.github.com/repos/andreheuer/openhab/tags","blobs_url":"https://api.github.com/repos/andreheuer/openhab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andreheuer/openhab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andreheuer/openhab/git/refs{/sha}","trees_url":"https://api.github.com/repos/andreheuer/openhab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andreheuer/openhab/statuses/{sha}","languages_url":"https://api.github.com/repos/andreheuer/openhab/languages","stargazers_url":"https://api.github.com/repos/andreheuer/openhab/stargazers","contributors_url":"https://api.github.com/repos/andreheuer/openhab/contributors","subscribers_url":"https://api.github.com/repos/andreheuer/openhab/subscribers","subscription_url":"https://api.github.com/repos/andreheuer/openhab/subscription","commits_url":"https://api.github.com/repos/andreheuer/openhab/commits{/sha}","git_commits_url":"https://api.github.com/repos/andreheuer/openhab/git/commits{/sha}","comments_url":"https://api.github.com/repos/andreheuer/openhab/comments{/number}","issue_comment_url":"https://api.github.com/repos/andreheuer/openhab/issues/comments{/number}","contents_url":"https://api.github.com/repos/andreheuer/openhab/contents/{+path}","compare_url":"https://api.github.com/repos/andreheuer/openhab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andreheuer/openhab/merges","archive_url":"https://api.github.com/repos/andreheuer/openhab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andreheuer/openhab/downloads","issues_url":"https://api.github.com/repos/andreheuer/openhab/issues{/number}","pulls_url":"https://api.github.com/repos/andreheuer/openhab/pulls{/number}","milestones_url":"https://api.github.com/repos/andreheuer/openhab/milestones{/number}","notifications_url":"https://api.github.com/repos/andreheuer/openhab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andreheuer/openhab/labels{/name}","releases_url":"https://api.github.com/repos/andreheuer/openhab/releases{/id}","created_at":"2015-01-04T21:47:50Z","updated_at":"2015-01-11T22:32:27Z","pushed_at":"2015-01-11T22:32:26Z","git_url":"git://github.com/andreheuer/openhab.git","ssh_url":"git@github.com:andreheuer/openhab.git","clone_url":"https://github.com/andreheuer/openhab.git","svn_url":"https://github.com/andreheuer/openhab","homepage":null,"size":140369,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"acc9d3961e1d0d8ebf12269a08566222ec382cf2","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":12983151,"name":"openhab","full_name":"openhab/openhab","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/openhab","description":"Source code of the open Home Automation Bus (openHAB)","fork":false,"url":"https://api.github.com/repos/openhab/openhab","forks_url":"https://api.github.com/repos/openhab/openhab/forks","keys_url":"https://api.github.com/repos/openhab/openhab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openhab/openhab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openhab/openhab/teams","hooks_url":"https://api.github.com/repos/openhab/openhab/hooks","issue_events_url":"https://api.github.com/repos/openhab/openhab/issues/events{/number}","events_url":"https://api.github.com/repos/openhab/openhab/events","assignees_url":"https://api.github.com/repos/openhab/openhab/assignees{/user}","branches_url":"https://api.github.com/repos/openhab/openhab/branches{/branch}","tags_url":"https://api.github.com/repos/openhab/openhab/tags","blobs_url":"https://api.github.com/repos/openhab/openhab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openhab/openhab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openhab/openhab/git/refs{/sha}","trees_url":"https://api.github.com/repos/openhab/openhab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openhab/openhab/statuses/{sha}","languages_url":"https://api.github.com/repos/openhab/openhab/languages","stargazers_url":"https://api.github.com/repos/openhab/openhab/stargazers","contributors_url":"https://api.github.com/repos/openhab/openhab/contributors","subscribers_url":"https://api.github.com/repos/openhab/openhab/subscribers","subscription_url":"https://api.github.com/repos/openhab/openhab/subscription","commits_url":"https://api.github.com/repos/openhab/openhab/commits{/sha}","git_commits_url":"https://api.github.com/repos/openhab/openhab/git/commits{/sha}","comments_url":"https://api.github.com/repos/openhab/openhab/comments{/number}","issue_comment_url":"https://api.github.com/repos/openhab/openhab/issues/comments{/number}","contents_url":"https://api.github.com/repos/openhab/openhab/contents/{+path}","compare_url":"https://api.github.com/repos/openhab/openhab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openhab/openhab/merges","archive_url":"https://api.github.com/repos/openhab/openhab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openhab/openhab/downloads","issues_url":"https://api.github.com/repos/openhab/openhab/issues{/number}","pulls_url":"https://api.github.com/repos/openhab/openhab/pulls{/number}","milestones_url":"https://api.github.com/repos/openhab/openhab/milestones{/number}","notifications_url":"https://api.github.com/repos/openhab/openhab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openhab/openhab/labels{/name}","releases_url":"https://api.github.com/repos/openhab/openhab/releases{/id}","created_at":"2013-09-20T20:28:43Z","updated_at":"2015-03-30T09:09:13Z","pushed_at":"2015-03-30T09:09:13Z","git_url":"git://github.com/openhab/openhab.git","ssh_url":"git@github.com:openhab/openhab.git","clone_url":"https://github.com/openhab/openhab.git","svn_url":"https://github.com/openhab/openhab","homepage":null,"size":213422,"stargazers_count":1232,"watchers_count":1232,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":733,"mirror_url":null,"open_issues_count":486,"forks":733,"open_issues":486,"watchers":1232,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1987"},"html":{"href":"https://github.com/openhab/openhab/pull/1987"},"issue":{"href":"https://api.github.com/repos/openhab/openhab/issues/1987"},"comments":{"href":"https://api.github.com/repos/openhab/openhab/issues/1987/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1987/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1987/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab/statuses/7afa43057bea8ce3e13bf067e453084f2bb048e5"}}}}