2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.wemo.internal.handler;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.wemo.internal.WemoBindingConstants;
20 import org.openhab.binding.wemo.internal.http.WemoHttpCall;
21 import org.openhab.core.io.transport.upnp.UpnpIOParticipant;
22 import org.openhab.core.io.transport.upnp.UpnpIOService;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.binding.BaseThingHandler;
26 import org.openhab.core.types.Command;
29 * {@link WemoBaseThingHandler} provides a base implementation for the
30 * concrete WeMo handlers for each thing type.
32 * @author Jacob Laursen - Initial contribution
35 public abstract class WemoBaseThingHandler extends BaseThingHandler implements UpnpIOParticipant {
37 protected @Nullable UpnpIOService service;
38 protected WemoHttpCall wemoHttpCaller;
39 protected String host = "";
41 public WemoBaseThingHandler(Thing thing, UpnpIOService upnpIOService, WemoHttpCall wemoHttpCaller) {
43 this.service = upnpIOService;
44 this.wemoHttpCaller = wemoHttpCaller;
48 public void initialize() {
49 // can be overridden by subclasses
53 public void handleCommand(ChannelUID channelUID, Command command) {
54 // can be overridden by subclasses
58 public void onStatusChanged(boolean status) {
59 // can be overridden by subclasses
63 public void onValueReceived(@Nullable String variable, @Nullable String value, @Nullable String service) {
64 // can be overridden by subclasses
68 public void onServiceSubscribed(@Nullable String service, boolean succeeded) {
69 // can be overridden by subclasses
73 public @Nullable String getUDN() {
74 return (String) this.getThing().getConfiguration().get(WemoBindingConstants.UDN);
77 protected boolean isUpnpDeviceRegistered() {
78 UpnpIOService service = this.service;
79 if (service != null) {
80 return service.isRegistered(this);
85 protected String getHost() {
86 String localHost = host;
87 if (!localHost.isEmpty()) {
90 UpnpIOService localService = service;
91 if (localService != null) {
92 URL descriptorURL = localService.getDescriptorURL(this);
93 if (descriptorURL != null) {
94 return descriptorURL.getHost();