]> git.basschouten.com Git - openhab-addons.git/blob
bd62eadf46f335a4b882281c5d5330867c27e1a2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyaudio.internal.handler;
14
15 import java.io.IOException;
16 import java.util.Map;
17 import java.util.concurrent.CompletionException;
18
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;
27
28 /**
29  * The {@link StrDn1080Handler} is responsible for handling commands for STR-DN1080, which are
30  * sent to one of the channels.
31  *
32  * @author David Ã…berg - Initial contribution
33  */
34 public class StrDn1080Handler extends SonyAudioHandler {
35
36     private final Logger logger = LoggerFactory.getLogger(StrDn1080Handler.class);
37
38     public StrDn1080Handler(Thing thing, WebSocketClient webSocketClient) {
39         super(thing, webSocketClient);
40     }
41
42     @Override
43     public String setInputCommand(Command command) {
44         switch (command.toString().toLowerCase()) {
45             case "btaudio":
46                 return "extInput:btAudio";
47             case "fm":
48                 return "radio:fm";
49             case "usb":
50                 return "storage:usb1";
51             case "bd/dvd":
52                 return "extInput:bd-dvd";
53             case "game":
54                 return "extInput:game";
55             case "sat/catv":
56                 return "extInput:sat-catv";
57             case "video1":
58                 return "extInput:video?port=1";
59             case "video2":
60                 return "extInput:video?port=2";
61             case "tv":
62                 return "extInput:tv";
63             case "sa-cd/cd":
64                 return "extInput:sacd-cd";
65             case "network":
66                 return "dlna:music";
67             case "source":
68                 return "extInput:source";
69             case "cast":
70                 return "cast:audio";
71         }
72         return command.toString();
73     }
74
75     @Override
76     public StringType inputSource(String input) {
77         String in = input.toLowerCase();
78         if (in.contains("extinput:btaudio".toLowerCase())) {
79             return new StringType("btaudio");
80         }
81         if (in.contains("radio:fm".toLowerCase())) {
82             return new StringType("fm");
83         }
84         if (in.contains("storage:usb1".toLowerCase())) {
85             return new StringType("usb");
86         }
87         if (in.contains("extInput:bd-dvd".toLowerCase())) {
88             return new StringType("bd/dvd");
89         }
90         if (in.contains("extInput:game".toLowerCase())) {
91             return new StringType("game");
92         }
93         if (in.contains("extInput:sat-catv".toLowerCase())) {
94             return new StringType("sat/catv");
95         }
96         if (in.contains("extInput:video?port=1".toLowerCase())) {
97             return new StringType("video1");
98         }
99         if (in.contains("extInput:video?port=2".toLowerCase())) {
100             return new StringType("video2");
101         }
102         if (in.contains("extinput:tv".toLowerCase())) {
103             return new StringType("tv");
104         }
105         if (in.contains("extInput:sacd-cd".toLowerCase())) {
106             return new StringType("sa-cd/cd");
107         }
108         if (in.contains("dlna:music".toLowerCase())) {
109             return new StringType("network");
110         }
111         if (in.contains("extInput:source".toLowerCase())) {
112             return new StringType("source");
113         }
114         if (in.contains("cast:audio".toLowerCase())) {
115             return new StringType("cast");
116         }
117         return new StringType(input);
118     }
119
120     @Override
121     public void handleSoundSettings(Command command, ChannelUID channelUID) throws IOException {
122         if (command instanceof RefreshType) {
123             try {
124                 logger.debug("StrDn1080Handler handleSoundSettings RefreshType");
125                 Map<String, String> result = soundSettingsCache.getValue();
126
127                 if (result != null) {
128                     logger.debug("StrDn1080Handler Updateing sound field to {} {}", result.get("pureDirect"),
129                             result.get("soundField"));
130                     if ("on".equalsIgnoreCase(result.get("pureDirect"))) {
131                         updateState(channelUID, new StringType("pureDirect"));
132                     } else {
133                         updateState(channelUID, new StringType(result.get("soundField")));
134                     }
135                 }
136             } catch (CompletionException ex) {
137                 throw new IOException(ex.getCause());
138             }
139         }
140         if (command instanceof StringType stringCommand) {
141             if ("pureDirect".equalsIgnoreCase(stringCommand.toString())) {
142                 connection.setSoundSettings("pureDirect", "on");
143             } else {
144                 connection.setSoundSettings("soundField", stringCommand.toString());
145             }
146         }
147     }
148 }