Skip to content

Commit

Permalink
[magentatv] Fix: Start UPNP listener to catch power off button, thing…
Browse files Browse the repository at this point in the history
… id in log (openhab#11238)

* Fix: Start UPNP listener to catch power off button, thing id in log
messages

Signed-off-by: Markus Michels <markus7017@gmail.com>

* comment removed

Signed-off-by: Markus Michels <markus7017@gmail.com>
  • Loading branch information
markus7017 authored and frederictobiasc committed Oct 26, 2021
1 parent 3ef193d commit 28db0e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MagentaTVControl() {
}

public MagentaTVControl(MagentaTVDynamicConfig config, MagentaTVNetwork network, HttpClient httpClient) {
thingId = config.getFriendlyName();
this.thingId = config.getFriendlyName();
this.network = network;
this.oauth = new MagentaTVOAuth(httpClient);
this.config = config;
Expand All @@ -71,6 +71,10 @@ public boolean isInitialized() {
return initialized;
}

public void setThingId(String thingId) {
this.thingId = thingId;
}

/**
* Returns the thingConfig - the Control class adds various attributes of the
* discovered device (like the MR model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void initialize() {
private void initializeThing() {
String errorMessage = "";
try {
config.setFriendlyName(getThing().getLabel().toString());
if (config.getUDN().isEmpty()) {
// get UDN from device name
String uid = this.getThing().getUID().getAsString();
Expand Down Expand Up @@ -321,6 +322,7 @@ private void mapKeyToMediateState(String key) {
protected void connectReceiver() throws MagentaTVException {
if (control.checkDev()) {
updateThingProperties();
control.setThingId(config.getFriendlyName());
manager.registerDevice(config.getUDN(), config.getTerminalID(), config.getIpAddress(), this);
control.subscribeEventChannel();
control.sendPairingRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class MagentaTVPoweroffListener extends Thread {
protected final MulticastSocket socket;
protected @Nullable NetworkInterface networkInterface;
protected byte[] buf = new byte[256];
private boolean started = false;

public MagentaTVPoweroffListener(MagentaTVHandlerFactory handlerFactory,
@Nullable NetworkInterface networkInterface) throws IOException {
Expand All @@ -61,6 +62,7 @@ public MagentaTVPoweroffListener(MagentaTVHandlerFactory handlerFactory,
public void start() {
if (!isStarted()) {
logger.debug("Listening to SSDP shutdown messages");
started = true;
super.start();
}
}
Expand Down Expand Up @@ -112,18 +114,19 @@ public void run() {
}

public boolean isStarted() {
return socket.isBound();
return started;
}

/**
* Make sure the socket gets closed
*/
public void close() {
if (isStarted()) {
if (started) { // if (isStarted()) {
logger.debug("No longer listening to SSDP messages");
if (!socket.isClosed()) {
socket.close();
}
started = false;
}
}

Expand Down

0 comments on commit 28db0e6

Please sign in to comment.