]> git.basschouten.com Git - openhab-addons.git/commitdiff
Adding unknown event type + bootstrap handling of topology changes (#15860)
authorGaël L'hopital <gael@lhopital.org>
Sat, 11 Nov 2023 12:52:06 +0000 (13:52 +0100)
committerGitHub <noreply@github.com>
Sat, 11 Nov 2023 12:52:06 +0000 (13:52 +0100)
Signed-off-by: clinique <gael@lhopital.org>
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/EventType.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java
bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/WebhookEvent.java

index d088853d2426d1cf06518d0adb7f5cb10b7a979e..1b4a6cd9eed5145a3746918e8bd59c341336a03f 100644 (file)
@@ -20,14 +20,18 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import com.google.gson.annotations.SerializedName;
 
 /**
- * This enum describes events generated by webhooks and the type of
- * module they are related to according to API documentation
+ * This enum describes events generated by webhooks and the type of module they are related to according to
+ * API documentation
  *
  * @author Gaël L'hopital - Initial contribution
  */
 @NonNullByDefault
 public enum EventType {
-    UNKNOWN(),
+    UNKNOWN(ModuleType.UNKNOWN),
+
+    @SerializedName("topology_changed") // Module configuration changed
+    TOPOLOGY_CHANGED(ModuleType.ACCOUNT),
+
     @SerializedName("webhook_activation") // Ack of a 'webhook set' Api Call
     WEBHOOK_ACTIVATION(ModuleType.ACCOUNT),
 
@@ -171,6 +175,10 @@ public enum EventType {
     private final Set<ModuleType> appliesTo;
 
     EventType(ModuleType... appliesTo) {
+        if (appliesTo.length == 0) {
+            throw new IllegalArgumentException(
+                    "Event type must be associated to at least a module type, please file a bug report.");
+        }
         this.appliesTo = Set.of(appliesTo);
     }
 
index d9c5283faf08a451bf584200945163c317b61ad1..e5ba87e53912e475e987322751c7e29e6ee1bca2 100644 (file)
@@ -195,7 +195,7 @@ public enum ModuleType {
                     : WIFI_SIGNAL_LEVELS;
         }
         throw new IllegalArgumentException(
-                "getSignalLevels should not be called for module type : '%s', please file a bug report."
+                "getSignalLevels should not be called for module type: '%s', please file a bug report."
                         .formatted(name()));
     }
 
index 471ff007ef71cfcf07f078cffd8e9a7e1369fe41..555eab75475e09bd4911fc534934c3019b6c5ba6 100644 (file)
@@ -203,6 +203,23 @@ public class NetatmoConstants {
         UNKNOWN
     }
 
+    // Topology Changes
+    public enum TopologyChange {
+        @SerializedName("home_owner_added")
+        HOME_OWNER_ADDED,
+        @SerializedName("device_associated_to_user")
+        DEVICE_ASSOCIATED_TO_USER,
+        @SerializedName("device_associated_to_home")
+        DEVICE_ASSOCIATED_TO_HOME,
+        @SerializedName("device_updated")
+        DEVICE_UPDATED,
+        @SerializedName("device_associated_to_room")
+        DEVICE_ASSOCIATED_TO_ROOM,
+        @SerializedName("room_created")
+        ROOM_CREATED,
+        UNKNOWN
+    }
+
     private static final Scope[] SMOKE_SCOPES = { Scope.READ_SMOKEDETECTOR };
     private static final Scope[] CARBON_MONOXIDE_SCOPES = { Scope.READ_CARBONMONOXIDEDETECTOR };
     private static final Scope[] AIR_CARE_SCOPES = { Scope.READ_HOMECOACH };
index c8e84368112f6b6e9505b6b864514729aeda2bff..602541944c5e208be3cc0d1d7cbcfb81e5a5da55 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.netatmo.internal.api.data.EventType;
+import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.TopologyChange;
 import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;
 import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
 
@@ -37,6 +38,7 @@ public class WebhookEvent extends Event {
     private String deviceId = "";
     private @Nullable String snapshotUrl;
     private @Nullable String vignetteUrl;
+    private TopologyChange change = TopologyChange.UNKNOWN;
     private NAObjectMap<Person> persons = new NAObjectMap<>();
     // Webhook does not provide the event generation time, so we'll use the event reception time
     private ZonedDateTime time = ZonedDateTime.now();
@@ -89,4 +91,8 @@ public class WebhookEvent extends Event {
             collection.add(value);
         }
     }
+
+    public TopologyChange getChange() {
+        return change;
+    }
 }