Simplify getWemoURL usages in handlers (#12397)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
7da00f1d68
commit
93e3a710e1
@ -125,19 +125,6 @@ public class WemoUtil {
|
|||||||
return unescapedOutput.toString();
|
return unescapedOutput.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable String getWemoURL(String host, String actionService) {
|
|
||||||
int portCheckStart = 49151;
|
|
||||||
int portCheckStop = 49157;
|
|
||||||
String port = null;
|
|
||||||
for (int i = portCheckStart; i < portCheckStop; i++) {
|
|
||||||
if (serviceAvailableFunction.apply(host, i)) {
|
|
||||||
port = String.valueOf(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return port == null ? null : "http://" + host + ":" + port + "/upnp/control/" + actionService + "1";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean servicePing(String host, int port) {
|
private static boolean servicePing(String host, int port) {
|
||||||
try {
|
try {
|
||||||
HttpUtil.executeUrl("GET", "http://" + host + ":" + port, 250);
|
HttpUtil.executeUrl("GET", "http://" + host + ":" + port, 250);
|
||||||
|
|||||||
@ -22,11 +22,14 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.wemo.internal.WemoBindingConstants;
|
import org.openhab.binding.wemo.internal.WemoBindingConstants;
|
||||||
|
import org.openhab.binding.wemo.internal.WemoUtil;
|
||||||
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
|
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
|
||||||
import org.openhab.core.io.transport.upnp.UpnpIOParticipant;
|
import org.openhab.core.io.transport.upnp.UpnpIOParticipant;
|
||||||
import org.openhab.core.io.transport.upnp.UpnpIOService;
|
import org.openhab.core.io.transport.upnp.UpnpIOService;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
|
import org.openhab.core.thing.ThingStatus;
|
||||||
|
import org.openhab.core.thing.ThingStatusDetail;
|
||||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -48,8 +51,8 @@ public abstract class WemoBaseThingHandler extends BaseThingHandler implements U
|
|||||||
|
|
||||||
protected @Nullable UpnpIOService service;
|
protected @Nullable UpnpIOService service;
|
||||||
protected WemoHttpCall wemoHttpCaller;
|
protected WemoHttpCall wemoHttpCaller;
|
||||||
protected String host = "";
|
|
||||||
|
|
||||||
|
private @Nullable String host;
|
||||||
private Map<String, Instant> subscriptions = new ConcurrentHashMap<String, Instant>();
|
private Map<String, Instant> subscriptions = new ConcurrentHashMap<String, Instant>();
|
||||||
private @Nullable ScheduledFuture<?> subscriptionRenewalJob;
|
private @Nullable ScheduledFuture<?> subscriptionRenewalJob;
|
||||||
|
|
||||||
@ -65,6 +68,7 @@ public abstract class WemoBaseThingHandler extends BaseThingHandler implements U
|
|||||||
if (service != null) {
|
if (service != null) {
|
||||||
logger.debug("Registering UPnP participant for {}", getThing().getUID());
|
logger.debug("Registering UPnP participant for {}", getThing().getUID());
|
||||||
service.registerParticipant(this);
|
service.registerParticipant(this);
|
||||||
|
initializeHost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,18 +227,50 @@ public abstract class WemoBaseThingHandler extends BaseThingHandler implements U
|
|||||||
subscriptions.clear();
|
subscriptions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getHost() {
|
public @Nullable String getWemoURL(String actionService) {
|
||||||
String localHost = host;
|
String host = getHost();
|
||||||
if (!localHost.isEmpty()) {
|
if (host == null) {
|
||||||
return localHost;
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
|
"@text/config-status.error.missing-ip");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
UpnpIOService localService = service;
|
int portCheckStart = 49151;
|
||||||
if (localService != null) {
|
int portCheckStop = 49157;
|
||||||
URL descriptorURL = localService.getDescriptorURL(this);
|
String port = null;
|
||||||
|
for (int i = portCheckStart; i < portCheckStop; i++) {
|
||||||
|
if (WemoUtil.serviceAvailableFunction.apply(host, i)) {
|
||||||
|
port = String.valueOf(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (port == null) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
|
"@text/config-status.error.missing-url");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return "http://" + host + ":" + port + "/upnp/control/" + actionService + "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String getHost() {
|
||||||
|
if (host != null) {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
initializeHost();
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeHost() {
|
||||||
|
host = getHostFromService();
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String getHostFromService() {
|
||||||
|
UpnpIOService service = this.service;
|
||||||
|
if (service != null) {
|
||||||
|
URL descriptorURL = service.getDescriptorURL(this);
|
||||||
if (descriptorURL != null) {
|
if (descriptorURL != null) {
|
||||||
return descriptorURL.getHost();
|
return descriptorURL.getHost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,6 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
|
|||||||
if (configuration.get(UDN) != null) {
|
if (configuration.get(UDN) != null) {
|
||||||
logger.debug("Initializing WemoCoffeeHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoCoffeeHandler for UDN '{}'", configuration.get(UDN));
|
||||||
addSubscription(DEVICEEVENT);
|
addSubscription(DEVICEEVENT);
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -113,7 +112,6 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
|
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -131,20 +129,10 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command instanceof RefreshType) {
|
if (command instanceof RefreshType) {
|
||||||
@ -198,19 +186,10 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
|
|||||||
* The {@link updateWemoState} polls the actual state of a WeMo CoffeeMaker.
|
* The {@link updateWemoState} polls the actual state of a WeMo CoffeeMaker.
|
||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String localHost = getHost();
|
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String actionService = DEVICEACTION;
|
String actionService = DEVICEACTION;
|
||||||
String wemoURL = getWemoURL(host, actionService);
|
String wemoURL = getWemoURL(actionService);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -74,7 +74,6 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
if (configuration.get(UDN) != null) {
|
if (configuration.get(UDN) != null) {
|
||||||
logger.debug("Initializing WemoCrockpotHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoCrockpotHandler for UDN '{}'", configuration.get(UDN));
|
||||||
addSubscription(BASICEVENT);
|
addSubscription(BASICEVENT);
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -103,7 +102,6 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -121,20 +119,10 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String mode = "0";
|
String mode = "0";
|
||||||
@ -192,19 +180,10 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String localHost = getHost();
|
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String actionService = BASICEVENT;
|
String actionService = BASICEVENT;
|
||||||
String wemoURL = getWemoURL(localHost, actionService);
|
String wemoURL = getWemoURL(actionService);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.warn("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.warn("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -87,7 +87,6 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
if (configuration.get(UDN) != null) {
|
if (configuration.get(UDN) != null) {
|
||||||
logger.debug("Initializing WemoDimmerHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoDimmerHandler for UDN '{}'", configuration.get(UDN));
|
||||||
addSubscription(BASICEVENT);
|
addSubscription(BASICEVENT);
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -117,7 +116,6 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -418,18 +416,9 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String action = "GetBinaryState";
|
String action = "GetBinaryState";
|
||||||
@ -496,18 +485,9 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBinaryState(String action, String argument, String value) {
|
public void setBinaryState(String action, String argument, String value) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to set binary state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to set binary state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to set binary state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -527,18 +507,9 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTimerStart(String action, String argument, String value) {
|
public void setTimerStart(String action, String argument, String value) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to set timerStart for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.warn("Failed to set timerStart for device '{}': URL cannot be created", getThing().getUID());
|
logger.warn("Failed to set timerStart for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
* @author Stefan Bußweiler - Added new thing status handling
|
* @author Stefan Bußweiler - Added new thing status handling
|
||||||
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
|
* @author Erdoan Hadzhiyusein - Adapted the class to work with the new DateTimeType
|
||||||
* @author Mihir Patil - Added standby switch
|
* @author Mihir Patil - Added standby switch
|
||||||
|
* @author Jacob Laursen - Refactoring
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public abstract class WemoHandler extends WemoBaseThingHandler {
|
public abstract class WemoHandler extends WemoBaseThingHandler {
|
||||||
@ -69,7 +70,6 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
if (THING_TYPE_INSIGHT.equals(thing.getThingTypeUID())) {
|
if (THING_TYPE_INSIGHT.equals(thing.getThingTypeUID())) {
|
||||||
addSubscription(INSIGHTEVENT);
|
addSubscription(INSIGHTEVENT);
|
||||||
}
|
}
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -99,7 +99,6 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -117,20 +116,10 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command instanceof RefreshType) {
|
if (command instanceof RefreshType) {
|
||||||
@ -163,13 +152,6 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String actionService = BASICACTION;
|
String actionService = BASICACTION;
|
||||||
String localhost = getHost();
|
|
||||||
if (localhost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String action = "GetBinaryState";
|
String action = "GetBinaryState";
|
||||||
String variable = "BinaryState";
|
String variable = "BinaryState";
|
||||||
String value = null;
|
String value = null;
|
||||||
@ -178,11 +160,9 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
variable = "InsightParams";
|
variable = "InsightParams";
|
||||||
actionService = INSIGHTACTION;
|
actionService = INSIGHTACTION;
|
||||||
}
|
}
|
||||||
String wemoURL = getWemoURL(localhost, actionService);
|
String wemoURL = getWemoURL(actionService);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\"";
|
String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\"";
|
||||||
|
|||||||
@ -88,7 +88,6 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
|
|||||||
if (configuration.get(UDN) != null) {
|
if (configuration.get(UDN) != null) {
|
||||||
logger.debug("Initializing WemoHolmesHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoHolmesHandler for UDN '{}'", configuration.get(UDN));
|
||||||
addSubscription(BASICEVENT);
|
addSubscription(BASICEVENT);
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -118,7 +117,6 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -136,20 +134,10 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(DEVICEACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, DEVICEACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String attribute = null;
|
String attribute = null;
|
||||||
@ -284,19 +272,10 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String localHost = getHost();
|
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String actionService = DEVICEACTION;
|
String actionService = DEVICEACTION;
|
||||||
String wemoURL = getWemoURL(localHost, actionService);
|
String wemoURL = getWemoURL(actionService);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -85,7 +85,6 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
final Bridge bridge = getBridge();
|
final Bridge bridge = getBridge();
|
||||||
if (bridge != null && bridge.getStatus() == ThingStatus.ONLINE) {
|
if (bridge != null && bridge.getStatus() == ThingStatus.ONLINE) {
|
||||||
addSubscription(BRIDGEEVENT);
|
addSubscription(BRIDGEEVENT);
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY,
|
||||||
DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -143,7 +142,6 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -161,20 +159,10 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command instanceof RefreshType) {
|
if (command instanceof RefreshType) {
|
||||||
@ -294,19 +282,10 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
* channel states.
|
* channel states.
|
||||||
*/
|
*/
|
||||||
public void getDeviceState() {
|
public void getDeviceState() {
|
||||||
String localHost = getHost();
|
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.debug("Request actual state for LightID '{}'", wemoLightID);
|
logger.debug("Request actual state for LightID '{}'", wemoLightID);
|
||||||
String wemoURL = getWemoURL(localHost, BRIDGEACTION);
|
String wemoURL = getWemoURL(BRIDGEACTION);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -75,7 +75,6 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
if (configuration.get(UDN) != null) {
|
if (configuration.get(UDN) != null) {
|
||||||
logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get(UDN));
|
||||||
host = getHost();
|
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -105,7 +104,6 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
host = getHost();
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// Check if the Wemo device is set in the UPnP service registry
|
||||||
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
// If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
|
||||||
if (!isUpnpDeviceRegistered()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
@ -123,20 +121,10 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
String localHost = getHost();
|
String wemoURL = getWemoURL(BASICACTION);
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to send command '{}' for device '{}': IP address missing", command,
|
|
||||||
getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String wemoURL = getWemoURL(localHost, BASICACTION);
|
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
logger.debug("Failed to send command '{}' for device '{}': URL cannot be created", command,
|
||||||
getThing().getUID());
|
getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (command instanceof RefreshType) {
|
if (command instanceof RefreshType) {
|
||||||
@ -165,19 +153,10 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
* The {@link updateWemoState} polls the actual state of a WeMo Maker.
|
* The {@link updateWemoState} polls the actual state of a WeMo Maker.
|
||||||
*/
|
*/
|
||||||
protected void updateWemoState() {
|
protected void updateWemoState() {
|
||||||
String localHost = getHost();
|
|
||||||
if (localHost.isEmpty()) {
|
|
||||||
logger.warn("Failed to get actual state for device '{}': IP address missing", getThing().getUID());
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-ip");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String actionService = DEVICEACTION;
|
String actionService = DEVICEACTION;
|
||||||
String wemoURL = getWemoURL(localHost, actionService);
|
String wemoURL = getWemoURL(actionService);
|
||||||
if (wemoURL == null) {
|
if (wemoURL == null) {
|
||||||
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
logger.debug("Failed to get actual state for device '{}': URL cannot be created", getThing().getUID());
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
|
||||||
"@text/config-status.error.missing-url");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user