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 StrDn1080Handler} is responsible for handling commands for STR-DN1080, which are
30 * sent to one of the channels.
32 * @author David Ã…berg - Initial contribution
34 public class StrDn1080Handler extends SonyAudioHandler {
36 private final Logger logger = LoggerFactory.getLogger(StrDn1080Handler.class);
38 public StrDn1080Handler(Thing thing, WebSocketClient webSocketClient) {
39 super(thing, webSocketClient);
43 public String setInputCommand(Command command) {
44 switch (command.toString().toLowerCase()) {
46 return "extInput:btAudio";
50 return "storage:usb1";
52 return "extInput:bd-dvd";
54 return "extInput:game";
56 return "extInput:sat-catv";
58 return "extInput:video?port=1";
60 return "extInput:video?port=2";
64 return "extInput:sacd-cd";
68 return "extInput:source";
72 return command.toString();
76 public StringType inputSource(String input) {
77 String in = input.toLowerCase();
78 if (in.contains("extinput:btaudio".toLowerCase())) {
79 return new StringType("btaudio");
81 if (in.contains("radio:fm".toLowerCase())) {
82 return new StringType("fm");
84 if (in.contains("storage:usb1".toLowerCase())) {
85 return new StringType("usb");
87 if (in.contains("extInput:bd-dvd".toLowerCase())) {
88 return new StringType("bd/dvd");
90 if (in.contains("extInput:game".toLowerCase())) {
91 return new StringType("game");
93 if (in.contains("extInput:sat-catv".toLowerCase())) {
94 return new StringType("sat/catv");
96 if (in.contains("extInput:video?port=1".toLowerCase())) {
97 return new StringType("video1");
99 if (in.contains("extInput:video?port=2".toLowerCase())) {
100 return new StringType("video2");
102 if (in.contains("extinput:tv".toLowerCase())) {
103 return new StringType("tv");
105 if (in.contains("extInput:sacd-cd".toLowerCase())) {
106 return new StringType("sa-cd/cd");
108 if (in.contains("dlna:music".toLowerCase())) {
109 return new StringType("network");
111 if (in.contains("extInput:source".toLowerCase())) {
112 return new StringType("source");
114 if (in.contains("cast:audio".toLowerCase())) {
115 return new StringType("cast");
117 return new StringType(input);
121 public void handleSoundSettings(Command command, ChannelUID channelUID) throws IOException {
122 if (command instanceof RefreshType) {
124 logger.debug("StrDn1080Handler handleSoundSettings RefreshType");
125 Map<String, String> result = soundSettingsCache.getValue();
127 if (result != null) {
128 logger.debug("StrDn1080Handler Updateing sound field to {} {}", result.get("pureDirect"),
129 result.get("soundField"));
130 if (result.get("pureDirect").equalsIgnoreCase("on")) {
131 updateState(channelUID, new StringType("pureDirect"));
133 updateState(channelUID, new StringType(result.get("soundField")));
136 } catch (CompletionException ex) {
137 throw new IOException(ex.getCause());
140 if (command instanceof StringType) {
141 if (((StringType) command).toString().equalsIgnoreCase("pureDirect")) {
142 connection.setSoundSettings("pureDirect", "on");
144 connection.setSoundSettings("soundField", ((StringType) command).toString());