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.handler;
15 import java.io.IOException;
17 import java.util.concurrent.CompletionException;
19 import org.eclipse.jetty.websocket.client.WebSocketClient;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.types.Command;
24 import org.openhab.core.types.RefreshType;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The {@link SrsZr5Handler} is responsible for handling commands for SRS-ZR5, which are
30 * sent to one of the channels.
32 * @author David Ã…berg - Initial contribution
34 public class SrsZr5Handler extends SonyAudioHandler {
36 private final Logger logger = LoggerFactory.getLogger(SrsZr5Handler.class);
38 public SrsZr5Handler(Thing thing, WebSocketClient webSocketClient) {
39 super(thing, webSocketClient);
43 public String setInputCommand(Command command) {
44 switch (command.toString().toLowerCase()) {
46 return "extInput:btAudio";
48 return "storage:usb1";
50 return "extInput:line?port=1";
52 return "extInput:hdmi";
58 return command.toString();
62 public StringType inputSource(String input) {
63 String in = input.toLowerCase();
64 if (in.contains("extinput:btaudio".toLowerCase())) {
65 return new StringType("btaudio");
67 if (in.contains("storage:usb1".toLowerCase())) {
68 return new StringType("usb");
70 if (in.contains("extinput:line?port=1".toLowerCase())) {
71 return new StringType("analog");
73 if (in.contains("extinput:hdmi".toLowerCase())) {
74 return new StringType("hdmi1");
76 if (in.contains("dlna:music".toLowerCase())) {
77 return new StringType("network");
79 if (in.contains("cast:audio".toLowerCase())) {
80 return new StringType("cast");
82 return new StringType(input);
86 public void handleSoundSettings(Command command, ChannelUID channelUID) throws IOException {
87 if (command instanceof RefreshType) {
89 logger.debug("SrsZr5Handler handleSoundSettings RefreshType");
90 Map<String, String> result = soundSettingsCache.getValue();
92 logger.debug("SrsZr5Handler Updating sound field to {} {}", result.get("clearAudio"),
93 result.get("soundField"));
94 if ("on".equalsIgnoreCase(result.get("clearAudio"))) {
95 updateState(channelUID, new StringType("clearAudio"));
97 updateState(channelUID, new StringType(result.get("soundField")));
100 } catch (CompletionException ex) {
101 throw new IOException(ex.getCause());
104 if (command instanceof StringType stringCommand) {
105 if ("clearAudio".equalsIgnoreCase(stringCommand.toString())) {
106 connection.setSoundSettings("clearAudio", "on");
108 connection.setSoundSettings("soundField", stringCommand.toString());