{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab/pulls/comments/65092619","id":65092619,"diff_hunk":"@@ -0,0 +1,190 @@\n+/**\n+ * Copyright (c) 2010-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.action.satel.internal;\n+\n+import java.io.UnsupportedEncodingException;\n+import java.util.Map;\n+import java.util.concurrent.ConcurrentHashMap;\n+\n+import org.openhab.binding.satel.command.ReadDeviceInfoCommand;\n+import org.openhab.binding.satel.command.ReadDeviceInfoCommand.DeviceType;\n+import org.openhab.binding.satel.command.ReadEventCommand;\n+import org.openhab.binding.satel.command.ReadEventCommand.EventClass;\n+import org.openhab.binding.satel.command.ReadEventDescCommand;\n+import org.openhab.core.library.types.DateTimeType;\n+import org.openhab.core.scriptengine.action.ActionDoc;\n+import org.openhab.core.scriptengine.action.ParamDoc;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * This class contains the methods that are made available in scripts and rules\n+ * for Satel.\n+ *\n+ * @author Krzysztof Goworek\n+ * @since 1.9.0\n+ */\n+public class Satel {\n+\n+    private static final Logger logger = LoggerFactory.getLogger(Satel.class);\n+    private static Map<String, EventDescription> eventDescriptions = new ConcurrentHashMap<String, EventDescription>();\n+\n+    /**\n+     * Checks current connection status to the communication module.\n+     * \n+     * @return <code>true</code> if connection is established\n+     */\n+    @ActionDoc(text = \"Check current connection status to Satel communication module\", returns = \"<code>true</code>, if connected and <code>false</code> otherwise.\")\n+    public static boolean satelIsConnected() {\n+        if (!SatelActionService.isProperlyConfigured) {\n+            logger.debug(\"Satel action is not yet configured - execution aborted!\");\n+            return false;\n+        }\n+        if (SatelActionService.satelCommModule == null) {\n+            logger.debug(\"Satel communication module not available - execution aborted!\");\n+            return false;\n+        }\n+        if (!SatelActionService.satelCommModule.isConnected()) {\n+            logger.debug(\"Satel communication module is not connected\");\n+            return false;\n+        }\n+        return true;\n+    }\n+\n+    /**\n+     * Read event log record from the alarm system for given index.\n+     * For the most recent record pass <code>-1</code> as index,\n+     * next records can be retrieved by using next index value in the record data (the last field in a record).\n+     * \n+     * Fields in the record:\n+     * <ol>\n+     * <li>timestamp - {@link DateTimeType}</li>\n+     * <li>partition - String</li>\n+     * <li>event class - {@link EventClass}</li>\n+     * <li>event code - Integer}</li>\n+     * <li>state restoration flag - Boolean</li>\n+     * <li>event description - String</li>\n+     * <li>kind of description - Integer</li>\n+     * <li>source - Integer</li>\n+     * <li>object - Integer</li>\n+     * <li>user control number - Integer</li>\n+     * <li>next record index - Integer</li>\n+     * <li>current record index - Integer</li>\n+     * </ol>\n+     * \n+     * <p>\n+     * The details about each field meaning can be found in protocol documentation.\n+     * </p>\n+     * \n+     * @param eventIndex event log record index to read\n+     * @return event as array of objects\n+     */\n+    @ActionDoc(text = \"Returns record from the event log for given index\", returns = \"Array of values: timestamp, partition, event class, event code, restore, event description, kind og description, source, object, user control object, next event index, current event index\")\n+    public static Object[] satelReadEvent(\n+            @ParamDoc(name = \"eventIndex\", text = \"index of event to read, -1 for the most recent\") int eventIndex) {\n+        if (!satelIsConnected()) {\n+            return null;\n+        }\n+        ReadEventCommand cmd = new ReadEventCommand(eventIndex);\n+        if (!SatelActionService.satelCommModule.sendCommand(cmd)) {\n+            logger.error(\"Unable to read record for given index: {}\", eventIndex);\n+            return null;\n+        } else if (cmd.isEmpty()) {\n+            logger.warn(\"No record under given index: {}\", eventIndex);\n+            return null;\n+        } else {\n+            EventDescription desc = getEventDescription(cmd.getEventCode(), cmd.isRestore());\n+            return new Object[] { new DateTimeType(cmd.getTimestamp()), cmd.getPartition(), cmd.getEventClass(),\n+                    cmd.getEventCode(), cmd.isRestore(), desc.eventText, desc.descKind, cmd.getSource(),\n+                    cmd.getObject(), cmd.getUserControlNumber(), cmd.getNextIndex(), cmd.getCurrentIndex() };\n+        }\n+    }\n+\n+    /**\n+     * Reads name of alarm system's device.\n+     * Device types:\n+     * <ul>\n+     * <li>PARTITION</li>\n+     * <li>ZONE</li>\n+     * <li>USER</li>\n+     * <li>EXPANDER</li>\n+     * <li>LCD</li>\n+     * <li>OUTPUT</li>\n+     * <li>TIMER</li>\n+     * <li>TELEPHONE</li>\n+     * <li>OBJECT</li>\n+     * </ul>\n+     * \n+     * @param deviceType type of the device\n+     * @param deviceNumber number of the device\n+     * @return string representing device's name or <code>null</code> if device is not present or an error occurred\n+     */\n+    @ActionDoc(text = \"Returns name of a device.\")\n+    public static String satelReadDeviceName(\n+            @ParamDoc(name = \"deviceType\", text = \"type of the device, one of: PARTITION, ZONE, USER, EXPANDER, LCD, OUTPUT, TIMER, TELEPHONE, OBJECT\") String deviceType,\n+            @ParamDoc(name = \"deviceNumber\", text = \"number of the device to read\") int deviceNumber) {\n+        if (!satelIsConnected()) {\n+            return null;","path":"bundles/action/org.openhab.action.satel/src/main/java/org/openhab/action/satel/internal/Satel.java","position":133,"original_position":133,"commit_id":"c440a8e8e97210ae24e1ed4e12d389e8099efbeb","original_commit_id":"c440a8e8e97210ae24e1ed4e12d389e8099efbeb","user":{"login":"watou","id":3008217,"avatar_url":"https://avatars.githubusercontent.com/u/3008217?v=3","gravatar_id":"","url":"https://api.github.com/users/watou","html_url":"https://github.com/watou","followers_url":"https://api.github.com/users/watou/followers","following_url":"https://api.github.com/users/watou/following{/other_user}","gists_url":"https://api.github.com/users/watou/gists{/gist_id}","starred_url":"https://api.github.com/users/watou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watou/subscriptions","organizations_url":"https://api.github.com/users/watou/orgs","repos_url":"https://api.github.com/users/watou/repos","events_url":"https://api.github.com/users/watou/events{/privacy}","received_events_url":"https://api.github.com/users/watou/received_events","type":"User","site_admin":false},"body":"I mean that a user would call `satelReadDeviceName`, but would get back `null` with no other feedback in the log or otherwise, leaving them to wonder why they got `null`.","created_at":"2016-05-30T16:54:32Z","updated_at":"2016-05-30T16:54:32Z","html_url":"https://github.com/openhab/openhab/pull/3290#discussion_r65092619","pull_request_url":"https://api.github.com/repos/openhab/openhab/pulls/3290","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments/65092619"},"html":{"href":"https://github.com/openhab/openhab/pull/3290#discussion_r65092619"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab/pulls/3290"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab/pulls/3290","id":47460112,"html_url":"https://github.com/openhab/openhab/pull/3290","diff_url":"https://github.com/openhab/openhab/pull/3290.diff","patch_url":"https://github.com/openhab/openhab/pull/3290.patch","issue_url":"https://api.github.com/repos/openhab/openhab/issues/3290","number":3290,"state":"open","locked":false,"title":"[Satel] action added, binding refactored.","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 introduces action bundle for Satel. Action bundle contains 3 actions at the moment:\r\n- _satelIsConnected_ - returns _true_ if OH is connected to configured module\r\n- _satelReadEvent_ - reads single record from alarm system's event log\r\n- _satelReadDeviceName_ - reads device name to convert device ids to text\r\n\r\nFor this purpose Satel binding exposes a service which allows sending commands directly and synchronously to communication module and therefore it also needed bigger changes.","created_at":"2015-10-12T20:19:34Z","updated_at":"2016-05-30T16:54:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"290ed0783af3f9a155e8aa63ac2475f11caf32be","assignee":null,"milestone":{"url":"https://api.github.com/repos/openhab/openhab/milestones/12","html_url":"https://github.com/openhab/openhab/milestones/1.9.0","labels_url":"https://api.github.com/repos/openhab/openhab/milestones/12/labels","id":1479830,"number":12,"title":"1.9.0","description":"","creator":{"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},"open_issues":44,"closed_issues":189,"state":"open","created_at":"2016-01-01T16:37:00Z","updated_at":"2016-05-30T12:19:00Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/openhab/openhab/pulls/3290/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab/pulls/3290/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab/issues/3290/comments","statuses_url":"https://api.github.com/repos/openhab/openhab/statuses/c440a8e8e97210ae24e1ed4e12d389e8099efbeb","head":{"label":"druciak:satel_action","ref":"satel_action","sha":"c440a8e8e97210ae24e1ed4e12d389e8099efbeb","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}","deployments_url":"https://api.github.com/repos/druciak/openhab/deployments","created_at":"2014-09-23T08:36:31Z","updated_at":"2016-01-20T19:10:30Z","pushed_at":"2016-05-29T11:28:45Z","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":200547,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"openhab:master","ref":"master","sha":"11ca7ba6a9dc8223ef726c3a035db30d3f3cdbf1","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}","deployments_url":"https://api.github.com/repos/openhab/openhab/deployments","created_at":"2013-09-20T20:28:43Z","updated_at":"2016-05-30T14:48:33Z","pushed_at":"2016-05-30T12:19:00Z","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":288540,"stargazers_count":2630,"watchers_count":2630,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1329,"mirror_url":null,"open_issues_count":331,"forks":1329,"open_issues":331,"watchers":2630,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab/pulls/3290"},"html":{"href":"https://github.com/openhab/openhab/pull/3290"},"issue":{"href":"https://api.github.com/repos/openhab/openhab/issues/3290"},"comments":{"href":"https://api.github.com/repos/openhab/openhab/issues/3290/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab/pulls/3290/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab/pulls/3290/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab/statuses/c440a8e8e97210ae24e1ed4e12d389e8099efbeb"}}}}
{"actor":{"display_login":"watou"}}