{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/114025436","pull_request_review_id":35466798,"id":114025436,"diff_hunk":"@@ -0,0 +1,162 @@\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.homepilot.discovery;\n+\n+import static org.openhab.binding.homepilot.HomePilotBindingConstants.*;\n+\n+import java.util.List;\n+import java.util.concurrent.CancellationException;\n+import java.util.concurrent.Future;\n+\n+import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;\n+import org.eclipse.smarthome.config.discovery.DiscoveryResult;\n+import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;\n+import org.eclipse.smarthome.config.discovery.DiscoveryServiceCallback;\n+import org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService;\n+import org.eclipse.smarthome.core.thing.ThingTypeUID;\n+import org.eclipse.smarthome.core.thing.ThingUID;\n+import org.openhab.binding.homepilot.handler.HomePilotBridgeHandler;\n+import org.openhab.binding.homepilot.internal.HomePilotDevice;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import com.google.common.collect.ImmutableSet;\n+\n+/**\n+ * The {@link HomePilotDeviceDiscoveryService} is used to discover devices that are connected to a Homematic gateway.\n+ *\n+ * @author Gerhard Riegler - Initial contribution\n+ */\n+public class HomePilotDeviceDiscoveryService extends AbstractDiscoveryService implements ExtendedDiscoveryService {\n+    private static final Logger logger = LoggerFactory.getLogger(HomePilotDeviceDiscoveryService.class);\n+    private static final int DISCOVER_TIMEOUT_SECONDS = 300;\n+\n+    private HomePilotBridgeHandler bridgeHandler;\n+    private Future<?> scanFuture;\n+    private DiscoveryServiceCallback discoveryServiceCallback;\n+\n+    public HomePilotDeviceDiscoveryService(HomePilotBridgeHandler bridgeHandler) {\n+        super(ImmutableSet.of(new ThingTypeUID(BINDING_ID, \"-\")), DISCOVER_TIMEOUT_SECONDS, false);\n+        this.bridgeHandler = bridgeHandler;\n+    }\n+\n+    /**\n+     * Called on component activation.\n+     */\n+    public void activate() {\n+        super.activate(null);\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    @Override\n+    public void deactivate() {\n+        super.deactivate();\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    @Override\n+    protected void startScan() {\n+        logger.info(\"Starting HomePilot discovery scan\");\n+        loadDevices();\n+    }\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    @Override\n+    public synchronized void stopScan() {\n+        logger.info(\"Stopping HomePilot discovery scan\");\n+        bridgeHandler.getGateway().cancelLoadAllDevices();\n+        waitForScanFinishing();\n+        super.stopScan();\n+    }\n+\n+    /**\n+     * Waits for the discovery scan to finish and then returns.\n+     */\n+    public void waitForScanFinishing() {\n+        if (scanFuture != null) {\n+            logger.info(\"Waiting for finishing HomePilot device discovery scan\");\n+            try {\n+                scanFuture.get();\n+                logger.debug(\"HomePilot device discovery scan finished\");\n+            } catch (CancellationException ex) {\n+                // ignore\n+            } catch (Exception ex) {\n+                logger.error(\"Error waiting for device discovery scan: {}\", ex.getMessage(), ex);\n+            }\n+        }\n+    }\n+\n+    /**\n+     * Starts a thread which loads all Homematic devices connected to the gateway.\n+     */\n+    public void loadDevices() {\n+        if (scanFuture == null) {\n+            scanFuture = scheduler.submit(new Runnable() {\n+\n+                @Override\n+                public void run() {\n+                    try {\n+                        List<HomePilotDevice> allKnownDevices = bridgeHandler.getGateway().loadAllDevices();\n+                        // discover all things\n+                        for (HomePilotDevice device : allKnownDevices) {\n+                            ThingUID uid = createUID(device);\n+                            deviceDiscovered(uid, device);\n+                        }\n+\n+                        logger.debug(\"Finished HomePilot device discovery scan on gateway '{}'\",\n+                                bridgeHandler.getGateway().getId());\n+                    } catch (Throwable ex) {\n+                        logger.error(ex.getMessage(), ex);\n+                    } finally {\n+                        scanFuture = null;\n+                        bridgeHandler.setOfflineStatus();\n+                        removeOlderResults(getTimestampOfLastScan());\n+                    }\n+                }\n+            });\n+        } else {\n+            logger.debug(\"HomePilot devices discovery scan in progress\");\n+        }\n+    }\n+\n+    private void deviceRemoved(ThingUID thingUID) {\n+        thingRemoved(thingUID);\n+    }\n+\n+    private void deviceDiscovered(ThingUID thingUID, HomePilotDevice device) {\n+        // device.setU\n+        String label = device.getName() != null ? device.getName() : \"unknown\";\n+\n+        if (discoveryServiceCallback.getExistingDiscoveryResult(thingUID) == null\n+                && discoveryServiceCallback.getExistingThing(thingUID) == null) {\n+            DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)\n+                    .withBridge(bridgeHandler.getThing().getUID()).withLabel(label)\n+                    .withProperty(\"description\", device.getDescription())\n+                    .withProperty(CHANNEL_POSITION, device.getPosition()).build();\n+            thingDiscovered(discoveryResult);\n+        }\n+    }\n+\n+    private ThingUID createUID(HomePilotDevice device) {\n+        ThingUID bridgeUID = bridgeHandler.getThing().getUID();\n+        ThingUID thingUID = new ThingUID(device.getTypeUID(), bridgeUID, device.getDeviceId());","path":"addons/binding/org.openhab.binding.homepilot/src/main/java/org/openhab/binding/homepilot/discovery/HomePilotDeviceDiscoveryService.java","position":154,"original_position":154,"commit_id":"eccd87bd1d390ceef529ee5f2a6d36d7935dabfa","original_commit_id":"eccd87bd1d390ceef529ee5f2a6d36d7935dabfa","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":"Unneeded local before return","created_at":"2017-04-28T21:44:15Z","updated_at":"2017-04-28T21:58:22Z","html_url":"https://github.com/openhab/openhab2-addons/pull/1685#discussion_r114025436","pull_request_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/comments/114025436"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1685#discussion_r114025436"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685","id":100958401,"html_url":"https://github.com/openhab/openhab2-addons/pull/1685","diff_url":"https://github.com/openhab/openhab2-addons/pull/1685.diff","patch_url":"https://github.com/openhab/openhab2-addons/pull/1685.patch","issue_url":"https://api.github.com/repos/openhab/openhab2-addons/issues/1685","number":1685,"state":"open","locked":false,"title":"HomePilot","user":{"login":"stundzig","id":1140546,"avatar_url":"https://avatars3.githubusercontent.com/u/1140546?v=3","gravatar_id":"","url":"https://api.github.com/users/stundzig","html_url":"https://github.com/stundzig","followers_url":"https://api.github.com/users/stundzig/followers","following_url":"https://api.github.com/users/stundzig/following{/other_user}","gists_url":"https://api.github.com/users/stundzig/gists{/gist_id}","starred_url":"https://api.github.com/users/stundzig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stundzig/subscriptions","organizations_url":"https://api.github.com/users/stundzig/orgs","repos_url":"https://api.github.com/users/stundzig/repos","events_url":"https://api.github.com/users/stundzig/events{/privacy}","received_events_url":"https://api.github.com/users/stundzig/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\ni've created my first draft of the homepilot addon.\r\n\r\nDevice Discovery, Switch on/off and dim of Rohrmotor and Universal Actor is working great.\r\n\r\nWhat is the correct way, to contribute to the main source tree?\r\n\r\nRegards\r\n   Steffen...","created_at":"2017-01-10T21:36:55Z","updated_at":"2017-04-28T21:58:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc9e27c7c352abe9f29bcec0e457add6008456b3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685/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/1685/comments","statuses_url":"https://api.github.com/repos/openhab/openhab2-addons/statuses/eccd87bd1d390ceef529ee5f2a6d36d7935dabfa","head":{"label":"stundzig:homepilot","ref":"homepilot","sha":"eccd87bd1d390ceef529ee5f2a6d36d7935dabfa","user":{"login":"stundzig","id":1140546,"avatar_url":"https://avatars3.githubusercontent.com/u/1140546?v=3","gravatar_id":"","url":"https://api.github.com/users/stundzig","html_url":"https://github.com/stundzig","followers_url":"https://api.github.com/users/stundzig/followers","following_url":"https://api.github.com/users/stundzig/following{/other_user}","gists_url":"https://api.github.com/users/stundzig/gists{/gist_id}","starred_url":"https://api.github.com/users/stundzig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stundzig/subscriptions","organizations_url":"https://api.github.com/users/stundzig/orgs","repos_url":"https://api.github.com/users/stundzig/repos","events_url":"https://api.github.com/users/stundzig/events{/privacy}","received_events_url":"https://api.github.com/users/stundzig/received_events","type":"User","site_admin":false},"repo":{"id":78563659,"name":"openhab2-addons","full_name":"stundzig/openhab2-addons","owner":{"login":"stundzig","id":1140546,"avatar_url":"https://avatars3.githubusercontent.com/u/1140546?v=3","gravatar_id":"","url":"https://api.github.com/users/stundzig","html_url":"https://github.com/stundzig","followers_url":"https://api.github.com/users/stundzig/followers","following_url":"https://api.github.com/users/stundzig/following{/other_user}","gists_url":"https://api.github.com/users/stundzig/gists{/gist_id}","starred_url":"https://api.github.com/users/stundzig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stundzig/subscriptions","organizations_url":"https://api.github.com/users/stundzig/orgs","repos_url":"https://api.github.com/users/stundzig/repos","events_url":"https://api.github.com/users/stundzig/events{/privacy}","received_events_url":"https://api.github.com/users/stundzig/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stundzig/openhab2-addons","description":"The next-generation open Home Automation Bus (openHAB)","fork":true,"url":"https://api.github.com/repos/stundzig/openhab2-addons","forks_url":"https://api.github.com/repos/stundzig/openhab2-addons/forks","keys_url":"https://api.github.com/repos/stundzig/openhab2-addons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stundzig/openhab2-addons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stundzig/openhab2-addons/teams","hooks_url":"https://api.github.com/repos/stundzig/openhab2-addons/hooks","issue_events_url":"https://api.github.com/repos/stundzig/openhab2-addons/issues/events{/number}","events_url":"https://api.github.com/repos/stundzig/openhab2-addons/events","assignees_url":"https://api.github.com/repos/stundzig/openhab2-addons/assignees{/user}","branches_url":"https://api.github.com/repos/stundzig/openhab2-addons/branches{/branch}","tags_url":"https://api.github.com/repos/stundzig/openhab2-addons/tags","blobs_url":"https://api.github.com/repos/stundzig/openhab2-addons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stundzig/openhab2-addons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stundzig/openhab2-addons/git/refs{/sha}","trees_url":"https://api.github.com/repos/stundzig/openhab2-addons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stundzig/openhab2-addons/statuses/{sha}","languages_url":"https://api.github.com/repos/stundzig/openhab2-addons/languages","stargazers_url":"https://api.github.com/repos/stundzig/openhab2-addons/stargazers","contributors_url":"https://api.github.com/repos/stundzig/openhab2-addons/contributors","subscribers_url":"https://api.github.com/repos/stundzig/openhab2-addons/subscribers","subscription_url":"https://api.github.com/repos/stundzig/openhab2-addons/subscription","commits_url":"https://api.github.com/repos/stundzig/openhab2-addons/commits{/sha}","git_commits_url":"https://api.github.com/repos/stundzig/openhab2-addons/git/commits{/sha}","comments_url":"https://api.github.com/repos/stundzig/openhab2-addons/comments{/number}","issue_comment_url":"https://api.github.com/repos/stundzig/openhab2-addons/issues/comments{/number}","contents_url":"https://api.github.com/repos/stundzig/openhab2-addons/contents/{+path}","compare_url":"https://api.github.com/repos/stundzig/openhab2-addons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stundzig/openhab2-addons/merges","archive_url":"https://api.github.com/repos/stundzig/openhab2-addons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stundzig/openhab2-addons/downloads","issues_url":"https://api.github.com/repos/stundzig/openhab2-addons/issues{/number}","pulls_url":"https://api.github.com/repos/stundzig/openhab2-addons/pulls{/number}","milestones_url":"https://api.github.com/repos/stundzig/openhab2-addons/milestones{/number}","notifications_url":"https://api.github.com/repos/stundzig/openhab2-addons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stundzig/openhab2-addons/labels{/name}","releases_url":"https://api.github.com/repos/stundzig/openhab2-addons/releases{/id}","deployments_url":"https://api.github.com/repos/stundzig/openhab2-addons/deployments","created_at":"2017-01-10T18:54:45Z","updated_at":"2017-01-10T18:54:52Z","pushed_at":"2017-01-12T13:45:02Z","git_url":"git://github.com/stundzig/openhab2-addons.git","ssh_url":"git@github.com:stundzig/openhab2-addons.git","clone_url":"https://github.com/stundzig/openhab2-addons.git","svn_url":"https://github.com/stundzig/openhab2-addons","homepage":null,"size":64177,"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-28T15:16:48Z","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":251936,"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":955,"mirror_url":null,"open_issues_count":326,"forks":955,"open_issues":326,"watchers":569,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685"},"html":{"href":"https://github.com/openhab/openhab2-addons/pull/1685"},"issue":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1685"},"comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/issues/1685/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab2-addons/pulls/1685/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/1685/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab2-addons/statuses/eccd87bd1d390ceef529ee5f2a6d36d7935dabfa"}}}}
{"actor":{"display_login":"martinvw"}}