diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/WemoBindingConstants.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/WemoBindingConstants.java index 82a8a9a5eddea..5f36ad5707abf 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/WemoBindingConstants.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/WemoBindingConstants.java @@ -111,7 +111,7 @@ public class WemoBindingConstants { public static final String UDN = "udn"; public static final String DEVICE_ID = "deviceID"; public static final String POLLINGINTERVALL = "pollingInterval"; - public static final int DEFAULT_REFRESH_INTERVALL_SECONDS = 60; + public static final int DEFAULT_REFRESH_INTERVAL_SECONDS = 60; public static final int SUBSCRIPTION_DURATION_SECONDS = 600; public static final int LINK_DISCOVERY_SERVICE_INITIAL_DELAY = 5; public static final String HTTP_CALL_CONTENT_HEADER = "text/xml; charset=utf-8"; diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/AbstractWemoHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/AbstractWemoHandler.java deleted file mode 100644 index 92c7a3a1cda74..0000000000000 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/AbstractWemoHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2010-2022 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.wemo.internal.handler; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.wemo.internal.http.WemoHttpCall; -import org.openhab.core.thing.Thing; -import org.openhab.core.thing.binding.BaseThingHandler; - -/** - * @author Stefan Triller - Initial contribution - */ -@NonNullByDefault -public abstract class AbstractWemoHandler extends BaseThingHandler { - - protected WemoHttpCall wemoHttpCaller; - - public AbstractWemoHandler(Thing thing, WemoHttpCall wemoHttpCaller) { - super(thing); - this.wemoHttpCaller = wemoHttpCaller; - } -} diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoBaseThingHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoBaseThingHandler.java new file mode 100644 index 0000000000000..2be37f227f599 --- /dev/null +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoBaseThingHandler.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wemo.internal.handler; + +import java.net.URL; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.wemo.internal.WemoBindingConstants; +import org.openhab.binding.wemo.internal.http.WemoHttpCall; +import org.openhab.core.io.transport.upnp.UpnpIOParticipant; +import org.openhab.core.io.transport.upnp.UpnpIOService; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.types.Command; + +/** + * {@link WemoBaseThingHandler} provides a base implementation for the + * concrete WeMo handlers for each thing type. + * + * @author Jacob Laursen - Initial contribution + */ +@NonNullByDefault +public class WemoBaseThingHandler extends BaseThingHandler implements UpnpIOParticipant { + + protected @Nullable UpnpIOService service; + protected WemoHttpCall wemoHttpCaller; + protected String host = ""; + + public WemoBaseThingHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { + super(thing); + this.service = upnpIOService; + this.wemoHttpCaller = wemoHttpCaller; + } + + @Override + public void initialize() { + // can be overridden by subclasses + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + // can be overridden by subclasses + } + + @Override + public void onStatusChanged(boolean status) { + // can be overridden by subclasses + } + + @Override + public void onValueReceived(@Nullable String variable, @Nullable String value, @Nullable String service) { + // can be overridden by subclasses + } + + @Override + public void onServiceSubscribed(@Nullable String service, boolean succeeded) { + // can be overridden by subclasses + } + + @Override + public @Nullable String getUDN() { + return (String) this.getThing().getConfiguration().get(WemoBindingConstants.UDN); + } + + protected boolean isUpnpDeviceRegistered() { + UpnpIOService service = this.service; + if (service != null) { + return service.isRegistered(this); + } + return false; + } + + protected String getHost() { + String localHost = host; + if (!localHost.isEmpty()) { + return localHost; + } + UpnpIOService localService = service; + if (localService != null) { + URL descriptorURL = localService.getDescriptorURL(this); + if (descriptorURL != null) { + return descriptorURL.getHost(); + } + } + return ""; + } +} diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java index cd3264867caf0..e9e6205e05c49 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.wemo.internal.WemoUtil.*; import java.io.StringReader; -import java.net.URL; import java.time.Instant; import java.time.ZonedDateTime; import java.util.Collections; @@ -34,7 +33,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; @@ -63,7 +61,7 @@ * @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType */ @NonNullByDefault -public class WemoCoffeeHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoCoffeeHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoCoffeeHandler.class); @@ -72,21 +70,12 @@ public class WemoCoffeeHandler extends AbstractWemoHandler implements UpnpIOPart private final Object upnpLock = new Object(); private final Object jobLock = new Object(); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - - private String host = ""; - private Map subscriptionState = new HashMap<>(); private @Nullable ScheduledFuture pollingJob; public WemoCoffeeHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { - super(thing, wemoHttpCaller); - - this.wemoCall = wemoHttpCaller; - this.service = upnpIOService; + super(thing, upnpIOService, wemoHttpCaller); logger.debug("Creating a WemoCoffeeHandler for thing '{}'", getThing().getUID()); } @@ -102,7 +91,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -195,7 +184,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { + "<attribute><name>Cleaning</name><value>NULL</value></attribute>" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { updateState(CHANNEL_STATE, OnOffType.ON); State newMode = new StringType("Brewing"); @@ -279,19 +268,6 @@ private synchronized void removeSubscription() { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - /** * The {@link updateWemoState} polls the actual state of a WeMo CoffeeMaker. */ @@ -315,7 +291,7 @@ protected void updateWemoState() { String action = "GetAttributes"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -474,23 +450,4 @@ protected void updateWemoState() { logger.trace("New attribute brewed '{}' received", dateTimeState); return dateTimeState; } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } - - @Override - public void onStatusChanged(boolean status) { - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCrockpotHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCrockpotHandler.java index 047f82b8bcba4..73d7edd564a0c 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCrockpotHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCrockpotHandler.java @@ -15,7 +15,6 @@ import static org.openhab.binding.wemo.internal.WemoBindingConstants.*; import static org.openhab.binding.wemo.internal.WemoUtil.*; -import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -27,7 +26,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.StringType; @@ -49,7 +47,7 @@ * @author Hans-Jörg Merk - Initial contribution; */ @NonNullByDefault -public class WemoCrockpotHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoCrockpotHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoCrockpotHandler.class); @@ -60,21 +58,12 @@ public class WemoCrockpotHandler extends AbstractWemoHandler implements UpnpIOPa private final Map stateMap = Collections.synchronizedMap(new HashMap<>()); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - - private String host = ""; - private Map subscriptionState = new HashMap<>(); private @Nullable ScheduledFuture pollingJob; public WemoCrockpotHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { - super(thing, wemoHttpCaller); - - this.wemoCall = wemoHttpCaller; - this.service = upnpIOService; + super(thing, upnpIOService, wemoHttpCaller); logger.debug("Creating a WemoCrockpotHandler for thing '{}'", getThing().getUID()); } @@ -90,7 +79,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -186,7 +175,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { + "" + "" + "" + mode + "" + "" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -264,19 +253,6 @@ private synchronized void removeSubscription() { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - /** * The {@link updateWemoState} polls the actual state of a WeMo device and * calls {@link onValueReceived} to update the statemap and channels.. @@ -302,7 +278,7 @@ protected void updateWemoState() { String action = "GetCrockpotState"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -345,23 +321,4 @@ protected void updateWemoState() { } updateStatus(ThingStatus.ONLINE); } - - @Override - public void onStatusChanged(boolean status) { - } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java index f864d402500ae..eaaba0fd89ef9 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java @@ -15,7 +15,6 @@ import static org.openhab.binding.wemo.internal.WemoBindingConstants.*; import static org.openhab.binding.wemo.internal.WemoUtil.*; -import java.net.URL; import java.time.Instant; import java.time.ZonedDateTime; import java.util.Collections; @@ -30,7 +29,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; @@ -55,7 +53,7 @@ * @author Hans-Jörg Merk - Initial contribution */ @NonNullByDefault -public class WemoDimmerHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoDimmerHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoDimmerHandler.class); @@ -66,12 +64,6 @@ public class WemoDimmerHandler extends AbstractWemoHandler implements UpnpIOPart private final Map stateMap = Collections.synchronizedMap(new HashMap<>()); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - - private String host = ""; - private Map subscriptionState = new HashMap<>(); private @Nullable ScheduledFuture pollingJob; @@ -85,10 +77,7 @@ public class WemoDimmerHandler extends AbstractWemoHandler implements UpnpIOPart private static final int DIM_STEPSIZE = 5; public WemoDimmerHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { - super(thing, wemoHttpCaller); - - this.service = upnpIOService; - this.wemoCall = wemoHttpCaller; + super(thing, upnpIOService, wemoHttpCaller); logger.debug("Creating a WemoDimmerHandler for thing '{}'", getThing().getUID()); } @@ -104,7 +93,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -477,19 +466,6 @@ private synchronized void removeSubscription() { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - /** * The {@link updateWemoState} polls the actual state of a WeMo device and * calls {@link onValueReceived} to update the statemap and channels.. @@ -517,7 +493,7 @@ protected void updateWemoState() { String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); try { - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -546,7 +522,7 @@ protected void updateWemoState() { soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; content = createStateRequestContent(action, actionService); try { - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -613,7 +589,7 @@ public void setBinaryState(String action, String argument, String value) { + "" + "" + "<" + argument + ">" + value + "" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -648,7 +624,7 @@ public void setTimerStart(String action, String argument, String value) { + "" + "" + "" + value + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -661,23 +637,4 @@ public void setTimerStart(String action, String argument, String value) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } - - @Override - public void onStatusChanged(boolean status) { - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java index 23c2a99a42964..fb31f7539fad6 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java @@ -17,7 +17,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; -import java.net.URL; import java.time.Instant; import java.time.ZonedDateTime; import java.util.Collections; @@ -34,7 +33,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; @@ -63,7 +61,7 @@ * @author Mihir Patil - Added standby switch */ @NonNullByDefault -public class WemoHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoHandler.class); @@ -76,21 +74,12 @@ public class WemoHandler extends AbstractWemoHandler implements UpnpIOParticipan private final Map stateMap = Collections.synchronizedMap(new HashMap<>()); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - private Map subscriptionState = new HashMap<>(); private @Nullable ScheduledFuture pollingJob; - private String host = ""; - public WemoHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { - super(thing, wemoHttpCaller); - - this.service = upnpIOService; - this.wemoCall = wemoHttpCaller; + super(thing, upnpIOService, wemoHttpCaller); logger.debug("Creating a WemoHandler for thing '{}'", getThing().getUID()); } @@ -106,7 +95,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -186,7 +175,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { boolean binaryState = OnOffType.ON.equals(command) ? true : false; String soapHeader = "\"urn:Belkin:service:basicevent:1#SetBinaryState\""; String content = createBinaryStateContent(binaryState); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -407,34 +396,6 @@ private synchronized void removeSubscription() { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } - /** * The {@link updateWemoState} polls the actual state of a WeMo device and * calls {@link onValueReceived} to update the statemap and channels.. @@ -467,7 +428,7 @@ protected void updateWemoState() { String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); try { - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -489,8 +450,4 @@ protected void updateWemoState() { logger.error("Failed to get actual state for device '{}': {}", getThing().getUID(), e.getMessage()); } } - - @Override - public void onStatusChanged(boolean status) { - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHolmesHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHolmesHandler.java index a97a99f41bf56..5742e4a5f66fc 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHolmesHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHolmesHandler.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.io.StringReader; -import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -33,7 +32,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; @@ -61,7 +59,7 @@ * @author Hans-Jörg Merk - Initial contribution; */ @NonNullByDefault -public class WemoHolmesHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoHolmesHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoHolmesHandler.class); @@ -75,21 +73,12 @@ public class WemoHolmesHandler extends AbstractWemoHandler implements UpnpIOPart private final Map stateMap = Collections.synchronizedMap(new HashMap<>()); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - - private String host = ""; - private Map subscriptionState = new HashMap<>(); private @Nullable ScheduledFuture pollingJob; public WemoHolmesHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) { - super(thing, wemoHttpCaller); - - this.service = upnpIOService; - this.wemoCall = wemoHttpCaller; + super(thing, upnpIOService, wemoHttpCaller); logger.debug("Creating a WemoHolmesHandler for thing '{}'", getThing().getUID()); } @@ -105,7 +94,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -280,7 +269,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { + "<attribute><name>" + attribute + "</name><value>" + value + "</value></attribute>" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -357,19 +346,6 @@ private synchronized void removeSubscription() { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - /** * The {@link updateWemoState} polls the actual state of a WeMo device and * calls {@link onValueReceived} to update the statemap and channels.. @@ -395,7 +371,7 @@ protected void updateWemoState() { String action = "GetAttributes"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -611,23 +587,4 @@ protected void updateWemoState() { } updateStatus(ThingStatus.ONLINE); } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } - - @Override - public void onStatusChanged(boolean status) { - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoLightHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoLightHandler.java index 1aad41ee31cf7..94c5df7146122 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoLightHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoLightHandler.java @@ -15,7 +15,6 @@ import static org.openhab.binding.wemo.internal.WemoBindingConstants.*; import static org.openhab.binding.wemo.internal.WemoUtil.*; -import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ScheduledFuture; @@ -25,7 +24,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.IncreaseDecreaseType; import org.openhab.core.library.types.OnOffType; @@ -50,7 +48,7 @@ * @author Hans-Jörg Merk - Initial contribution */ @NonNullByDefault -public class WemoLightHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoLightHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoLightHandler.class); @@ -61,16 +59,10 @@ public class WemoLightHandler extends AbstractWemoHandler implements UpnpIOParti private @Nullable WemoBridgeHandler wemoBridgeHandler; - private @Nullable UpnpIOService service; - - private String host = ""; - private @Nullable String wemoLightID; private int currentBrightness; - private WemoHttpCall wemoCall; - /** * Set dimming stepsize to 5% */ @@ -86,10 +78,7 @@ public class WemoLightHandler extends AbstractWemoHandler implements UpnpIOParti private @Nullable ScheduledFuture pollingJob; public WemoLightHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpcaller) { - super(thing, wemoHttpcaller); - - this.service = upnpIOService; - this.wemoCall = wemoHttpcaller; + super(thing, upnpIOService, wemoHttpcaller); logger.debug("Creating a WemoLightHandler for thing '{}'", getThing().getUID()); } @@ -107,7 +96,7 @@ public void initialize() { } host = getHost(); pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY, - DEFAULT_REFRESH_INTERVALL_SECONDS, TimeUnit.SECONDS); + DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE); @@ -288,7 +277,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { + "</CapabilityValue></DeviceStatus>" + "" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -348,7 +337,7 @@ public void getDeviceState() { + "" + "" + "" + wemoLightID + "" + "" + "" + ""; - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -411,10 +400,6 @@ public void onValueReceived(@Nullable String variable, @Nullable String value, @ } } - @Override - public void onStatusChanged(boolean status) { - } - private synchronized void addSubscription() { synchronized (upnpLock) { UpnpIOService localService = service; @@ -454,27 +439,4 @@ private synchronized void removeSubscription() { } } } - - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoMakerHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoMakerHandler.java index 5586bfe43f4c5..2bfb66deda814 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoMakerHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoMakerHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.wemo.internal.WemoUtil.*; import java.io.StringReader; -import java.net.URL; import java.util.Collections; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -29,7 +28,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wemo.internal.http.WemoHttpCall; import org.openhab.core.config.core.Configuration; -import org.openhab.core.io.transport.upnp.UpnpIOParticipant; import org.openhab.core.io.transport.upnp.UpnpIOService; import org.openhab.core.library.types.OnOffType; import org.openhab.core.thing.ChannelUID; @@ -54,7 +52,7 @@ * @author Hans-Jörg Merk - Initial contribution */ @NonNullByDefault -public class WemoMakerHandler extends AbstractWemoHandler implements UpnpIOParticipant { +public class WemoMakerHandler extends WemoBaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WemoMakerHandler.class); @@ -62,19 +60,10 @@ public class WemoMakerHandler extends AbstractWemoHandler implements UpnpIOParti private final Object jobLock = new Object(); - private @Nullable UpnpIOService service; - - private WemoHttpCall wemoCall; - - private String host = ""; - private @Nullable ScheduledFuture pollingJob; public WemoMakerHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpcaller) { - super(thing, wemoHttpcaller); - - this.service = upnpIOService; - this.wemoCall = wemoHttpcaller; + super(thing, upnpIOService, wemoHttpcaller); logger.debug("Creating a WemoMakerHandler for thing '{}'", getThing().getUID()); } @@ -90,7 +79,7 @@ public void initialize() { localService.registerParticipant(this); } host = getHost(); - pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVALL_SECONDS, + pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } else { @@ -169,7 +158,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { boolean binaryState = OnOffType.ON.equals(command) ? true : false; String soapHeader = "\"urn:Belkin:service:basicevent:1#SetBinaryState\""; String content = createBinaryStateContent(binaryState); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null && logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); logger.trace("wemoCall with soapHeader '{}' for device '{}'", soapHeader, getThing().getUID()); @@ -184,19 +173,6 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } - private boolean isUpnpDeviceRegistered() { - UpnpIOService localService = service; - if (localService != null) { - return localService.isRegistered(this); - } - return false; - } - - @Override - public String getUDN() { - return (String) this.getThing().getConfiguration().get(UDN); - } - /** * The {@link updateWemoState} polls the actual state of a WeMo Maker. */ @@ -220,7 +196,7 @@ protected void updateWemoState() { String action = "GetAttributes"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = createStateRequestContent(action, actionService); - String wemoCallResponse = wemoCall.executeCall(wemoURL, soapHeader, content); + String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { if (logger.isTraceEnabled()) { logger.trace("wemoCall to URL '{}' for device '{}'", wemoURL, getThing().getUID()); @@ -292,31 +268,4 @@ protected void updateWemoState() { logger.error("Failed to get attributes for device '{}'", getThing().getUID(), e); } } - - public String getHost() { - String localHost = host; - if (!localHost.isEmpty()) { - return localHost; - } - UpnpIOService localService = service; - if (localService != null) { - URL descriptorURL = localService.getDescriptorURL(this); - if (descriptorURL != null) { - return descriptorURL.getHost(); - } - } - return ""; - } - - @Override - public void onStatusChanged(boolean status) { - } - - @Override - public void onServiceSubscribed(@Nullable String service, boolean succeeded) { - } - - @Override - public void onValueReceived(@Nullable String variable, @Nullable String value, @Nullable String service) { - } }