[magentatv] Fix: Start UPNP listener to catch power off button, thing id in log (#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>
This commit is contained in:
parent
8d38276dce
commit
937a331f67
@ -57,7 +57,7 @@ public class MagentaTVControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MagentaTVControl(MagentaTVDynamicConfig config, MagentaTVNetwork network, HttpClient httpClient) {
|
public MagentaTVControl(MagentaTVDynamicConfig config, MagentaTVNetwork network, HttpClient httpClient) {
|
||||||
thingId = config.getFriendlyName();
|
this.thingId = config.getFriendlyName();
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.oauth = new MagentaTVOAuth(httpClient);
|
this.oauth = new MagentaTVOAuth(httpClient);
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@ -71,6 +71,10 @@ public class MagentaTVControl {
|
|||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setThingId(String thingId) {
|
||||||
|
this.thingId = thingId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the thingConfig - the Control class adds various attributes of the
|
* Returns the thingConfig - the Control class adds various attributes of the
|
||||||
* discovered device (like the MR model)
|
* discovered device (like the MR model)
|
||||||
|
|||||||
@ -141,6 +141,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
|
|||||||
private void initializeThing() {
|
private void initializeThing() {
|
||||||
String errorMessage = "";
|
String errorMessage = "";
|
||||||
try {
|
try {
|
||||||
|
config.setFriendlyName(getThing().getLabel().toString());
|
||||||
if (config.getUDN().isEmpty()) {
|
if (config.getUDN().isEmpty()) {
|
||||||
// get UDN from device name
|
// get UDN from device name
|
||||||
String uid = this.getThing().getUID().getAsString();
|
String uid = this.getThing().getUID().getAsString();
|
||||||
@ -321,6 +322,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
|
|||||||
protected void connectReceiver() throws MagentaTVException {
|
protected void connectReceiver() throws MagentaTVException {
|
||||||
if (control.checkDev()) {
|
if (control.checkDev()) {
|
||||||
updateThingProperties();
|
updateThingProperties();
|
||||||
|
control.setThingId(config.getFriendlyName());
|
||||||
manager.registerDevice(config.getUDN(), config.getTerminalID(), config.getIpAddress(), this);
|
manager.registerDevice(config.getUDN(), config.getTerminalID(), config.getIpAddress(), this);
|
||||||
control.subscribeEventChannel();
|
control.subscribeEventChannel();
|
||||||
control.sendPairingRequest();
|
control.sendPairingRequest();
|
||||||
|
|||||||
@ -46,6 +46,7 @@ public class MagentaTVPoweroffListener extends Thread {
|
|||||||
protected final MulticastSocket socket;
|
protected final MulticastSocket socket;
|
||||||
protected @Nullable NetworkInterface networkInterface;
|
protected @Nullable NetworkInterface networkInterface;
|
||||||
protected byte[] buf = new byte[256];
|
protected byte[] buf = new byte[256];
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
public MagentaTVPoweroffListener(MagentaTVHandlerFactory handlerFactory,
|
public MagentaTVPoweroffListener(MagentaTVHandlerFactory handlerFactory,
|
||||||
@Nullable NetworkInterface networkInterface) throws IOException {
|
@Nullable NetworkInterface networkInterface) throws IOException {
|
||||||
@ -61,6 +62,7 @@ public class MagentaTVPoweroffListener extends Thread {
|
|||||||
public void start() {
|
public void start() {
|
||||||
if (!isStarted()) {
|
if (!isStarted()) {
|
||||||
logger.debug("Listening to SSDP shutdown messages");
|
logger.debug("Listening to SSDP shutdown messages");
|
||||||
|
started = true;
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,18 +114,19 @@ public class MagentaTVPoweroffListener extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStarted() {
|
public boolean isStarted() {
|
||||||
return socket.isBound();
|
return started;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the socket gets closed
|
* Make sure the socket gets closed
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
if (isStarted()) {
|
if (started) { // if (isStarted()) {
|
||||||
logger.debug("No longer listening to SSDP messages");
|
logger.debug("No longer listening to SSDP messages");
|
||||||
if (!socket.isClosed()) {
|
if (!socket.isClosed()) {
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user