Skip to content

Commit

Permalink
[imperihome] Use DS annotations (openhab#4721)
Browse files Browse the repository at this point in the history
* [imperihome] Use DS annotations

Signed-off-by: Wouter Born <[email protected]>
Signed-off-by: Pshatsillo <[email protected]>
  • Loading branch information
wborn authored and Pshatsillo committed Jun 19, 2019
1 parent 314a913 commit bcacb53
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
1 change: 1 addition & 0 deletions addons/io/org.openhab.io.imperihome/OSGI-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.xml
29 changes: 0 additions & 29 deletions addons/io/org.openhab.io.imperihome/OSGI-INF/imperihome.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.smarthome.config.core.ConfigurableService;
import org.eclipse.smarthome.core.events.EventPublisher;
import org.eclipse.smarthome.core.items.ItemRegistry;
import org.eclipse.smarthome.core.persistence.PersistenceServiceRegistry;
Expand All @@ -41,6 +42,13 @@
import org.openhab.io.imperihome.internal.model.param.ParamType;
import org.openhab.io.imperihome.internal.processor.DeviceRegistry;
import org.openhab.io.imperihome.internal.processor.ItemProcessor;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -53,6 +61,11 @@
*
* @author Pepijn de Geus - Initial contribution
*/
@Component(immediate = true, service = HttpServlet.class, configurationPid = "org.openhab.imperihome", property = {
Constants.SERVICE_PID + "=org.openhab.imperihome",
ConfigurableService.SERVICE_PROPERTY_DESCRIPTION_URI + "=io:imperihome",
ConfigurableService.SERVICE_PROPERTY_CATEGORY + "=io",
ConfigurableService.SERVICE_PROPERTY_LABEL + "=ImperiHome Integration" })
public class ImperiHomeApiServlet extends HttpServlet {

private static final long serialVersionUID = -1966364789075448441L;
Expand Down Expand Up @@ -107,6 +120,7 @@ public ImperiHomeApiServlet() {
*
* @param config Service config.
*/
@Activate
protected void activate(Map<String, Object> config) {
modified(config);

Expand All @@ -130,16 +144,18 @@ protected void activate(Map<String, Object> config) {

/**
* OSGi config modification callback.
*
* @param config Service config.
*/
@Modified
protected void modified(Map<String, Object> config) {
imperiHomeConfig.update(config);
}

/**
* OSGi deactivation callback.
*/
@Deactivate
protected void deactivate() {
try {
httpService.unregister(PATH);
Expand All @@ -159,6 +175,7 @@ protected void deactivate() {
logger.info("ImperiHome integration service stopped");
}

@Reference(policy = ReferencePolicy.DYNAMIC)
protected void setItemRegistry(ItemRegistry itemRegistry) {
this.itemRegistry = itemRegistry;
}
Expand All @@ -167,6 +184,7 @@ protected void unsetItemRegistry(ItemRegistry itemRegistry) {
this.itemRegistry = null;
}

@Reference
protected void setEventPublisher(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
Expand All @@ -175,6 +193,7 @@ protected void unsetEventPublisher(EventPublisher eventPublisher) {
this.eventPublisher = null;
}

@Reference
protected void setHttpService(HttpService httpService) {
this.httpService = httpService;
}
Expand All @@ -183,6 +202,7 @@ protected void unsetHttpService(HttpService httpService) {
this.httpService = null;
}

@Reference
protected void setPersistenceServiceRegistry(PersistenceServiceRegistry persistenceServiceRegistry) {
this.persistenceServiceRegistry = persistenceServiceRegistry;
}
Expand Down

0 comments on commit bcacb53

Please sign in to comment.