mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Adding unknown event type + bootstrap handling of topology changes (#15860)
Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
parent
d0c70f88b3
commit
6176b080c4
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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 };
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user