{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab/pulls/comments/25149064","id":25149064,"diff_hunk":"@@ -0,0 +1,240 @@\n+/**\n+ * Copyright (c) 2010-2014, 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.satel.internal;\n+\n+import java.util.ArrayList;\n+import java.util.Dictionary;\n+import java.util.List;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.openhab.binding.satel.SatelBindingConfig;\n+import org.openhab.binding.satel.SatelBindingProvider;\n+import org.openhab.binding.satel.internal.event.EventListener;\n+import org.openhab.binding.satel.internal.event.NewStatesEvent;\n+import org.openhab.binding.satel.internal.event.SatelEvent;\n+import org.openhab.binding.satel.internal.protocol.Ethm1Module;\n+import org.openhab.binding.satel.internal.protocol.IntRSModule;\n+import org.openhab.binding.satel.internal.protocol.SatelMessage;\n+import org.openhab.binding.satel.internal.protocol.SatelModule;\n+import org.openhab.binding.satel.internal.protocol.command.NewStatesCommand;\n+import org.openhab.binding.satel.internal.types.IntegraType;\n+import org.openhab.core.binding.AbstractActiveBinding;\n+import org.openhab.core.items.Item;\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+ * This is main service class that helps exchanging data between openHAB and\n+ * Satel module in both directions. Implements regular openHAB binding service.\n+ * \n+ * @author Krzysztof Goworek\n+ * @since 1.7.0\n+ */\n+public class SatelBinding extends AbstractActiveBinding<SatelBindingProvider> implements ManagedService, EventListener {\n+\n+\tprivate static final Logger logger = LoggerFactory.getLogger(SatelBinding.class);\n+\n+\tprivate long refreshInterval = 10000;\n+\tprivate String userCode;\n+\tprivate SatelModule satelModule = null;\n+\n+\t/**\n+\t * {@inheritDoc}\n+\t */\n+\t@Override\n+\tprotected String getName() {\n+\t\treturn \"Satel Refresh Service\";\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+\tpublic void execute() {\n+\t\tif (!this.satelModule.isInitialized()) {\n+\t\t\tlogger.debug(\"Module not initialized yet, skipping refresh\");\n+\t\t\treturn;\n+\t\t}\n+\n+\t\t// for first refresh after connecting to the module, make full refresh\n+\t\t// after that check what has changed since last refresh\n+\t\tlogger.trace(\"Sending 'get new states' command\");\n+\t\tthis.satelModule\n+\t\t\t\t.sendCommand(NewStatesCommand.buildMessage(this.satelModule.getIntegraType() == IntegraType.I256_PLUS));\n+\t}\n+\n+\t/**\n+\t * {@inheritDoc}\n+\t */\n+\t@Override\n+\tpublic void updated(Dictionary<String, ?> config) throws ConfigurationException {\n+\t\tlogger.trace(\"Binding configuration updated\");\n+\n+\t\tif (config == null) {\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tthis.refreshInterval = getLongValue(config, \"refresh\", 10000);\n+\t\tthis.userCode = getStringValue(config, \"user_code\", null);\n+\n+\t\tint timeout = getIntValue(config, \"timeout\", 5000);\n+\t\tString host = getStringValue(config, \"host\", null);;\n+\t\tif (StringUtils.isNotBlank(host)) {\n+\t\t\tthis.satelModule = new Ethm1Module(host, getIntValue(config, \"port\", 7094), timeout,\n+\t\t\t\t\t(String) config.get(\"encryption_key\"));\n+\t\t} else {\n+\t\t\tthis.satelModule = new IntRSModule((String) config.get(\"port\"), timeout);\n+\t\t}\n+\n+\t\tthis.satelModule.addEventListener(this);\n+\t\tthis.satelModule.open();\n+\t\tsetProperlyConfigured(true);\n+\t\tlogger.trace(\"Binding properly configured\");\n+\t}\n+\n+\t/**\n+\t * {@inheritDoc}\n+\t */\n+\t@Override\n+\tprotected void internalReceiveCommand(String itemName, Command command) {\n+\t\tif (!isProperlyConfigured()) {\n+\t\t\tlogger.warn(\"Binding not properly configured, exiting\");\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tif (!this.satelModule.isInitialized()) {\n+\t\t\tlogger.debug(\"Module not initialized yet, ignoring command\");\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tfor (SatelBindingProvider provider : providers) {\n+\t\t\tSatelBindingConfig itemConfig = provider.getItemConfig(itemName);\n+\t\t\tif (itemConfig != null) {\n+\t\t\t\tlogger.trace(\"Sending internal command for item {}: {}\", itemName, command);\n+\t\t\t\tSatelMessage message = itemConfig.handleCommand(command, this.satelModule.getIntegraType(),\n+\t\t\t\t\t\tthis.userCode);\n+\t\t\t\tif (message != null) {\n+\t\t\t\t\tthis.satelModule.sendCommand(message);\n+\t\t\t\t}\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * {@inheritDoc}\n+\t */\n+\t@Override\n+\tpublic void incomingEvent(SatelEvent event) {\n+\t\tlogger.trace(\"Handling incoming event: {}\", event);\n+\n+\t\t// refresh all states that have changed\n+\t\tif (event instanceof NewStatesEvent) {\n+\t\t\tNewStatesEvent nse = (NewStatesEvent) event;\n+\t\t\tList<SatelMessage> commands = getRefreshCommands();\n+\t\t\tfor (SatelMessage message : commands) {\n+\t\t\t\tif (nse.isNew(message.getCommand())) {\n+\t\t\t\t\tthis.satelModule.sendCommand(message);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\t// update items\n+\t\tfor (SatelBindingProvider provider : providers) {\n+\t\t\tfor (String itemName : provider.getItemNames()) {\n+\t\t\t\tSatelBindingConfig itemConfig = provider.getItemConfig(itemName);\n+\t\t\t\tItem item = provider.getItem(itemName);\n+\t\t\t\tState newState = itemConfig.convertEventToState(item, event);\n+\t\t\t\tif (newState != null) {\n+\t\t\t\t\teventPublisher.postUpdate(itemName, newState);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Deactivates the binding by closing connected module.\n+\t */\n+\t@Override\n+\tpublic void deactivate() {\n+\t\tif (this.satelModule != null) {\n+\t\t\tthis.satelModule.close();\n+\t\t\tthis.satelModule = null;\n+\t\t}\n+\t}\n+\n+\tprivate List<SatelMessage> getRefreshCommands() {\n+\t\tlogger.debug(\"Gathering refresh commands from all items\");","path":"bundles/binding/org.openhab.binding.satel/src/main/java/org/openhab/binding/satel/internal/SatelBinding.java","position":null,"original_position":185,"commit_id":"d2e87232e59a393bfa98adbd256abe298ae6d767","original_commit_id":"a5e76b5a5f253ab0e4c2a41435f917cb660ee23e","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 decrease to TRACE","created_at":"2015-02-23T08:32:25Z","updated_at":"2015-02-23T08:32:25Z","html_url":"https://github.com/openhab/openhab/pull/1750#discussion_r25149064","pull_request_url":"https://api.github.com/repos/openhab/openhab/pulls/1750","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments/25149064"},"html":{"href":"https://github.com/openhab/openhab/pull/1750#discussion_r25149064"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1750"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab/pulls/1750","id":25167561,"html_url":"https://github.com/openhab/openhab/pull/1750","diff_url":"https://github.com/openhab/openhab/pull/1750.diff","patch_url":"https://github.com/openhab/openhab/pull/1750.patch","issue_url":"https://api.github.com/repos/openhab/openhab/issues/1750","number":1750,"state":"open","locked":false,"title":"[new binding] Initial version of Satel Integra security system binding","user":{"login":"druciak","id":998582,"avatar_url":"https://avatars.githubusercontent.com/u/998582?v=3","gravatar_id":"","url":"https://api.github.com/users/druciak","html_url":"https://github.com/druciak","followers_url":"https://api.github.com/users/druciak/followers","following_url":"https://api.github.com/users/druciak/following{/other_user}","gists_url":"https://api.github.com/users/druciak/gists{/gist_id}","starred_url":"https://api.github.com/users/druciak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druciak/subscriptions","organizations_url":"https://api.github.com/users/druciak/orgs","repos_url":"https://api.github.com/users/druciak/repos","events_url":"https://api.github.com/users/druciak/events{/privacy}","received_events_url":"https://api.github.com/users/druciak/received_events","type":"User","site_admin":false},"body":"This PR replaces  #1723.","created_at":"2014-11-27T19:35:37Z","updated_at":"2015-02-23T08:32:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b157e49dc31a0408117fef803ca105b600fecb66","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab/pulls/1750/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab/pulls/1750/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab/issues/1750/comments","statuses_url":"https://api.github.com/repos/openhab/openhab/statuses/d2e87232e59a393bfa98adbd256abe298ae6d767","head":{"label":"druciak:satel_binding","ref":"satel_binding","sha":"d2e87232e59a393bfa98adbd256abe298ae6d767","user":{"login":"druciak","id":998582,"avatar_url":"https://avatars.githubusercontent.com/u/998582?v=3","gravatar_id":"","url":"https://api.github.com/users/druciak","html_url":"https://github.com/druciak","followers_url":"https://api.github.com/users/druciak/followers","following_url":"https://api.github.com/users/druciak/following{/other_user}","gists_url":"https://api.github.com/users/druciak/gists{/gist_id}","starred_url":"https://api.github.com/users/druciak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druciak/subscriptions","organizations_url":"https://api.github.com/users/druciak/orgs","repos_url":"https://api.github.com/users/druciak/repos","events_url":"https://api.github.com/users/druciak/events{/privacy}","received_events_url":"https://api.github.com/users/druciak/received_events","type":"User","site_admin":false},"repo":{"id":24363310,"name":"openhab","full_name":"druciak/openhab","owner":{"login":"druciak","id":998582,"avatar_url":"https://avatars.githubusercontent.com/u/998582?v=3","gravatar_id":"","url":"https://api.github.com/users/druciak","html_url":"https://github.com/druciak","followers_url":"https://api.github.com/users/druciak/followers","following_url":"https://api.github.com/users/druciak/following{/other_user}","gists_url":"https://api.github.com/users/druciak/gists{/gist_id}","starred_url":"https://api.github.com/users/druciak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druciak/subscriptions","organizations_url":"https://api.github.com/users/druciak/orgs","repos_url":"https://api.github.com/users/druciak/repos","events_url":"https://api.github.com/users/druciak/events{/privacy}","received_events_url":"https://api.github.com/users/druciak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/druciak/openhab","description":"Source code of the open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/druciak/openhab","forks_url":"https://api.github.com/repos/druciak/openhab/forks","keys_url":"https://api.github.com/repos/druciak/openhab/keys{/key_id}","collaborators_url":"https://api.github.com/repos/druciak/openhab/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/druciak/openhab/teams","hooks_url":"https://api.github.com/repos/druciak/openhab/hooks","issue_events_url":"https://api.github.com/repos/druciak/openhab/issues/events{/number}","events_url":"https://api.github.com/repos/druciak/openhab/events","assignees_url":"https://api.github.com/repos/druciak/openhab/assignees{/user}","branches_url":"https://api.github.com/repos/druciak/openhab/branches{/branch}","tags_url":"https://api.github.com/repos/druciak/openhab/tags","blobs_url":"https://api.github.com/repos/druciak/openhab/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/druciak/openhab/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/druciak/openhab/git/refs{/sha}","trees_url":"https://api.github.com/repos/druciak/openhab/git/trees{/sha}","statuses_url":"https://api.github.com/repos/druciak/openhab/statuses/{sha}","languages_url":"https://api.github.com/repos/druciak/openhab/languages","stargazers_url":"https://api.github.com/repos/druciak/openhab/stargazers","contributors_url":"https://api.github.com/repos/druciak/openhab/contributors","subscribers_url":"https://api.github.com/repos/druciak/openhab/subscribers","subscription_url":"https://api.github.com/repos/druciak/openhab/subscription","commits_url":"https://api.github.com/repos/druciak/openhab/commits{/sha}","git_commits_url":"https://api.github.com/repos/druciak/openhab/git/commits{/sha}","comments_url":"https://api.github.com/repos/druciak/openhab/comments{/number}","issue_comment_url":"https://api.github.com/repos/druciak/openhab/issues/comments{/number}","contents_url":"https://api.github.com/repos/druciak/openhab/contents/{+path}","compare_url":"https://api.github.com/repos/druciak/openhab/compare/{base}...{head}","merges_url":"https://api.github.com/repos/druciak/openhab/merges","archive_url":"https://api.github.com/repos/druciak/openhab/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/druciak/openhab/downloads","issues_url":"https://api.github.com/repos/druciak/openhab/issues{/number}","pulls_url":"https://api.github.com/repos/druciak/openhab/pulls{/number}","milestones_url":"https://api.github.com/repos/druciak/openhab/milestones{/number}","notifications_url":"https://api.github.com/repos/druciak/openhab/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/druciak/openhab/labels{/name}","releases_url":"https://api.github.com/repos/druciak/openhab/releases{/id}","created_at":"2014-09-23T08:36:31Z","updated_at":"2015-01-08T18:12:51Z","pushed_at":"2015-02-23T06:50:43Z","git_url":"git://github.com/druciak/openhab.git","ssh_url":"git@github.com:druciak/openhab.git","clone_url":"https://github.com/druciak/openhab.git","svn_url":"https://github.com/druciak/openhab","homepage":null,"size":144096,"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":"47a2b2848350c7454f51478627b8b4939ed41ecc","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-02-23T03:54:43Z","pushed_at":"2015-02-22T17:48:10Z","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":192912,"stargazers_count":1107,"watchers_count":1107,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":667,"mirror_url":null,"open_issues_count":444,"forks":667,"open_issues":444,"watchers":1107,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1750"},"html":{"href":"https://github.com/openhab/openhab/pull/1750"},"issue":{"href":"https://api.github.com/repos/openhab/openhab/issues/1750"},"comments":{"href":"https://api.github.com/repos/openhab/openhab/issues/1750/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1750/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab/pulls/1750/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab/statuses/d2e87232e59a393bfa98adbd256abe298ae6d767"}}}}