forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pulseaudio] Allow flexible parameters to find a given pulseaudio device
To identify the device on the pulseaudio server, you can now use the description instead of the technical id (a.k.a. "name"). To filter furthermore, you can also use the parameter additionalFilters (optional regular expressions that need to match a property value of a device on the pulseaudio server) Closes openhab#12555 Signed-off-by: Gwendal Roulleau <[email protected]>
- Loading branch information
Showing
19 changed files
with
258 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...audio/src/main/java/org/openhab/binding/pulseaudio/internal/handler/DeviceIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.pulseaudio.internal.handler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
/** | ||
* All informations needed to precisely identify a device | ||
* | ||
* @author Gwendal Roulleau - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class DeviceIdentifier { | ||
|
||
private String nameOrDescription; | ||
private List<Pattern> additionalFilters = new ArrayList<>(); | ||
|
||
public DeviceIdentifier(String nameOrDescription, @Nullable String additionalFilters) { | ||
super(); | ||
this.nameOrDescription = nameOrDescription; | ||
if (additionalFilters != null && !additionalFilters.isEmpty()) { | ||
Arrays.asList(additionalFilters.split("###")).stream() | ||
.forEach(ad -> this.additionalFilters.add(Pattern.compile(ad))); | ||
} | ||
} | ||
|
||
public String getNameOrDescription() { | ||
return nameOrDescription; | ||
} | ||
|
||
public List<Pattern> getAdditionalFilters() { | ||
return additionalFilters; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
List<Pattern> additionalFiltersFinal = additionalFilters; | ||
String additionalPatternToString = additionalFiltersFinal.stream().map(Pattern::pattern) | ||
.collect(Collectors.joining("###")); | ||
return "DeviceIdentifier [nameOrDescription=" + nameOrDescription + ", additionalFilter=" | ||
+ additionalPatternToString + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.