]> git.basschouten.com Git - openhab-addons.git/blob
7797efb716470a18a2b38854c8258e84fc05ffe2
[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.pjlinkdevice.internal.device.command.mute;
14
15 import java.util.Arrays;
16 import java.util.HashSet;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.pjlinkdevice.internal.device.command.ErrorCode;
20 import org.openhab.binding.pjlinkdevice.internal.device.command.PrefixedResponse;
21 import org.openhab.binding.pjlinkdevice.internal.device.command.ResponseException;
22
23 /**
24  * The response part of {@link MuteQueryCommand}
25  *
26  * @author Nils Schnabel - Initial contribution
27  */
28 @NonNullByDefault
29 public class MuteQueryResponse extends PrefixedResponse<MuteQueryResponse.MuteQueryResponseValue> {
30
31     public enum MuteQueryResponseValue {
32         OFF("Mute off", "30", false, false),
33         VIDEO_MUTE_ON("Video muted", "11", false, true),
34         AUDIO_MUTE_ON("Audio muted", "21", true, false),
35         AUDIO_AND_VIDEO_MUTE_ON("Audio and video muted", "31", true, true);
36
37         private String text;
38         private String code;
39         private boolean audioMuted;
40         private boolean videoMuted;
41
42         private MuteQueryResponseValue(String text, String code, boolean audioMuted, boolean videoMuted) {
43             this.text = text;
44             this.code = code;
45             this.audioMuted = audioMuted;
46             this.videoMuted = videoMuted;
47         }
48
49         public String getText() {
50             return this.text;
51         }
52
53         public static MuteQueryResponseValue parseString(String code) throws ResponseException {
54             for (MuteQueryResponseValue result : MuteQueryResponseValue.values()) {
55                 if (result.code.equals(code)) {
56                     return result;
57                 }
58             }
59
60             throw new ResponseException("Cannot understand mute status: " + code);
61         }
62
63         public boolean isAudioMuted() {
64             return this.audioMuted;
65         }
66
67         public boolean isVideoMuted() {
68             return this.videoMuted;
69         }
70     }
71
72     private static final HashSet<ErrorCode> SPECIFIED_ERRORCODES = new HashSet<>(
73             Arrays.asList(ErrorCode.UNAVAILABLE_TIME, ErrorCode.DEVICE_FAILURE));
74
75     public MuteQueryResponse(String response) throws ResponseException {
76         super("AVMT=", SPECIFIED_ERRORCODES, response);
77     }
78
79     @Override
80     protected MuteQueryResponseValue parseResponseWithoutPrefix(String responseWithoutPrefix) throws ResponseException {
81         return MuteQueryResponseValue.parseString(responseWithoutPrefix);
82     }
83 }