Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created January 20, 2023 19:07
Show Gist options
  • Save kopiro/161630e5508b449ff7f864ff6acd8a92 to your computer and use it in GitHub Desktop.
Save kopiro/161630e5508b449ff7f864ff6acd8a92 to your computer and use it in GitHub Desktop.

Revisions

  1. kopiro created this gist Jan 20, 2023.
    52 changes: 52 additions & 0 deletions tv-hyperhdr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/bin/bash

    IP="192.168.0.45"
    MAC="AA-BB-CC-DD-EE-FF"

    get_status() {
    /usr/bin/curl -s "http://$IP:8090/json-rpc?request=%7B%22command%22:%22serverinfo%22%7D"
    }

    call_autostart() {
    /usr/local/bin/webostv luna-message "$IP" "$MAC" luna://org.webosbrew.hbchannel.service/autostart '{}'
    }

    ensure_autostarted() {
    if ! get_status; then
    retries=0
    call_autostart

    while ! get_status; do
    sleep 2
    retries=$((retries+1))
    if [ $retries -gt 5 ]; then
    echo "Timeout"
    exit 1
    fi
    done
    fi
    }

    if [ "$1" = "on" ]; then


    ensure_autostarted
    /usr/bin/curl "http://$IP:8090/json-rpc?request=%7B%22command%22:%22componentstate%22,%22componentstate%22:%7B%22component%22:%22LEDDEVICE%22,%22state%22:true%7D%7D"


    elif [ "$1" = "off" ]; then

    ensure_autostarted
    /usr/bin/curl "http://$IP:8090/json-rpc?request=%7B%22command%22:%22componentstate%22,%22componentstate%22:%7B%22component%22:%22LEDDEVICE%22,%22state%22:false%7D%7D"

    elif [ "$1" = "status" ]; then

    if get_status | jq '.info.components[] | select(.name=="LEDDEVICE") | .enabled' | grep -i 'true'; then
    echo "HyperHDR is on"
    exit 0
    else
    echo "HyperHDR is off"
    exit 1
    fi

    fi