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.vdr.internal.svdrp;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link SVDRPVolume} contains SVDRP Response Data for Volume Object
20 * @author Matthias Klocke - Initial contribution
23 public class SVDRPVolume {
25 private int volume = -1;
27 private SVDRPVolume() {
31 * parse object from SVDRP Client Response
33 * @param message SVDRP Client Response
34 * @return Volume Object
35 * @throws SVDRPParseResponseException thrown if response data is not parseable
37 public static SVDRPVolume parse(String message) throws SVDRPParseResponseException {
38 SVDRPVolume volume = new SVDRPVolume();
40 String vol = message.substring(message.lastIndexOf(" ") + 1, message.length());
41 if ("mute".equals(vol)) {
44 int val = Integer.parseInt(vol);
45 val = val * 100 / 255;
46 volume.setVolume(val);
48 } catch (NumberFormatException nex) {
49 throw new SVDRPParseResponseException(nex.getMessage(), nex);
50 } catch (IndexOutOfBoundsException ie) {
51 throw new SVDRPParseResponseException(ie.getMessage(), ie);
57 * Get Volume in Percent
59 * @param volume Volume in Percent
61 private void setVolume(int volume) {
66 * Set Volume in Percent
68 * @return Volume in Percent
70 public int getVolume() {
75 * String Representation of SVDRPDiskStatus Object
78 public String toString() {
79 StringBuilder sb = new StringBuilder();
81 sb.append("Volume: ");
82 sb.append(String.valueOf(volume));