{"action":"created","comment":{"url":"https://api.github.com/repos/eclipse/smarthome/pulls/comments/130320519","pull_request_review_id":53178269,"id":130320519,"diff_hunk":"@@ -0,0 +1,142 @@\n+/**\n+ * Copyright (c) 2014-2017 by the respective copyright holders.\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.eclipse.smarthome.config.discovery.internal;\n+\n+import java.util.List;\n+import java.util.Map;\n+\n+import org.eclipse.smarthome.config.discovery.DiscoveryResult;\n+import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;\n+import org.eclipse.smarthome.config.discovery.inbox.Inbox;\n+import org.eclipse.smarthome.config.discovery.inbox.InboxFilterCriteria;\n+import org.eclipse.smarthome.core.events.AbstractTypedEventSubscriber;\n+import org.eclipse.smarthome.core.events.EventSubscriber;\n+import org.eclipse.smarthome.core.thing.Thing;\n+import org.eclipse.smarthome.core.thing.ThingRegistry;\n+import org.eclipse.smarthome.core.thing.ThingStatus;\n+import org.eclipse.smarthome.core.thing.binding.ThingHandler;\n+import org.eclipse.smarthome.core.thing.events.ThingStatusInfoChangedEvent;\n+import org.osgi.service.component.annotations.Activate;\n+import org.osgi.service.component.annotations.Component;\n+import org.osgi.service.component.annotations.Reference;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * This class implements a service to automatically ignore {@link Inbox} entries of newly created things.\n+ * <p>\n+ * The {@link InboxAutoIgnore} service implements a {@link EventSubscriber}, that is triggered\n+ * for each thing when coming ONLINE. {@link Inbox} entries with the same device id like the\n+ * newly created thing will be automatically set to {@link DiscoveryResultFlag#IGNORED}.\n+ * </p>\n+ * <p>\n+ * If a thing is being removed, possibly existing {@link Inbox} entries with the same device id\n+ * are removed from the {@link Inbox} so they could be discovered again afterwards.\n+ * </p>\n+ * <p>\n+ * This service can be enabled or disabled by setting the {@code autoIgnore} property to either\n+ * {@code true} or {@code false} via ConfigAdmin.\n+ * </p>\n+ *\n+ * @author Andre Fuechsel - Initial Contribution\n+ */\n+@Component(immediate = true, service = EventSubscriber.class, property = {\n+        \"service.config.description.uri=system:inbox\", \"service.config.label=Inbox Auto Ignore\",\n+        \"service.config.category=system\", \"service.pid=org.eclipse.smarthome.inbox\" })\n+public class InboxAutoIgnore extends AbstractTypedEventSubscriber<ThingStatusInfoChangedEvent> {\n+\n+    private final Logger logger = LoggerFactory.getLogger(this.getClass());\n+\n+    private ThingRegistry thingRegistry;\n+    private Inbox inbox;\n+    private boolean autoIgnore = true;\n+\n+    public InboxAutoIgnore() {\n+        super(ThingStatusInfoChangedEvent.TYPE);\n+    }\n+\n+    @Override\n+    public void receiveTypedEvent(ThingStatusInfoChangedEvent event) {\n+        if (autoIgnore) {\n+            if (ThingStatus.ONLINE.equals(event.getStatusInfo().getStatus())) {\n+                checkAndIgnoreInInbox(event);\n+            } else if (ThingStatus.REMOVING.equals(event.getStatusInfo().getStatus())) {\n+                removePossiblyIgnoredResultInInbox(event);\n+            }\n+        }\n+    }\n+\n+    private void checkAndIgnoreInInbox(ThingStatusInfoChangedEvent event) {\n+        Thing thing = thingRegistry.get(event.getThingUID());\n+        if (thing != null) {\n+            ThingHandler handler = thing.getHandler();\n+            if (handler != null) {\n+                String deviceUid = handler.getDeviceId();\n+                if (deviceUid != null) {\n+                    ignoreInInbox(deviceUid);\n+                }\n+            }\n+        }\n+    }\n+\n+    private void ignoreInInbox(String deviceUid) {\n+        List<DiscoveryResult> results = inbox.get(InboxFilterCriteria.representationFilter(deviceUid, null));\n+        if (results.size() == 1) {\n+            logger.debug(\"Auto-ignoring the inbox entry for the device uid {}\", deviceUid);\n+            inbox.setFlag(results.get(0).getThingUID(), DiscoveryResultFlag.IGNORED);\n+        }\n+    }\n+\n+    private void removePossiblyIgnoredResultInInbox(ThingStatusInfoChangedEvent event) {\n+        Thing thing = thingRegistry.get(event.getThingUID());\n+        if (thing != null) {\n+            ThingHandler handler = thing.getHandler();\n+            if (handler != null) {\n+                String deviceUid = handler.getDeviceId();\n+                if (deviceUid != null) {\n+                    removeFromInbox(deviceUid);\n+                }\n+            }\n+        }\n+    }\n+\n+    private void removeFromInbox(String deviceUid) {\n+        List<DiscoveryResult> results = inbox\n+                .get(InboxFilterCriteria.representationFilter(deviceUid, DiscoveryResultFlag.IGNORED));\n+        if (results.size() == 1) {\n+            logger.debug(\"Removing the ignored result from the inbox for the device uid {}\", deviceUid);\n+            inbox.remove(results.get(0).getThingUID());\n+        }\n+    }\n+\n+    @Activate\n+    protected void activate(Map<String, String> properties) {\n+        if (properties != null) {\n+            String value = properties.get(\"autoIgnore\");\n+            autoIgnore = value == null || !value.toString().equals(\"false\");\n+        }\n+    }\n+\n+    @Reference\n+    protected void setThingRegistry(ThingRegistry thingRegistry) {\n+        this.thingRegistry = thingRegistry;\n+    }\n+\n+    protected void unsetThingRegistry(ThingRegistry thingRegistry) {","path":"bundles/config/org.eclipse.smarthome.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/InboxAutoIgnore.java","position":130,"original_position":130,"commit_id":"05670bf54731df2f219904788a82f2f51cf1b501","original_commit_id":"05670bf54731df2f219904788a82f2f51cf1b501","user":{"login":"kaikreuzer","id":3244965,"avatar_url":"https://avatars3.githubusercontent.com/u/3244965?v=4","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":"Sorry, I haven't yet used the annotations myself: Is the \"unset\" automatically derived from the name of the `@Reference`-annotated method?","created_at":"2017-07-31T10:35:52Z","updated_at":"2017-07-31T10:41:32Z","html_url":"https://github.com/eclipse/smarthome/pull/3899#discussion_r130320519","pull_request_url":"https://api.github.com/repos/eclipse/smarthome/pulls/3899","_links":{"self":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/comments/130320519"},"html":{"href":"https://github.com/eclipse/smarthome/pull/3899#discussion_r130320519"},"pull_request":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/3899"}}},"pull_request":{"url":"https://api.github.com/repos/eclipse/smarthome/pulls/3899","id":132687015,"html_url":"https://github.com/eclipse/smarthome/pull/3899","diff_url":"https://github.com/eclipse/smarthome/pull/3899.diff","patch_url":"https://github.com/eclipse/smarthome/pull/3899.patch","issue_url":"https://api.github.com/repos/eclipse/smarthome/issues/3899","number":3899,"state":"open","locked":false,"title":"added ThingHandler#getDeviceId() and InboxAutoIgnore service","user":{"login":"afuechsel","id":6408058,"avatar_url":"https://avatars1.githubusercontent.com/u/6408058?v=4","gravatar_id":"","url":"https://api.github.com/users/afuechsel","html_url":"https://github.com/afuechsel","followers_url":"https://api.github.com/users/afuechsel/followers","following_url":"https://api.github.com/users/afuechsel/following{/other_user}","gists_url":"https://api.github.com/users/afuechsel/gists{/gist_id}","starred_url":"https://api.github.com/users/afuechsel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afuechsel/subscriptions","organizations_url":"https://api.github.com/users/afuechsel/orgs","repos_url":"https://api.github.com/users/afuechsel/repos","events_url":"https://api.github.com/users/afuechsel/events{/privacy}","received_events_url":"https://api.github.com/users/afuechsel/received_events","type":"User","site_admin":false},"body":"implemented device id in the hue binding\r\nadded a representation property for a hue light\r\n\r\nFixes: #3863\r\nSigned-off-by: Andre Fuechsel <andre.fuechsel@telekom.de>","created_at":"2017-07-27T07:53:51Z","updated_at":"2017-07-31T10:41:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c83c34c1638ebad6788b942dcce61ef74febdec3","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/eclipse/smarthome/pulls/3899/commits","review_comments_url":"https://api.github.com/repos/eclipse/smarthome/pulls/3899/comments","review_comment_url":"https://api.github.com/repos/eclipse/smarthome/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eclipse/smarthome/issues/3899/comments","statuses_url":"https://api.github.com/repos/eclipse/smarthome/statuses/05670bf54731df2f219904788a82f2f51cf1b501","head":{"label":"afuechsel:unique-device-id","ref":"unique-device-id","sha":"05670bf54731df2f219904788a82f2f51cf1b501","user":{"login":"afuechsel","id":6408058,"avatar_url":"https://avatars1.githubusercontent.com/u/6408058?v=4","gravatar_id":"","url":"https://api.github.com/users/afuechsel","html_url":"https://github.com/afuechsel","followers_url":"https://api.github.com/users/afuechsel/followers","following_url":"https://api.github.com/users/afuechsel/following{/other_user}","gists_url":"https://api.github.com/users/afuechsel/gists{/gist_id}","starred_url":"https://api.github.com/users/afuechsel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afuechsel/subscriptions","organizations_url":"https://api.github.com/users/afuechsel/orgs","repos_url":"https://api.github.com/users/afuechsel/repos","events_url":"https://api.github.com/users/afuechsel/events{/privacy}","received_events_url":"https://api.github.com/users/afuechsel/received_events","type":"User","site_admin":false},"repo":{"id":55478260,"name":"smarthome","full_name":"afuechsel/smarthome","owner":{"login":"afuechsel","id":6408058,"avatar_url":"https://avatars1.githubusercontent.com/u/6408058?v=4","gravatar_id":"","url":"https://api.github.com/users/afuechsel","html_url":"https://github.com/afuechsel","followers_url":"https://api.github.com/users/afuechsel/followers","following_url":"https://api.github.com/users/afuechsel/following{/other_user}","gists_url":"https://api.github.com/users/afuechsel/gists{/gist_id}","starred_url":"https://api.github.com/users/afuechsel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afuechsel/subscriptions","organizations_url":"https://api.github.com/users/afuechsel/orgs","repos_url":"https://api.github.com/users/afuechsel/repos","events_url":"https://api.github.com/users/afuechsel/events{/privacy}","received_events_url":"https://api.github.com/users/afuechsel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/afuechsel/smarthome","description":"Eclipse SmartHome project","fork":true,"url":"https://api.github.com/repos/afuechsel/smarthome","forks_url":"https://api.github.com/repos/afuechsel/smarthome/forks","keys_url":"https://api.github.com/repos/afuechsel/smarthome/keys{/key_id}","collaborators_url":"https://api.github.com/repos/afuechsel/smarthome/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/afuechsel/smarthome/teams","hooks_url":"https://api.github.com/repos/afuechsel/smarthome/hooks","issue_events_url":"https://api.github.com/repos/afuechsel/smarthome/issues/events{/number}","events_url":"https://api.github.com/repos/afuechsel/smarthome/events","assignees_url":"https://api.github.com/repos/afuechsel/smarthome/assignees{/user}","branches_url":"https://api.github.com/repos/afuechsel/smarthome/branches{/branch}","tags_url":"https://api.github.com/repos/afuechsel/smarthome/tags","blobs_url":"https://api.github.com/repos/afuechsel/smarthome/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/afuechsel/smarthome/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/afuechsel/smarthome/git/refs{/sha}","trees_url":"https://api.github.com/repos/afuechsel/smarthome/git/trees{/sha}","statuses_url":"https://api.github.com/repos/afuechsel/smarthome/statuses/{sha}","languages_url":"https://api.github.com/repos/afuechsel/smarthome/languages","stargazers_url":"https://api.github.com/repos/afuechsel/smarthome/stargazers","contributors_url":"https://api.github.com/repos/afuechsel/smarthome/contributors","subscribers_url":"https://api.github.com/repos/afuechsel/smarthome/subscribers","subscription_url":"https://api.github.com/repos/afuechsel/smarthome/subscription","commits_url":"https://api.github.com/repos/afuechsel/smarthome/commits{/sha}","git_commits_url":"https://api.github.com/repos/afuechsel/smarthome/git/commits{/sha}","comments_url":"https://api.github.com/repos/afuechsel/smarthome/comments{/number}","issue_comment_url":"https://api.github.com/repos/afuechsel/smarthome/issues/comments{/number}","contents_url":"https://api.github.com/repos/afuechsel/smarthome/contents/{+path}","compare_url":"https://api.github.com/repos/afuechsel/smarthome/compare/{base}...{head}","merges_url":"https://api.github.com/repos/afuechsel/smarthome/merges","archive_url":"https://api.github.com/repos/afuechsel/smarthome/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/afuechsel/smarthome/downloads","issues_url":"https://api.github.com/repos/afuechsel/smarthome/issues{/number}","pulls_url":"https://api.github.com/repos/afuechsel/smarthome/pulls{/number}","milestones_url":"https://api.github.com/repos/afuechsel/smarthome/milestones{/number}","notifications_url":"https://api.github.com/repos/afuechsel/smarthome/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/afuechsel/smarthome/labels{/name}","releases_url":"https://api.github.com/repos/afuechsel/smarthome/releases{/id}","deployments_url":"https://api.github.com/repos/afuechsel/smarthome/deployments","created_at":"2016-04-05T07:42:58Z","updated_at":"2016-04-05T07:43:04Z","pushed_at":"2017-07-31T06:14:58Z","git_url":"git://github.com/afuechsel/smarthome.git","ssh_url":"git@github.com:afuechsel/smarthome.git","clone_url":"https://github.com/afuechsel/smarthome.git","svn_url":"https://github.com/afuechsel/smarthome","homepage":null,"size":28574,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"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":"eclipse:master","ref":"master","sha":"6e16762ef0be097be997719df861fe4941fdc3fe","user":{"login":"eclipse","id":56974,"avatar_url":"https://avatars1.githubusercontent.com/u/56974?v=4","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"repo":{"id":15778981,"name":"smarthome","full_name":"eclipse/smarthome","owner":{"login":"eclipse","id":56974,"avatar_url":"https://avatars1.githubusercontent.com/u/56974?v=4","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eclipse/smarthome","description":"Eclipse SmartHome™ project","fork":false,"url":"https://api.github.com/repos/eclipse/smarthome","forks_url":"https://api.github.com/repos/eclipse/smarthome/forks","keys_url":"https://api.github.com/repos/eclipse/smarthome/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eclipse/smarthome/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eclipse/smarthome/teams","hooks_url":"https://api.github.com/repos/eclipse/smarthome/hooks","issue_events_url":"https://api.github.com/repos/eclipse/smarthome/issues/events{/number}","events_url":"https://api.github.com/repos/eclipse/smarthome/events","assignees_url":"https://api.github.com/repos/eclipse/smarthome/assignees{/user}","branches_url":"https://api.github.com/repos/eclipse/smarthome/branches{/branch}","tags_url":"https://api.github.com/repos/eclipse/smarthome/tags","blobs_url":"https://api.github.com/repos/eclipse/smarthome/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eclipse/smarthome/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eclipse/smarthome/git/refs{/sha}","trees_url":"https://api.github.com/repos/eclipse/smarthome/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eclipse/smarthome/statuses/{sha}","languages_url":"https://api.github.com/repos/eclipse/smarthome/languages","stargazers_url":"https://api.github.com/repos/eclipse/smarthome/stargazers","contributors_url":"https://api.github.com/repos/eclipse/smarthome/contributors","subscribers_url":"https://api.github.com/repos/eclipse/smarthome/subscribers","subscription_url":"https://api.github.com/repos/eclipse/smarthome/subscription","commits_url":"https://api.github.com/repos/eclipse/smarthome/commits{/sha}","git_commits_url":"https://api.github.com/repos/eclipse/smarthome/git/commits{/sha}","comments_url":"https://api.github.com/repos/eclipse/smarthome/comments{/number}","issue_comment_url":"https://api.github.com/repos/eclipse/smarthome/issues/comments{/number}","contents_url":"https://api.github.com/repos/eclipse/smarthome/contents/{+path}","compare_url":"https://api.github.com/repos/eclipse/smarthome/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eclipse/smarthome/merges","archive_url":"https://api.github.com/repos/eclipse/smarthome/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eclipse/smarthome/downloads","issues_url":"https://api.github.com/repos/eclipse/smarthome/issues{/number}","pulls_url":"https://api.github.com/repos/eclipse/smarthome/pulls{/number}","milestones_url":"https://api.github.com/repos/eclipse/smarthome/milestones{/number}","notifications_url":"https://api.github.com/repos/eclipse/smarthome/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eclipse/smarthome/labels{/name}","releases_url":"https://api.github.com/repos/eclipse/smarthome/releases{/id}","deployments_url":"https://api.github.com/repos/eclipse/smarthome/deployments","created_at":"2014-01-09T20:47:19Z","updated_at":"2017-07-31T09:55:32Z","pushed_at":"2017-07-31T08:04:17Z","git_url":"git://github.com/eclipse/smarthome.git","ssh_url":"git@github.com:eclipse/smarthome.git","clone_url":"https://github.com/eclipse/smarthome.git","svn_url":"https://github.com/eclipse/smarthome","homepage":"https://www.eclipse.org/smarthome/","size":35021,"stargazers_count":537,"watchers_count":537,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":520,"mirror_url":null,"open_issues_count":322,"forks":520,"open_issues":322,"watchers":537,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/3899"},"html":{"href":"https://github.com/eclipse/smarthome/pull/3899"},"issue":{"href":"https://api.github.com/repos/eclipse/smarthome/issues/3899"},"comments":{"href":"https://api.github.com/repos/eclipse/smarthome/issues/3899/comments"},"review_comments":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/3899/comments"},"review_comment":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eclipse/smarthome/pulls/3899/commits"},"statuses":{"href":"https://api.github.com/repos/eclipse/smarthome/statuses/05670bf54731df2f219904788a82f2f51cf1b501"}}}}
{"actor":{"display_login":"kaikreuzer"}}