PR #68 from martinweu/master

Add query notifications
This commit is contained in:
Alex 2019-11-18 13:50:50 +01:00 committed by GitHub
commit 9ab7dadd34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 3 deletions

View File

@ -24,7 +24,7 @@ export LANGUAGE='de,en-US;q=0.7,en;q=0.3'
```
alexa-remote-control [-d <device>|ALL] -e <pause|play|next|prev|fwd|rwd|shuffle|repeat|vol:<0-100>> |
-b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -r <"station name"|stationid> |
-b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -n | -r <"station name"|stationid> |
-s <trackID|'Artist' 'Album'> | -t <ASIN> | -u <seedID> | -v <queueID> |
-w <playlistId> | -i | -p | -P | -S | -a | -l | -h |
-m <multiroom_device> [device_1 .. device_X] | -lastalexa
@ -34,6 +34,7 @@ alexa-remote-control [-d <device>|ALL] -e <pause|play|next|prev|fwd|rwd|shuffle|
speak:'<text>',automation:'<routine name>'
-b : connect/disconnect/list bluetooth device
-q : query queue
-n : query notifications
-r : play tunein radio
-s : play library track/library album
-t : play Prime playlist

View File

@ -156,6 +156,7 @@ usage()
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>',automation:'<routine name>'"
echo " -b : connect/disconnect/list bluetooth device"
echo " -q : query queue"
echo " -n : query notifications"
echo " -r : play tunein radio"
echo " -s : play library track/library album"
echo " -t : play Prime playlist"
@ -303,6 +304,9 @@ while [ "$#" -gt 0 ] ; do
-q)
QUEUE="true"
;;
-n)
NOTIFICATIONS="true"
;;
-lastalexa)
LASTALEXA="true"
;;
@ -772,6 +776,19 @@ show_queue()
"https://${ALEXA}/api/np/queue?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" | jq '.'
}
#
# show notifications and alarms
#
show_notifications()
{
echo "/api/notifications"
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
-H "csrf: $(awk "\$0 ~/.${AMAZON}.*csrf[ \\s\\t]+/ {print \$7}" ${COOKIE})" -X GET \
"https://${ALEXA}/api/notifications?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}"
echo
}
#
# deletes a multiroom device
#
@ -861,7 +878,7 @@ rm -f ${COOKIE}
rm -f ${TMP}/.alexa.*.list
}
if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$PRIME" -a -z "$TYPE" -a -z "$QUEUE" -a -z "$LIST" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then
if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$PRIME" -a -z "$TYPE" -a -z "$QUEUE" -a -z "$NOTIFICATIONS" -a -z "$LIST" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then
echo "only logout option present, logging off ..."
log_off
exit 0
@ -920,6 +937,34 @@ if [ -n "$COMMAND" -o -n "$QUEUE" ] ; then
echo
fi
fi
elif [ -n "$COMMAND" -o -n "$NOTIFICATIONS" ] ; then
if [ "${DEVICE}" = "ALL" ] ; then
while IFS= read -r DEVICE ; do
set_var
if [ -n "$COMMAND" ] ; then
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
run_cmd
# in order to prevent a "Rate exceeded" we need to delay the command
sleep 1
echo
else
echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
show_notifications
echo
fi
done < ${DEVALL}
else
set_var
if [ -n "$COMMAND" ] ; then
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
run_cmd
echo
else
echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
show_notifications
echo
fi
fi
elif [ -n "$LEMUR" ] ; then
DEVICESERIALNUMBER=$(jq --arg device "${LEMUR}" -r '.devices[] | select(.accountName == $device and .deviceFamily == "WHA") | .serialNumber' ${DEVLIST})
if [ -n "$DEVICESERIALNUMBER" ] ; then

View File

@ -114,6 +114,7 @@ usage()
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>'"
echo " -b : connect/disconnect/list bluetooth device"
echo " -q : query queue"
echo " -n : query notifications"
echo " -r : play tunein radio"
echo " -s : play library track/library album"
echo " -t : play Prime playlist"
@ -245,6 +246,9 @@ while [ "$#" -gt 0 ] ; do
-q)
QUEUE="true"
;;
-n)
NOTIFICATIONS="true"
;;
-lastalexa)
LASTALEXA="true"
;;
@ -709,6 +713,19 @@ ${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep
echo
}
#
# show notifications and alarms
#
show_notifications()
{
echo "/api/notifications"
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
-H "csrf: $(awk "\$0 ~/.${AMAZON}.*csrf[ \\s\\t]+/ {print \$7}" ${COOKIE})" -X GET \
"https://${ALEXA}/api/notifications?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}"
echo
}
#
# deletes a multiroom device
#
@ -797,7 +814,7 @@ rm -f ${DEVALL}
rm -f ${COOKIE}
}
if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$QUEUE" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then
if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$QUEUE" -a -z "$NOTIFICATIONS" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then
echo "only logout option present, logging off ..."
log_off
exit 0
@ -856,6 +873,34 @@ if [ -n "$COMMAND" -o -n "$QUEUE" ] ; then
echo
fi
fi
elif [ -n "$COMMAND" -o -n "$NOTIFICATIONS" ] ; then
if [ "${DEVICE}" = "ALL" ] ; then
while IFS= read -r DEVICE ; do
set_var
if [ -n "$COMMAND" ] ; then
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
run_cmd
# in order to prevent a "Rate exceeded" we need to delay the command
sleep 1
echo
else
echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
show_notifications
echo
fi
done < ${DEVALL}
else
set_var
if [ -n "$COMMAND" ] ; then
echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}"
run_cmd
echo
else
echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}"
show_notifications
echo
fi
fi
elif [ -n "$LEMUR" ] ; then
DEVICE="${LEMUR}"
set_var