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;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This enum describes events generated by webhooks and the type of
|
* This enum describes events generated by webhooks and the type of module they are related to according to
|
||||||
* module they are related to according to API documentation
|
* API documentation
|
||||||
*
|
*
|
||||||
* @author Gaël L'hopital - Initial contribution
|
* @author Gaël L'hopital - Initial contribution
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public enum EventType {
|
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
|
@SerializedName("webhook_activation") // Ack of a 'webhook set' Api Call
|
||||||
WEBHOOK_ACTIVATION(ModuleType.ACCOUNT),
|
WEBHOOK_ACTIVATION(ModuleType.ACCOUNT),
|
||||||
|
|
||||||
@ -171,6 +175,10 @@ public enum EventType {
|
|||||||
private final Set<ModuleType> appliesTo;
|
private final Set<ModuleType> appliesTo;
|
||||||
|
|
||||||
EventType(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);
|
this.appliesTo = Set.of(appliesTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -203,6 +203,23 @@ public class NetatmoConstants {
|
|||||||
UNKNOWN
|
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[] SMOKE_SCOPES = { Scope.READ_SMOKEDETECTOR };
|
||||||
private static final Scope[] CARBON_MONOXIDE_SCOPES = { Scope.READ_CARBONMONOXIDEDETECTOR };
|
private static final Scope[] CARBON_MONOXIDE_SCOPES = { Scope.READ_CARBONMONOXIDEDETECTOR };
|
||||||
private static final Scope[] AIR_CARE_SCOPES = { Scope.READ_HOMECOACH };
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.netatmo.internal.api.data.EventType;
|
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.NAObjectMap;
|
||||||
import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
|
import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ public class WebhookEvent extends Event {
|
|||||||
private String deviceId = "";
|
private String deviceId = "";
|
||||||
private @Nullable String snapshotUrl;
|
private @Nullable String snapshotUrl;
|
||||||
private @Nullable String vignetteUrl;
|
private @Nullable String vignetteUrl;
|
||||||
|
private TopologyChange change = TopologyChange.UNKNOWN;
|
||||||
private NAObjectMap<Person> persons = new NAObjectMap<>();
|
private NAObjectMap<Person> persons = new NAObjectMap<>();
|
||||||
// Webhook does not provide the event generation time, so we'll use the event reception time
|
// Webhook does not provide the event generation time, so we'll use the event reception time
|
||||||
private ZonedDateTime time = ZonedDateTime.now();
|
private ZonedDateTime time = ZonedDateTime.now();
|
||||||
@ -89,4 +91,8 @@ public class WebhookEvent extends Event {
|
|||||||
collection.add(value);
|
collection.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TopologyChange getChange() {
|
||||||
|
return change;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user