2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sonyaudio.internal.protocol;
15 import java.util.List;
18 * The {@link SonyAudioMethod} base class for SONY API methods
20 * @author David Åberg - Initial contribution
22 public abstract class SonyAudioMethod {
24 protected String method;
25 protected String version;
27 public SonyAudioMethod(String method, String version) {
29 this.version = version;
34 * The {@link GetPowerStatus} SONY Audio control API method
36 * @author David Åberg - Initial contribution
38 class GetPowerStatus extends SonyAudioMethod {
39 public String[] params = new String[] {};
41 public GetPowerStatus() {
42 super("getPowerStatus", "1.1");
47 * The {@link GetCurrentExternalTerminalsStatus} SONY Audio control API method
49 * @author David Åberg - Initial contribution
51 class GetCurrentExternalTerminalsStatus extends SonyAudioMethod {
52 public String[] params = new String[] {};
54 public GetCurrentExternalTerminalsStatus() {
55 super("getCurrentExternalTerminalsStatus", "1.0");
60 * The {@link SetPowerStatus} SONY Audio control API method
62 * @author David Åberg - Initial contribution
64 class SetPowerStatus extends SonyAudioMethod {
65 public Param[] params;
70 Param(boolean power) {
71 status = power ? "active" : "off";
75 SetPowerStatus(boolean power) {
76 super("setPowerStatus", "1.1");
77 Param param = new Param(power);
78 params = new Param[] { param };
83 * The {@link SetActiveTerminal} SONY Audio control API method
85 * @author David Åberg - Initial contribution
87 class SetActiveTerminal extends SonyAudioMethod {
88 public Param[] params;
94 Param(boolean power, int zone) {
95 active = power ? "active" : "inactive";
97 uri = "extOutput:zone?zone=" + Integer.toString(zone);
102 SetActiveTerminal(boolean power, int zone) {
103 super("setActiveTerminal", "1.0");
104 Param param = new Param(power, zone);
105 params = new Param[] { param };
110 * The {@link GetPlayingContentInfo} SONY Audio control API method
112 * @author David Åberg - Initial contribution
114 class GetPlayingContentInfo extends SonyAudioMethod {
115 public Param[] params;
125 output = "extOutput:zone?zone=" + Integer.toString(zone);
130 GetPlayingContentInfo() {
131 super("getPlayingContentInfo", "1.2");
132 Param param = new Param();
133 params = new Param[] { param };
136 GetPlayingContentInfo(int zone) {
137 super("getPlayingContentInfo", "1.2");
138 Param param = new Param(zone);
139 params = new Param[] { param };
144 * The {@link SetPlayContent} SONY Audio control API method
146 * @author David Åberg - Initial contribution
148 class SetPlayContent extends SonyAudioMethod {
149 public Param[] params;
155 Param(String input) {
159 Param(String input, int zone) {
162 output = "extOutput:zone?zone=" + Integer.toString(zone);
167 SetPlayContent(String input) {
168 super("setPlayContent", "1.2");
169 params = new Param[] { new Param(input) };
172 SetPlayContent(String input, int zone) {
173 super("setPlayContent", "1.2");
174 params = new Param[] { new Param(input, zone) };
179 * The {@link GetVolumeInformation} SONY Audio control API method
181 * @author David Åberg - Initial contribution
183 class GetVolumeInformation extends SonyAudioMethod {
184 public Param[] params;
194 output = "extOutput:zone?zone=" + Integer.toString(zone);
199 GetVolumeInformation() {
203 GetVolumeInformation(int zone) {
204 super("getVolumeInformation", "1.1");
205 params = new Param[] { new Param(zone) };
210 * The {@link SetAudioVolume} SONY Audio control API method
212 * @author David Åberg - Initial contribution
214 class SetAudioVolume extends SonyAudioMethod {
215 public Param[] params;
221 Param(long new_volume) {
222 volume = Long.toString(new_volume);
225 Param(String volume_change) {
226 volume = volume_change;
229 Param(long new_volume, int zone) {
230 volume = Long.toString(new_volume);
232 output = "extOutput:zone?zone=" + Integer.toString(zone);
236 Param(String volume_change, int zone) {
237 volume = volume_change;
239 output = "extOutput:zone?zone=" + Integer.toString(zone);
244 SetAudioVolume(int volume, int min, int max) {
245 super("setAudioVolume", "1.1");
246 long scaledVolume = scaleVolume(volume, min, max);
247 params = new Param[] { new Param(scaledVolume) };
250 SetAudioVolume(int zone, int volume, int min, int max) {
251 super("setAudioVolume", "1.1");
252 long scaledVolume = scaleVolume(volume, min, max);
253 params = new Param[] { new Param(scaledVolume, zone) };
256 SetAudioVolume(String volume_change) {
257 super("setAudioVolume", "1.1");
258 params = new Param[] { new Param(volume_change) };
261 SetAudioVolume(int zone, String volume_change) {
262 super("setAudioVolume", "1.1");
263 params = new Param[] { new Param(volume_change, zone) };
266 long scaleVolume(int volume, int min, int max) {
267 return Math.round(((max - min) * volume / 100.0) + min);
272 * The {@link SetAudioMute} SONY Audio control API method
274 * @author David Åberg - Initial contribution
276 class SetAudioMute extends SonyAudioMethod {
277 public Param[] params;
283 Param(boolean mute) {
284 this.mute = mute ? "on" : "off";
287 Param(boolean mute, int zone) {
288 this.mute = mute ? "on" : "off";
290 output = "extOutput:zone?zone=" + Integer.toString(zone);
295 SetAudioMute(boolean mute) {
296 super("setAudioMute", "1.1");
297 params = new Param[] { new Param(mute) };
300 SetAudioMute(boolean mute, int zone) {
301 super("setAudioMute", "1.1");
302 params = new Param[] { new Param(mute, zone) };
309 * @author David Åberg - Initial contribution
311 class GetSoundSettings extends SonyAudioMethod {
312 public Param[] params;
317 Param(String target) {
318 this.target = target;
323 super("getSoundSettings", "1.1");
324 params = new Param[] { new Param("") };
327 GetSoundSettings(String target) {
328 super("getSoundSettings", "1.1");
329 params = new Param[] { new Param(target) };
336 * @author David Åberg - Initial contribution
338 class SetSoundSettings extends SonyAudioMethod {
339 public Param[] params;
345 Settings(String target, String value) {
346 this.target = target;
355 Param(Settings[] settings) {
356 this.settings = settings;
361 super("setSoundSettings", "1.1");
364 SetSoundSettings(String target, String value) {
365 super("setSoundSettings", "1.1");
366 Settings[] settings = { new Settings(target, value) };
367 params = new Param[] { new Param(settings) };
372 * The {@link SetSoundField} SONY Audio control API method
374 * @author David Åberg - Initial contribution
376 class SetSoundField extends SetSoundSettings {
377 SetSoundField(String soundField) {
378 super("soundField", soundField);
383 * The {@link SetPureDirect} SONY Audio control API method
385 * @author David Åberg - Initial contribution
387 class SetPureDirect extends SetSoundSettings {
388 SetPureDirect(boolean pureDirect) {
389 super("pureDirect", pureDirect ? "on" : "off");
394 * The {@link SetClearAudio} SONY Audio control API method
396 * @author David Åberg - Initial contribution
398 class SetClearAudio extends SetSoundSettings {
399 SetClearAudio(boolean clearAudio) {
400 super("clearAudio", clearAudio ? "on" : "off");
405 * The {@link SwitchNotifications} SONY Audio control API method
407 * @author David Åberg - Initial contribution
409 class SwitchNotifications extends SonyAudioMethod {
410 public Param[] params;
417 public String toString() {
418 return "Notification{name='" + name + "' version='" + version + "'}";
423 List<Notification> enabled;
424 List<Notification> disabled;
426 Param(List<Notification> enabled, List<Notification> disabled) {
427 this.enabled = enabled;
428 this.disabled = disabled;
432 SwitchNotifications(List<Notification> enabled, List<Notification> disabled) {
433 super("switchNotifications", "1.0");
434 params = new Param[] { new Param(!enabled.isEmpty() ? enabled : null, !disabled.isEmpty() ? disabled : null) };
439 * The {@link SeekBroadcastStation} SONY Audio control API method
441 * @author David Åberg - Initial contribution
443 class SeekBroadcastStation extends SonyAudioMethod {
444 public Param[] params;
447 String tuning = "auto";
450 Param(boolean forward) {
451 this.direction = forward ? "fwd" : "bwd";
455 SeekBroadcastStation(boolean forward) {
456 super("seekBroadcastStation", "1.0");
457 params = new Param[] { new Param(forward) };