Skip to content

Commit ae2137f

Browse files
Support new resource for 'player' settings - e.g. volume mode, scaling factor, mono, and wifi disabling
1 parent a08d14e commit ae2137f

3 files changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package engineer.nightowl.sonos.api.domain;
2+
3+
import engineer.nightowl.sonos.api.enums.SonosVolumeMode;
4+
import org.apache.commons.lang3.builder.EqualsBuilder;
5+
import org.apache.commons.lang3.builder.HashCodeBuilder;
6+
7+
public class SonosPlayerSettings
8+
{
9+
private SonosVolumeMode volumeMode;
10+
private Float volumeScalingFactor;
11+
private Boolean monoMode;
12+
private Boolean wifiDisable;
13+
14+
public SonosPlayerSettings()
15+
{
16+
}
17+
18+
public SonosPlayerSettings(SonosVolumeMode volumeMode, Float volumeScalingFactor, Boolean monoMode, Boolean wifiDisable)
19+
{
20+
this.volumeMode = volumeMode;
21+
this.volumeScalingFactor = volumeScalingFactor;
22+
this.monoMode = monoMode;
23+
this.wifiDisable = wifiDisable;
24+
}
25+
26+
public SonosVolumeMode getVolumeMode()
27+
{
28+
return volumeMode;
29+
}
30+
31+
public void setVolumeMode(SonosVolumeMode volumeMode)
32+
{
33+
this.volumeMode = volumeMode;
34+
}
35+
36+
public Float getVolumeScalingFactor()
37+
{
38+
return volumeScalingFactor;
39+
}
40+
41+
public void setVolumeScalingFactor(Float volumeScalingFactor)
42+
{
43+
this.volumeScalingFactor = volumeScalingFactor;
44+
}
45+
46+
public Boolean getMonoMode()
47+
{
48+
return monoMode;
49+
}
50+
51+
public void setMonoMode(Boolean monoMode)
52+
{
53+
this.monoMode = monoMode;
54+
}
55+
56+
public Boolean getWifiDisable()
57+
{
58+
return wifiDisable;
59+
}
60+
61+
public void setWifiDisable(Boolean wifiDisable)
62+
{
63+
this.wifiDisable = wifiDisable;
64+
}
65+
66+
@Override
67+
public String toString()
68+
{
69+
return "SonosPlayerSettings{" +
70+
"volumeMode=" + volumeMode +
71+
", volumeScalingFactor=" + volumeScalingFactor +
72+
", monoMode=" + monoMode +
73+
", wifiDisable=" + wifiDisable +
74+
'}';
75+
}
76+
77+
@Override
78+
public boolean equals(Object o)
79+
{
80+
if (this == o) return true;
81+
82+
if (o == null || getClass() != o.getClass()) return false;
83+
84+
SonosPlayerSettings that = (SonosPlayerSettings) o;
85+
86+
return new EqualsBuilder()
87+
.append(volumeMode, that.volumeMode)
88+
.append(volumeScalingFactor, that.volumeScalingFactor)
89+
.append(monoMode, that.monoMode)
90+
.append(wifiDisable, that.wifiDisable)
91+
.isEquals();
92+
}
93+
94+
@Override
95+
public int hashCode()
96+
{
97+
return new HashCodeBuilder(17, 37)
98+
.append(volumeMode)
99+
.append(volumeScalingFactor)
100+
.append(monoMode)
101+
.append(wifiDisable)
102+
.toHashCode();
103+
}
104+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package engineer.nightowl.sonos.api.enums;
2+
3+
public enum SonosVolumeMode
4+
{
5+
VARIABLE,
6+
FIXED,
7+
PASS_THROUGH
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package engineer.nightowl.sonos.api.resource;
2+
3+
import engineer.nightowl.sonos.api.SonosApiClient;
4+
import engineer.nightowl.sonos.api.domain.SonosPlayerSettings;
5+
import engineer.nightowl.sonos.api.domain.SonosSuccess;
6+
import engineer.nightowl.sonos.api.exception.SonosApiClientException;
7+
import engineer.nightowl.sonos.api.exception.SonosApiError;
8+
9+
public class SettingsResource extends BaseResource
10+
{
11+
/**
12+
* <p>Constructor for SettingsResource.</p>
13+
*
14+
* @param apiClient a {@link engineer.nightowl.sonos.api.SonosApiClient} object.
15+
*/
16+
public SettingsResource(final SonosApiClient apiClient)
17+
{
18+
super(apiClient);
19+
}
20+
21+
/**
22+
* Get a player's settings
23+
*
24+
* @see <a href="https://developer.sonos.com/reference/control-api/settings/getplayersettings/">Sonos docs</a>
25+
* @param clientToken for the user
26+
* @param playerId to fetch settings for
27+
* @return SonosPlayerSettings for the specified player
28+
* @throws engineer.nightowl.sonos.api.exception.SonosApiClientException if an error occurs during the call.
29+
* @throws engineer.nightowl.sonos.api.exception.SonosApiError if there is an error from the API
30+
*/
31+
public SonosPlayerSettings getSettings(final String clientToken, final String playerId) throws SonosApiClientException, SonosApiError
32+
{
33+
return getFromApi(SonosPlayerSettings.class, clientToken, String.format("/v1/players/%s/settings/player", playerId));
34+
}
35+
36+
/**
37+
* Set settings for a specified player
38+
*
39+
* @see <a href="https://developer.sonos.com/reference/control-api/settings/setplayersettings/">Sonos docs</a>
40+
* @param clientToken for the user
41+
* @param playerId to set the options for
42+
* @param sonosPlayerSettings configured {@link engineer.nightowl.sonos.api.domain.SonosPlayerSettings}
43+
* @return if successful
44+
* @throws engineer.nightowl.sonos.api.exception.SonosApiClientException if an error occurs during the call
45+
* @throws engineer.nightowl.sonos.api.exception.SonosApiError if there is an error from the API
46+
*/
47+
public SonosSuccess setSettings(final String clientToken, final String playerId, final SonosPlayerSettings sonosPlayerSettings) throws SonosApiClientException, SonosApiError
48+
{
49+
return postToApi(SonosSuccess.class, clientToken, String.format("/v1/players/%s/settings/player", playerId), sonosPlayerSettings);
50+
}
51+
}

0 commit comments

Comments
 (0)