removed auto-approve service as this is now contained in ESH (#202)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
pull/203/head
Kai Kreuzer 2017-08-29 11:13:36 +02:00 committed by GitHub
parent f4d2c1ac6b
commit cd9d02ab94
2 changed files with 0 additions and 98 deletions

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015-2017 by the respective copyright holders.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" configuration-policy="require" immediate="true" name="org.openhab.autoapprove">
<implementation class="org.openhab.core.internal.inbox.AutoApproveService"/>
<reference bind="setInbox" cardinality="1..1" interface="org.eclipse.smarthome.config.discovery.inbox.Inbox" name="Inbox" policy="static" unbind="unsetInbox"/>
<property name="service.pid" type="String" value="org.openhab.autoapprove"/>
</scr:component>

View File

@ -1,82 +0,0 @@
/**
* Copyright (c) 2015-2017 by the respective copyright holders.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.core.internal.inbox;
import java.util.Map;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultFlag;
import org.eclipse.smarthome.config.discovery.inbox.Inbox;
import org.eclipse.smarthome.config.discovery.inbox.InboxListener;
import org.osgi.service.cm.ConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class is an OSGi service, which automatically approves all newly
* discovered things in the inbox. As a result, the inbox will always be empty
* and as thing instances are immediately created. This feature needs to be
* activated through a configuration, which is provided in services.cfg.
*
* @author Kai Kreuzer
*
*/
public class AutoApproveService implements InboxListener {
final static private Logger logger = LoggerFactory.getLogger(AutoApproveService.class);
private Inbox inbox;
protected void activate(Map<String, Object> configProps) throws ConfigurationException {
String enabled = (String) configProps.get("enabled");
enable(enabled);
}
protected void modified(Map<String, Object> configProps) throws ConfigurationException {
String enabled = (String) configProps.get("enabled");
enable(enabled);
}
private void enable(String enabled) {
if ("true".equalsIgnoreCase(enabled)) {
inbox.addInboxListener(this);
for (DiscoveryResult result : inbox.getAll()) {
if (result.getFlag().equals(DiscoveryResultFlag.NEW)) {
thingAdded(inbox, result);
}
}
} else {
this.inbox.removeInboxListener(this);
}
}
@Override
public void thingAdded(Inbox source, DiscoveryResult result) {
logger.debug("Approving inbox entry '{}'", result.toString());
inbox.approve(result.getThingUID(), result.getLabel());
}
@Override
public void thingUpdated(Inbox source, DiscoveryResult result) {
}
@Override
public void thingRemoved(Inbox source, DiscoveryResult result) {
}
protected void setInbox(Inbox inbox) {
this.inbox = inbox;
}
protected void unsetInbox(Inbox inbox) {
this.inbox.removeInboxListener(this);
this.inbox = null;
}
}