-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix integration test / Docker Compose env
The Homeassistant setup needs updating for newer version. This allows for a basic instance of HASS to be run via docker compose, and then for wifi-presence to send events to it via MQTT.
- Loading branch information
Showing
4 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
.PHONY: | ||
.PHONY: test | ||
test: | ||
go test -race ../... | ||
go test . ../internal/presence ../internal/hass -race -v -mqttAddr "tcp://localhost:1883" | ||
go test \ | ||
-race \ | ||
../... | ||
go test \ | ||
. \ | ||
../internal/presence \ | ||
../internal/hass \ | ||
-race \ | ||
-v \ | ||
-mqttAddr "tcp://localhost:1883" | ||
|
||
.PHONY: wifi-presence | ||
wifi-presence: | ||
go run ../cmd/wifi-presence \ | ||
-apName="test-AP" \ | ||
-debounce="2s" \ | ||
-hass.autodiscovery=true \ | ||
-mqtt.addr="tcp://localhost:1883" \ | ||
-hostapd.socks="./hostapd.sock" \ | ||
-verbose | ||
|
||
.PHONY: hostap-ctrl | ||
hostap-ctrl: | ||
go run ./hostap-ctrl | ||
|
||
.PHONY: send-cfg | ||
send-cfg: | ||
echo '{"devices":[{"name":"test-phone","mac":"BE:EF:00:00:FA:CE"}]}' \ | ||
| mosquitto_pub \ | ||
-h 'localhost' \ | ||
-t 'wifi-presence/config' \ | ||
-l | ||
|
||
.PHONY: send-empty-cfg | ||
send-empty-cfg: | ||
echo '{"devices":[]}' \ | ||
| mosquitto_pub \ | ||
-h 'localhost' \ | ||
-t 'wifi-presence/config' \ | ||
-l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# This script configures a fresh instance of HASS running | ||
# as part of the associated Docker Compose environment. | ||
|
||
set -e | ||
|
||
HAURL="http://localhost:8123" | ||
|
||
HANAME="admin" | ||
HAUSER="${HANAME}" | ||
HAPASSWORD="${HANAME}" | ||
|
||
# Create temporary directory which is deleted on exit. | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
TMPDIR=`mktemp -d -p "$DIR"` | ||
function cleanup { | ||
rm -rf "${TMPDIR}" | ||
} | ||
trap cleanup EXIT | ||
|
||
curl "${HAURL}/api/onboarding/users" \ | ||
--silent \ | ||
-H 'Content-Type: text/plain;charset=UTF-8' \ | ||
--data-binary "{\"client_id\":\"${HAURL}\",\"name\":\"${HANAME}\",\"username\":\"${HAUSER}\",\"password\":\"${HAPASSWORD}\",\"language\":\"en\"}" \ | ||
--output - \ | ||
| jq -r '.auth_code' > "${TMPDIR}/auth_code" | ||
|
||
curl "${HAURL}/auth/token" \ | ||
--silent \ | ||
-X 'POST' \ | ||
-F "client_id=${HAURL}" \ | ||
-F "code=$(cat "${TMPDIR}/auth_code")" \ | ||
-F 'grant_type=authorization_code' \ | ||
--output - \ | ||
| jq -r '.access_token' > "${TMPDIR}/access_token" | ||
|
||
curl "${HAURL}/api/onboarding/core_config" \ | ||
--silent \ | ||
-X 'POST' \ | ||
-H "Authorization: Bearer $(cat "${TMPDIR}/access_token")" \ | ||
-o /dev/null | ||
|
||
curl "${HAURL}/api/onboarding/analytics" \ | ||
--silent \ | ||
-X 'POST' \ | ||
-H "Authorization: Bearer $(cat "${TMPDIR}/access_token")" \ | ||
-o /dev/null | ||
|
||
curl "${HAURL}/api/onboarding/integration" \ | ||
--silent \ | ||
-H 'Content-Type: application/json;charset=UTF-8' \ | ||
-H "Authorization: Bearer $(cat "${TMPDIR}/access_token")" \ | ||
--data-binary "{\"client_id\":\"${HAURL}\",\"redirect_uri\":\"${HAURL}/?auth_callback=1\"}" \ | ||
-o /dev/null | ||
|
||
# Configure MQTT integration. | ||
|
||
curl "${HAURL}/api/config/config_entries/flow" \ | ||
--silent \ | ||
-X 'POST' \ | ||
-H 'Content-Type: application/json;charset=UTF-8' \ | ||
-H "Authorization: Bearer $(cat "${TMPDIR}/access_token")" \ | ||
--data-binary '{"handler":"mqtt","show_advanced_options":false}' \ | ||
--output - \ | ||
| jq -r '.flow_id' > "${TMPDIR}/flow_id" | ||
|
||
curl "${HAURL}/api/config/config_entries/flow/$(cat "${TMPDIR}/flow_id")" \ | ||
--silent \ | ||
-X 'POST' \ | ||
-H 'Content-Type: application/json;charset=UTF-8' \ | ||
-H "Authorization: Bearer $(cat "${TMPDIR}/access_token")" \ | ||
--data-binary '{"broker":"mosquitto","port":1883}' \ | ||
-o /dev/null | ||
|
||
echo "Created user '${HAUSER}'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters