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.pulseaudio.internal.items;
15 import java.util.List;
17 import java.util.regex.Pattern;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.pulseaudio.internal.handler.DeviceIdentifier;
24 * GenericAudioItems are any kind of items that deal with audio data and can be
25 * muted or their volume can be changed.
27 * @author Tobias Bräutigam - Initial contribution
30 public abstract class AbstractAudioDeviceConfig extends AbstractDeviceConfig {
40 protected @Nullable State state;
41 protected boolean muted;
43 protected @Nullable Module module;
44 protected String secondaryIdentifier;
45 protected Map<String, String> properties;
47 public AbstractAudioDeviceConfig(int id, String name, @Nullable String secondaryIdentifier,
48 Map<String, String> properties, @Nullable Module module) {
51 this.secondaryIdentifier = secondaryIdentifier == null ? "" : secondaryIdentifier;
52 this.properties = properties;
57 * @param deviceIdentifier The device identifier to check against
58 * @return true if this device match the requested identifier, false otherwise
60 public boolean matches(DeviceIdentifier deviceIdentifier) {
61 boolean matches = getPaName().equalsIgnoreCase(deviceIdentifier.getNameOrDescription())
62 || secondaryIdentifier.equalsIgnoreCase(deviceIdentifier.getNameOrDescription());
64 return false; // stop analysis right here, no need to parse properties
66 List<Pattern> additionalFilters = deviceIdentifier.getAdditionalFilters();
67 if (additionalFilters.isEmpty()) { // the additionalFilter property is not defined, don't check against
70 for (Pattern patternToMatch : additionalFilters) {
71 if (!properties.values().stream().anyMatch(value -> patternToMatch.matcher(value).find())) {
80 public @Nullable Module getModule() {
84 public @Nullable State getState() {
88 public void setState(State state) {
92 public boolean isMuted() {
96 public void setMuted(boolean muted) {
100 public int getVolume() {
104 public void setVolume(int volume) {
105 this.volume = volume;
109 public String toString() {
110 return this.getClass().getSimpleName() + " #" + id + " (Module: " + module + ") " + name + ", muted: " + muted
111 + ", state: " + state + ", volume: " + volume;