Skip to content

Commit

Permalink
Add json even deserialization to websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdgeisler committed Nov 29, 2022
1 parent 3c4de79 commit 6787c19
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import de.dvdgeisler.iot.dirigera.client.api.http.ClientApi;
import de.dvdgeisler.iot.dirigera.client.api.model.device.Device;
import de.dvdgeisler.iot.dirigera.client.api.model.device.DeviceType;
import de.dvdgeisler.iot.dirigera.client.api.model.events.Event;
import de.dvdgeisler.iot.dirigera.client.api.model.events.SceneUpdatedEvent;
import de.dvdgeisler.iot.dirigera.client.api.model.scene.Scene;
import de.dvdgeisler.iot.dirigera.client.api.model.scene.SceneTriggerApp;
import de.dvdgeisler.iot.dirigera.client.api.model.scene.SceneTriggerController;
Expand All @@ -22,7 +24,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -124,20 +125,17 @@ public CommandLineRunner run() {
};
}

private void logButtonPress(final String s) {
private void logButtonPress(final Event event) {
final Map json, data, info;
final String type;



try {
json = this.json.readValue(s, Map.class);
type = json.get("type").toString();
if(!Objects.equals(type, "sceneUpdated")) {
log.info("Received: {}", s);
return;
switch (event.type) {
case SCENE_UPDATED -> log.info("Received: {}", ((SceneUpdatedEvent)event).data.attributes.info);
default -> log.info("Received: {}", this.json.writeValueAsString(event));
}
data = (Map) json.get("data");
info = (Map) data.get("info");
log.info("Received: {}", info.get("name"));
} catch (Throwable e) {
log.error(e.getMessage());
}
Expand Down

0 comments on commit 6787c19

Please sign in to comment.