Skip to content

Commit

Permalink
Update SpeakerDevice properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco van Herk committed Nov 28, 2022
1 parent d7e9391 commit 373d199
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
25 changes: 19 additions & 6 deletions dirigera-client-api/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
"deviceType": "speaker",
"createdAt": "2022-11-27T10:08:08.515Z",
"isReachable": true,
"lastSeen": "2022-11-27T10:08:11.651Z",
"lastSeen": "2022-11-28T19:52:21.239Z",
"attributes": {
"customName": "Decak",
"model": "SYMFONISK Bookshelf S21",
Expand All @@ -328,14 +328,27 @@
"productCode": "S21",
"identifyStarted": "0001-01-01T00:00:00.000Z",
"identifyPeriod": 0,
"playback": "playbackIdle",
"playbackLastChangedTimestamp": "2022-11-27T10:08:08.515Z",
"playbackAudio": {},
"playback": "playbackPlaying",
"playbackLastChangedTimestamp": "2022-11-28T19:52:18.576Z",
"playbackAudio": {
"serviceType": "sonos",
"providerType": "linein.airplay",
"playItem": {
"title": "Fml",
"artist": "deadmau5",
"album": "For Lack of a Better Name",
"imageURL": "http://192.168.100.42:1400/getaa?v=0&vli=1&u=3094074005",
"duration": 419000
},
"nextPlayItem": {
"title": ""
}
},
"playbackPosition": {
"position": 0,
"timestamp": "2022-11-27T10:08:08.332Z"
"timestamp": "2022-11-28T19:52:18.576Z"
},
"volume": 25,
"volume": 13,
"isMuted": false,
"audioGroup": "4a786561-0c2c-4b82-9298-4f775c140d64"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

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.light.LightColorAttributes;
import de.dvdgeisler.iot.dirigera.client.api.model.device.light.LightDevice;
import de.dvdgeisler.iot.dirigera.client.api.model.device.light.LightStateAttributes;
import de.dvdgeisler.iot.dirigera.client.api.model.device.speaker.SpeakerAttributes;
import de.dvdgeisler.iot.dirigera.client.api.model.device.speaker.SpeakerConfigurationAttributes;
import de.dvdgeisler.iot.dirigera.client.api.model.device.speaker.SpeakerDevice;
import de.dvdgeisler.iot.dirigera.client.api.model.device.speaker.SpeakerPlaybackPositionAttributes;
import de.dvdgeisler.iot.dirigera.client.api.model.device.speaker.SpeakerStateAttributes;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -42,10 +36,16 @@ public Mono<SpeakerDevice> unmute(final SpeakerDevice device) {
}

public Mono<SpeakerDevice> setVolume(final SpeakerDevice device, final Integer volume) {

if(volume < 0 || volume > 100)
return Mono.error(new IllegalArgumentException("Volume must be between 0 and 100"));

return this.assertCapability(device, "volume")
.flatMap(d -> this.setStateAttribute(d, createStateAttribute(Optional.empty(), Optional.of(volume))));
}

// TODO: If possible figure out how to start playback. Device does support it as can be seen in the output

private SpeakerStateAttributes createStateAttribute(Optional<Boolean> isMuted, Optional<Integer> volume) {
final SpeakerStateAttributes attributes = new SpeakerStateAttributes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,19 @@

@JsonInclude(Include.NON_NULL)
public class SpeakerAudioAttributes {
public String serviceType;
public String providerType;
public SpeakerPlayItem playItem;
public SpeakerPlayItem nextPlayItem;

public SpeakerAudioAttributes() {
}

public SpeakerAudioAttributes(String serviceType, String providerType, SpeakerPlayItem playItem,
SpeakerPlayItem nextPlayItem) {
this.serviceType = serviceType;
this.providerType = providerType;
this.playItem = playItem;
this.nextPlayItem = nextPlayItem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.dvdgeisler.iot.dirigera.client.api.model.device.speaker;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_NULL)
public class SpeakerPlayItem {
public String title;
public String artist;
public String album;
public String imageUrl;
public Long duration;

public SpeakerPlayItem() {
}

public SpeakerPlayItem(String title, String artist, String album, String imageUrl,
Long duration) {
this.title = title;
this.artist = artist;
this.album = album;
this.imageUrl = imageUrl;
this.duration = duration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.time.LocalDateTime;

@JsonInclude(Include.NON_NULL)
public class SpeakerPlaybackPositionAttributes {
public class SpeakerPlaybackPosition {
public Integer position;
public LocalDateTime timestamp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SpeakerStateAttributes extends DeviceStateAttributes {
public String playback;
public LocalDateTime playbackLastChangedTimestamp;
public SpeakerAudioAttributes playbackAudio;
public SpeakerPlaybackPositionAttributes playbackPosition;
public SpeakerPlaybackPosition playbackPosition;
public Integer volume;
public Boolean isMuted;
}

0 comments on commit 373d199

Please sign in to comment.