diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/EventType.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/EventType.java index d088853d242..1b4a6cd9eed 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/EventType.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/EventType.java @@ -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 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); } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java index d9c5283faf0..e5ba87e5391 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java @@ -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())); } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java index 471ff007ef7..555eab75475 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/NetatmoConstants.java @@ -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 }; diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/WebhookEvent.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/WebhookEvent.java index c8e84368112..602541944c5 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/WebhookEvent.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/WebhookEvent.java @@ -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 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; + } }