Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[imperihome] Use DS annotations #4721

Merged
merged 3 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 @@
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.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 +60,11 @@
*
* @author Pepijn de Geus - Initial contribution
*/
@Component(immediate = true, service = HttpServlet.class, configurationPid = "org.openhab.imperihome", property = {
org.osgi.framework.Constants.SERVICE_PID + "=org.openhab.imperihome",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this one also be imported? Or maybe a static import?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now imported. A simple class import because that looks nicer because the auto-formatter would put multiple properties on the same line with a static import. :-)

ConfigurableService.SERVICE_PROPERTY_DESCRIPTION_URI + "=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 +119,7 @@ public ImperiHomeApiServlet() {
*
* @param config Service config.
*/
@Activate
protected void activate(Map<String, Object> config) {
modified(config);

Expand All @@ -130,16 +143,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 +174,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 +183,7 @@ protected void unsetItemRegistry(ItemRegistry itemRegistry) {
this.itemRegistry = null;
}

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

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

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