]> git.basschouten.com Git - openhab-addons.git/commitdiff
[magentatv] Fix: Start UPNP listener to catch power off button, thing id in log ...
authorMarkus Michels <markus7017@gmail.com>
Sat, 2 Oct 2021 21:02:28 +0000 (23:02 +0200)
committerGitHub <noreply@github.com>
Sat, 2 Oct 2021 21:02:28 +0000 (23:02 +0200)
* 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>
bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVControl.java
bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/handler/MagentaTVHandler.java
bundles/org.openhab.binding.magentatv/src/main/java/org/openhab/binding/magentatv/internal/network/MagentaTVPoweroffListener.java

index 68bed02f44245954f32bcef15bcffba7caf318ed..01a764bca7f05fae165cff78b7de1485a1675a8f 100755 (executable)
@@ -57,7 +57,7 @@ public class 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;
@@ -71,6 +71,10 @@ public class MagentaTVControl {
         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)
index 3d9a9f671690879343d6bba40cfe63326828d4b8..9d93c13f85cbe432f269e27435495d2bee392694 100755 (executable)
@@ -141,6 +141,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
     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();
@@ -321,6 +322,7 @@ public class MagentaTVHandler extends BaseThingHandler implements MagentaTVListe
     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();
index 8deca24405baeb51d1bd15e60100429134264806..5c8d7ef62a0f15e96047d7d020284b5a7929eb28 100755 (executable)
@@ -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 {
@@ -61,6 +62,7 @@ public class MagentaTVPoweroffListener extends Thread {
     public void start() {
         if (!isStarted()) {
             logger.debug("Listening to SSDP shutdown messages");
+            started = true;
             super.start();
         }
     }
@@ -112,18 +114,19 @@ public class MagentaTVPoweroffListener extends Thread {
     }
 
     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;
         }
     }