]> git.basschouten.com Git - openhab-addons.git/blob
6aecbab952fdbadfc0f877285a0c442629149e2e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.monopriceaudio.internal.communication;
14
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.monopriceaudio.internal.MonopriceAudioException;
21
22 /**
23  * Represents the different internal zone IDs of the Monoprice Whole House Amplifier
24  *
25  * @author Michael Lobstein - Initial contribution
26  */
27 @NonNullByDefault
28 public enum MonopriceAudioZone {
29
30     ALL("all"),
31     ZONE1("11"),
32     ZONE2("12"),
33     ZONE3("13"),
34     ZONE4("14"),
35     ZONE5("15"),
36     ZONE6("16"),
37     ZONE7("21"),
38     ZONE8("22"),
39     ZONE9("23"),
40     ZONE10("24"),
41     ZONE11("25"),
42     ZONE12("26"),
43     ZONE13("31"),
44     ZONE14("32"),
45     ZONE15("33"),
46     ZONE16("34"),
47     ZONE17("35"),
48     ZONE18("36");
49
50     private final String zoneId;
51
52     // make a list of all valid zone names
53     public static final List<String> VALID_ZONES = Arrays.stream(values()).filter(z -> z != ALL)
54             .map(MonopriceAudioZone::name).collect(Collectors.toList());
55
56     // make a list of all valid zone ids
57     public static final List<String> VALID_ZONE_IDS = Arrays.stream(values()).filter(z -> z != ALL)
58             .map(MonopriceAudioZone::getZoneId).collect(Collectors.toList());
59
60     public static MonopriceAudioZone fromZoneId(String zoneId) throws MonopriceAudioException {
61         return Arrays.stream(values()).filter(z -> z.zoneId.equalsIgnoreCase(zoneId)).findFirst()
62                 .orElseThrow(() -> new MonopriceAudioException("Invalid zoneId specified: " + zoneId));
63     }
64
65     MonopriceAudioZone(String zoneId) {
66         this.zoneId = zoneId;
67     }
68
69     /**
70      * Get the zone id
71      *
72      * @return the zone id
73      */
74     public String getZoneId() {
75         return zoneId;
76     }
77 }