- if [[ ($line == =*) && ($line =~ IPv4[[:space:]](.+)[[:space:]]_elg) ]]; then
- device=$(eval echo "${BASH_REMATCH[1]}") # eval to strip whitespace
- elif [[ $line =~ hostname.+\[(.+)\] ]]; then hostname=${BASH_REMATCH[1]};
- elif [[ $line =~ address.+\[(.+)\] ]]; then ip=${BASH_REMATCH[1]};
- elif [[ $line =~ port.+\[(.+)\] ]]; then port=${BASH_REMATCH[1]};
- elif [[ $line =~ txt.+\[(.+)\] ]]; then
- txt=$(eval echo "${BASH_REMATCH[1]}") # eval to strip single and double quotes
-
- if [[ $txt =~ mf=([^[[:space:]]*]*) ]]; then manufacturer=${BASH_REMATCH[1]}; fi
- if [[ $txt =~ id=([^[[:space:]]*]*) ]]; then mac=${BASH_REMATCH[1]}; fi
- if [[ $txt =~ md=.+[[:space:]]([^[[:space:]]*]*)[[:space:]]id= ]]; then sku=${BASH_REMATCH[1]}; fi
-
-
- # Get information from the light
- declare cfg="{}"
- declare url="{}"
- declare info="{}"
- declare light="{}"
- if [[ ! (-z $ip) && ! (-z $port) ]]; then
- url="http://$ip:$port"
- cfg=$(eval "${call} GET ${url}${settings}") > /dev/null
- info=$(eval "${call} GET ${url}${accessory_info}") > /dev/null
- light=$(eval "${call} GET ${url}${devices}") > /dev/null
- fi
- # Store the light as json
- lights["$ip"]=$( jq -n \
- --arg dev "$device" \
- --arg hn "$hostname" \
- --arg ip "$ip" \
- --arg port "$port" \
- --arg mf "$manufacturer" \
- --arg mac "$mac" \
- --arg sku "$sku" \
- --arg url "$url" \
- --argjson light "$light" \
- --argjson cfg "$cfg" \
- --argjson info "$info" \
- '{device: $dev, manufacturer: $mf, hostname: $hn, url: $url, ip: $ip,
- port: $port, mac: $mac, sku: $sku, light: $light, settings: $cfg, info: $info}' )
-
- # Reset for next light
- declare {device,hostname,manufacturer,url,ip,mac,protocol,sku,cfg}="N/A"
- declare port=0
+ device=$(echo "${data[3]}" | sed -e 's/\\032/ /g') # fix avahi output
+ hostname=${data[6]}
+ [[ ${data[7]} =~ fe80 ]] && ipv6=${data[7]} || ipv4=${data[7]}
+ port=${data[8]}
+ txt=$(eval echo "${data[9]}") # eval to strip quotes
+ [[ $txt =~ mf=([^[[:space:]]*]*) ]] && manufacturer=${BASH_REMATCH[1]}
+ [[ $txt =~ id=([^[[:space:]]*]*) ]] && mac=${BASH_REMATCH[1]}
+ [[ $txt =~ md=.+[[:space:]]([^[[:space:]]*]*)[[:space:]]id= ]] && sku=${BASH_REMATCH[1]}
+
+ # Get information from the light
+ url="http://$ipv4:$port"
+
+ declare protocol="--ipv4"
+ if [[ $ipv4 == "N/A" ]]; then
+ # Workaround: Ignoring ipv6 as Elgato miss-announces addressing and is not accepting requests
+ # properly for v6. Will not change to filter only on ipv4 from avahi, as that can cause us to only end
+ # up with an ipv6 address even though it was announced as ipv4, which in turn means we cannot communicate.
+ continue
+ # Remove above and uncomment below if a future update fixes ipv6 announcement and requests
+ #protocol="--ipv6"
+ #url="http://[$ip]:$port"