diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1618757b..b630c13e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,10 @@ jobs: run: meson setup ${{github.workspace}}/build - name: Build run: meson compile -C ${{github.workspace}}/build + - name: start HA in the background + run: scripts/background-ha.sh + - name: test client-cli + run: LD_LIBRARY_PATH=./build/subprojects/curl-8.5.0/build/lib/.libs/ HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN=$(cat scripts/docker/longtoken.txt) build/client-cli list-entities - uses: actions/upload-artifact@v4 with: name: ubuntu-build diff --git a/scripts/background-ha.sh b/scripts/background-ha.sh new file mode 100755 index 00000000..43864bc6 --- /dev/null +++ b/scripts/background-ha.sh @@ -0,0 +1,12 @@ +#!/bin/sh -x + +# FIXME: this started as a copy of tmux.sh, and we should see if we can unify them + +PWD=`pwd` +ROOT=`dirname $0`/.. + +docker pull ghcr.io/home-assistant/home-assistant:stable + +cp -r ${ROOT}/scripts/docker/config ${ROOT}/scripts/docker/ha-config +( cd ${ROOT}/scripts/docker && docker-compose up -d ) +( cd ${ROOT}/scripts/docker && ./register.sh ) diff --git a/scripts/docker/docker-compose.yaml b/scripts/docker/docker-compose.yaml index dc39b749..bd231487 100644 --- a/scripts/docker/docker-compose.yaml +++ b/scripts/docker/docker-compose.yaml @@ -8,4 +8,6 @@ services: - /etc/localtime:/etc/localtime:ro # restart: unless-stopped privileged: true - network_mode: host +# network_mode: host + ports: + - 8123:8123 diff --git a/scripts/docker/register.sh b/scripts/docker/register.sh index f8f36583..7a63f777 100755 --- a/scripts/docker/register.sh +++ b/scripts/docker/register.sh @@ -1,10 +1,10 @@ #!/bin/sh CHECK_COUNT=0 -curl -s 'http://localhost:8123/' 1>/dev/null +curl -s 'http://0.0.0.0:8123/' 1>/dev/null while [ $? -ne 0 ] do - if [ $CHECK_COUNT -gt 10 ]; then + if [ $CHECK_COUNT -gt 15 ]; then echo "HA doesn't seem to be started after a while, giving up." exit 1 fi @@ -14,41 +14,41 @@ do CHECK_COUNT=$((CHECK_COUNT+1)) # Keep on the last line because of exit status check - curl -s 'http://localhost:8123' 1>/dev/null + curl -s 'http://0.0.0.0:8123' 1>/dev/null done # Create voorkant user -curl 'http://localhost:8123/api/onboarding/users' -s -X POST --data-raw '{"client_id":"http://localhost:8123/","name":"voorkant","username":"voorkant","password":"v00rk4nt","language":"en-GB"}' > auth_code.json +curl 'http://0.0.0.0:8123/api/onboarding/users' -s -X POST --data-raw '{"client_id":"http://0.0.0.0:8123/","name":"voorkant","username":"voorkant","password":"v00rk4nt","language":"en-GB"}' > auth_code.json MSG=`jq -r '.message' auth_code.json` if [ "${MSG}" != "User step already done" ]; then CODE=`jq -r '.auth_code' auth_code.json` - curl 'http://localhost:8123/auth/token' -s -X POST -F "grant_type=authorization_code" -F "code=${CODE}" -F "client_id=http://localhost:8123/" > token.json + curl 'http://0.0.0.0:8123/auth/token' -s -X POST -F "grant_type=authorization_code" -F "code=${CODE}" -F "client_id=http://0.0.0.0:8123/" > token.json TOKEN=`jq -r '.access_token' token.json` # To complete setup, you have to set some other stuff. For whatever reason (might be because demo mode) these requests are empty in our capture. - curl 'http://localhost:8123/api/onboarding/core_config' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null - curl 'http://localhost:8123/api/onboarding/analytics' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null - curl 'http://localhost:8123/api/onboarding/integration' -s -X POST -H "authorization: Bearer ${TOKEN}" -d '{"client_id":"http://localhost:8123/","redirect_uri":"http://localhost:8123/?auth_callback=1"}' > /dev/null + curl 'http://0.0.0.0:8123/api/onboarding/core_config' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null + curl 'http://0.0.0.0:8123/api/onboarding/analytics' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null + curl 'http://0.0.0.0:8123/api/onboarding/integration' -s -X POST -H "authorization: Bearer ${TOKEN}" -d '{"client_id":"http://0.0.0.0:8123/","redirect_uri":"http://0.0.0.0:8123/?auth_callback=1"}' > /dev/null rm auth_code.json rm token.json if [ -x "../../build/client-cli" ] then - HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="${TOKEN}" LD_LIBRARY_PATH=../../build/subprojects/curl-8.5.0/build/lib/.libs/ ../../build/client-cli ha-get-token 2>register.log 1>longtoken.txt + HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="${TOKEN}" LD_LIBRARY_PATH=../../build/subprojects/curl-8.5.0/build/lib/.libs/ ../../build/client-cli ha-get-token 2>register.log 1>longtoken.txt echo "Providing long lived token" - echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`" + echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`" else echo "WARNING - could not find build/client-cli. Providing SHORT lived token" - echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="${TOKEN}" + echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="${TOKEN}" fi else if [ -e "longtoken.txt" ] then echo "Registration in HA was already completed, but found old long lived token." - echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`" + echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`" else echo "Registration in HA has already been completed, can't provide a token." - echo HA_WS_URL=ws://localhost:8123/api/websocket + echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket fi fi diff --git a/src/main.cpp b/src/main.cpp index f6030722..30de783e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,5 +44,8 @@ int main(int argc, char* argv[]) // running the uithread in the main thread makes LVGL/SDL work on macOS uithread(backend, argc, argv); + return 0; } + + return 1; }