From f1f628a9f56f6bae3f465baef954ca4377fb077d Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Sun, 19 Sep 2021 17:58:22 +0200 Subject: [PATCH] [pulseaudio] Fix sink-input configuration and other small improvements (#11272) The binding requires a parameter to activate the parsing of sink-input entries on the pulseaudio server. This patch : - document this behaviour - fix the parsing of these parameters if a configuration file is used (the old method of casting launched a class cast exception) Other small improvements : - Force a refresh/new parsing when the configuration changes - Fix scheduled disconnection : if a sound is played during the grace period, the scheduled disconnection is postponed, not added to the last - add a possibility to never disconnect the audio sink (in order to have a lower latency when playing sound) Signed-off-by: Gwendal Roulleau --- .../org.openhab.binding.pulseaudio/README.md | 23 +++++++- .../internal/PulseAudioAudioSink.java | 13 ++++- .../PulseAudioBindingConfiguration.java | 52 +++++++++++++++++++ ...ulseAudioBindingConfigurationListener.java | 24 +++++++++ .../internal/PulseaudioBindingConstants.java | 12 ----- .../pulseaudio/internal/PulseaudioClient.java | 20 +++---- .../internal/PulseaudioHandlerFactory.java | 33 +++++------- .../handler/PulseaudioBridgeHandler.java | 26 ++++++++-- .../internal/handler/PulseaudioHandler.java | 6 ++- .../src/main/resources/OH-INF/thing/sink.xml | 2 +- 10 files changed, 160 insertions(+), 51 deletions(-) create mode 100644 bundles/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseAudioBindingConfiguration.java create mode 100644 bundles/org.openhab.binding.pulseaudio/src/main/java/org/openhab/binding/pulseaudio/internal/PulseAudioBindingConfigurationListener.java diff --git a/bundles/org.openhab.binding.pulseaudio/README.md b/bundles/org.openhab.binding.pulseaudio/README.md index 571c82dc6ad87..2c8a4aa5f3e66 100644 --- a/bundles/org.openhab.binding.pulseaudio/README.md +++ b/bundles/org.openhab.binding.pulseaudio/README.md @@ -18,6 +18,24 @@ You need a running pulseaudio server with module **module-cli-protocol-tcp** loa The Pulseaudio bridge is discovered through mDNS in the local network. +## Binding Configuration (optional) + +The Pulseaudio binding can be customized to handle different devices. The Sink support is activated by default and you need no further action to use it. If you want to use another type of device, or disable the Sink type, you have to switch the corresponding binding property. + +- **sink:** Allow the binding to parse sink devices from the pulseaudio server +- **source:** Allow the binding to parse source devices from the pulseaudio server +- **sinkInput:** Allow the binding to parse sink-input devices from the pulseaudio server +- **sourceOutput:** Allow the binding to parse source-output devices from the pulseaudio server + +You can use the GUI on the bindings page (click on the pulseaudio binding then "Expand for details"), or create a `/services/pulseaudio.cfg` file and use the above options like this: + +``` +binding.pulseaudio:sink=true +binding.pulseaudio:source=false +binding.pulseaudio:sinkInput=false +binding.pulseaudio:sourceOutput=false +``` + ## Thing Configuration The Pulseaudio bridge requires the host (ip address or a hostname) and a port (default: 4712) as a configuration value in order for the binding to know where to access it. @@ -42,17 +60,20 @@ Use the appropriate parameter in the sink thing to activate this possibility (ac This requires the module **module-simple-protocol-tcp** to be present on the server which runs your openHAB instance. The binding will try to command (if not discovered first) the load of this module on the pulseaudio server. ## Full Example + ### pulseaudio.things + ``` Bridge pulseaudio:bridge: "" @ "" [ host="", port=4712 ] { Things: - Thing sink multiroom "Snapcast" @ "Room" [name="alsa_card.pci-0000_00_1f.3", activateSimpleProtocolSink="true", simpleProtocolSinkPort="4711"] // the name corresponds to `pactl list sinks` output + Thing sink multiroom "Snapcast" @ "Room" [name="alsa_card.pci-0000_00_1f.3", activateSimpleProtocolSink="true", simpleProtocolSinkPort="4711"] // the name corresponds to `pactl list sinks` output Thing source microphone "microphone" @ "Room" [name="alsa_input.pci-0000_00_14.2.analog-stereo"] Thing sink-input openhabTTS "OH-Voice" @ "Room" [name="alsa_output.pci-0000_00_1f.3.hdmi-stereo-extra1"] Thing source-output remotePulseSink "Other Room Speaker" @ "Other Room" [name="alsa_input.pci-0000_00_14.2.analog-stereo"] Thing combined-sink hdmiAndAnalog "Zone 1+2" @ "Room" [name="combined"] } ``` +