]> git.basschouten.com Git - openhab-addons.git/blob
2add95c7db9569d5ca46ab831d7593bcafbe3237
[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.upnpcontrol.internal.services;
14
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.jupnp.model.meta.RemoteDevice;
23 import org.jupnp.model.meta.RemoteService;
24 import org.jupnp.model.types.ServiceId;
25
26 /**
27  * Class representing the configuration of the renderer. Instantiation will get configuration parameters from UPnP
28  * {@link RemoteDevice}.
29  *
30  * @author Mark Herwege - Initial contribution
31  */
32 @NonNullByDefault
33 public class UpnpRenderingControlConfiguration {
34     protected static final String UPNP_RENDERING_CONTROL_SCHEMA = "urn:schemas-upnp-org:service:RenderingControl";
35
36     public Set<String> audioChannels = Collections.emptySet();
37
38     public boolean volume;
39     public boolean mute;
40     public boolean loudness;
41
42     public long maxvolume = 100;
43
44     public UpnpRenderingControlConfiguration() {
45     }
46
47     public UpnpRenderingControlConfiguration(@Nullable RemoteDevice device) {
48         if (device == null) {
49             return;
50         }
51
52         RemoteService rcService = device.findService(ServiceId.valueOf(UPNP_RENDERING_CONTROL_SCHEMA));
53         if (rcService != null) {
54             volume = (rcService.getStateVariable("Volume") != null);
55             if (volume) {
56                 maxvolume = rcService.getStateVariable("Volume").getTypeDetails().getAllowedValueRange().getMaximum();
57             }
58             mute = (rcService.getStateVariable("Mute") != null);
59             loudness = (rcService.getStateVariable("Loudness") != null);
60             if (rcService.getStateVariable("A_ARG_TYPE_Channel") != null) {
61                 audioChannels = new HashSet<String>(Arrays
62                         .asList(rcService.getStateVariable("A_ARG_TYPE_Channel").getTypeDetails().getAllowedValues()));
63             }
64         }
65     }
66 }