From 67610c7b282ff2b45b2b39d6713890abef38e463 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 4 Feb 2022 22:01:08 +0100 Subject: [PATCH] write volume to volume cache when volume is changed --- alexa_remote_control.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/alexa_remote_control.sh b/alexa_remote_control.sh index 6da2c8a..2e8a589 100755 --- a/alexa_remote_control.sh +++ b/alexa_remote_control.sh @@ -77,6 +77,7 @@ # 2021-11-16: v0.20c fixed AlexaApp device selection: since they're all called "This Device" use corresponding # line in /tmp/.alexa.devicelist.txt, e.g.: -d "This Device=A2TF17PFR55MTB=ce0123456789abcdef01=VOX" # -lastalexa now returns this string. Make sure to put the device in double quotes! +# 2022-02-04: v0.20d minor volume fix (write volume to volume cache when volume is changed) # ### # @@ -247,7 +248,7 @@ usage() while [ "$#" -gt 0 ] ; do case "$1" in --version) - echo "v0.20c" + echo "v0.20d" exit 0 ;; -d) @@ -776,9 +777,18 @@ if [ -n "${SEQUENCECMD}" ] ; then DEVICETYPE=$(grep "${DEVICESERIALNUMBER}" ${DEVLIST}.txt | cut -d'=' -f 2) NODESTOEXECUTE=$(add_node "$(node)" "${NODESTOEXECUTE}") + # if SequenceCommand is "Alexa.DeviceControls.Volume" we have to adjust the local volume cache + if [ "$SEQUENCECMD" = "Alexa.DeviceControls.Volume" ] ; then + VOL=${SEQUENCEVAL%\\\"} + VOL=${VOL##*\\\"} + if [ $VOL -gt 0 ] ; then + echo $VOL false > "${TMP}/.alexa.volume.${DEVICESERIALNUMBER}" + else + echo 0 true > "${TMP}/.alexa.volume.${DEVICESERIALNUMBER}" + fi # add volume setting per device - the WHA volume is unrelyable # don't set volume if Alexa.Music.PlaySearchPhrase is used - if [ \( $SPEAKVOL -gt 0 -o -n "${DEVICEVOLSPEAK}" \) -a "${SEQUENCECMD}" != "Alexa.Music.PlaySearchPhrase" ] ; then + elif [ \( $SPEAKVOL -gt 0 -o -n "${DEVICEVOLSPEAK}" \) -a "${SEQUENCECMD}" != "Alexa.Music.PlaySearchPhrase" ] ; then DEVICE=$(grep "${DEVICESERIALNUMBER}" ${DEVLIST}.txt | cut -d'=' -f 1) get_volumes VOLUMEPRENODESTOEXECUTE=$(add_node $(node Alexa.DeviceControls.Volume ',\"value\":\"'${SVOL}'\"') ${VOLUMEPRENODESTOEXECUTE}) @@ -793,8 +803,16 @@ if [ -n "${SEQUENCECMD}" ] ; then else NODESTOEXECUTE=$(add_node "$(node)" "${NODESTOEXECUTE}") + if [ "$SEQUENCECMD" = "Alexa.DeviceControls.Volume" ] ; then + VOL=${SEQUENCEVAL%\\\"} + VOL=${VOL##*\\\"} + if [ $VOL -gt 0 ] ; then + echo $VOL false > "${TMP}/.alexa.volume.${DEVICESERIALNUMBER}" + else + echo 0 true > "${TMP}/.alexa.volume.${DEVICESERIALNUMBER}" + fi # don't set volume if Alexa.Music.PlaySearchPhrase is used - if [ \( $SPEAKVOL -gt 0 -o -n "${DEVICEVOLSPEAK}" \) -a "${SEQUENCECMD}" != "Alexa.Music.PlaySearchPhrase" ] ; then + elif [ \( $SPEAKVOL -gt 0 -o -n "${DEVICEVOLSPEAK}" \) -a "${SEQUENCECMD}" != "Alexa.Music.PlaySearchPhrase" ] ; then get_volumes VOLUMEPRENODESTOEXECUTE=$(add_node $(node Alexa.DeviceControls.Volume ',\"value\":\"'${SVOL}'\"') ${VOLUMEPRENODESTOEXECUTE}) VOLUMEPOSTNODESTOEXECUTE=$(add_node $(node Alexa.DeviceControls.Volume ',\"value\":\"'${VOL}'\"') ${VOLUMEPOSTNODESTOEXECUTE})