* Extract getHost() and getUDN() to common handler base class.
* Delete AbstractWemoHandler as it serves no purpose.
* Extract isUpnpDeviceRegistered() to base class.
* Fix typo.
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
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";
+++ /dev/null
-/**
- * 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;
- }
-}
--- /dev/null
+/**
+ * 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 "";
+ }
+}
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;
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;
* @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);
private final Object upnpLock = new Object();
private final Object jobLock = new Object();
- private @Nullable UpnpIOService service;
-
- private WemoHttpCall wemoCall;
-
- private String host = "";
-
private Map<String, Boolean> 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());
}
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 {
+ "<attribute><name>Cleaning</name><value>NULL</value></attribute></attributeList>"
+ "</u:SetAttributes>" + "</s:Body>" + "</s:Envelope>";
- 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");
}
}
- 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.
*/
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());
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) {
- }
}
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;
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;
* @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);
private final Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<>());
- private @Nullable UpnpIOService service;
-
- private WemoHttpCall wemoCall;
-
- private String host = "";
-
private Map<String, Boolean> 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());
}
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 {
+ "<s:Body>" + "<u:SetCrockpotState xmlns:u=\"urn:Belkin:service:basicevent:1\">" + "<mode>"
+ mode + "</mode>" + "<time>" + time + "</time>" + "</u:SetCrockpotState>" + "</s:Body>"
+ "</s:Envelope>";
- 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());
}
}
- 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..
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());
}
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 "";
- }
}
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;
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;
* @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);
private final Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<>());
- private @Nullable UpnpIOService service;
-
- private WemoHttpCall wemoCall;
-
- private String host = "";
-
private Map<String, Boolean> subscriptionState = new HashMap<>();
private @Nullable ScheduledFuture<?> pollingJob;
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());
}
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 {
}
}
- 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..
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());
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());
+ "<s:Body>" + "<u:" + action + " xmlns:u=\"urn:Belkin:service:basicevent:1\">" + "<" + argument
+ ">" + value + "</" + argument + ">" + "</u:" + action + ">" + "</s:Body>" + "</s:Envelope>";
- 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());
+ "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
+ "<s:Body>" + "<u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\">" + value
+ "</u:SetBinaryState>" + "</s:Body>" + "</s:Envelope>";
- 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());
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) {
- }
}
import java.math.BigDecimal;
import java.math.RoundingMode;
-import java.net.URL;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Collections;
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;
* @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);
private final Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<>());
- private @Nullable UpnpIOService service;
-
- private WemoHttpCall wemoCall;
-
private Map<String, Boolean> 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());
}
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 {
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());
}
}
- 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..
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());
logger.error("Failed to get actual state for device '{}': {}", getThing().getUID(), e.getMessage());
}
}
-
- @Override
- public void onStatusChanged(boolean status) {
- }
}
import java.io.IOException;
import java.io.StringReader;
-import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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;
* @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);
private final Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<>());
- private @Nullable UpnpIOService service;
-
- private WemoHttpCall wemoCall;
-
- private String host = "";
-
private Map<String, Boolean> 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());
}
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 {
+ "<attributeList><attribute><name>" + attribute + "</name><value>" + value
+ "</value></attribute></attributeList>" + "</u:SetAttributes>" + "</s:Body>"
+ "</s:Envelope>";
- 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());
}
}
- 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..
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());
}
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) {
- }
}
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;
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;
* @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);
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%
*/
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());
}
}
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);
+ "</CapabilityValue></DeviceStatus>" + "</DeviceStatusList>"
+ "</u:SetDeviceStatus>" + "</s:Body>" + "</s:Envelope>";
- 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());
+ "<s:Body>" + "<u:GetDeviceStatus xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DeviceIDs>"
+ wemoLightID + "</DeviceIDs>" + "</u:GetDeviceStatus>" + "</s:Body>" + "</s:Envelope>";
- 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());
}
}
- @Override
- public void onStatusChanged(boolean status) {
- }
-
private synchronized void addSubscription() {
synchronized (upnpLock) {
UpnpIOService localService = service;
}
}
}
-
- 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 "";
- }
}
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;
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;
* @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);
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());
}
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 {
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());
}
}
- 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.
*/
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());
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) {
- }
}