-
Notifications
You must be signed in to change notification settings - Fork 11
/
test-shell.sh
executable file
·116 lines (105 loc) · 3.27 KB
/
test-shell.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# This script helps during development to test certain aspects of the wattpilot shell.
if [ -f dev.env ]; then
source dev.env
fi
export PYTHONPATH=src
WPCONFIG_FILE="src/wattpilot/ressources/wattpilot.yaml"
cmd="${1:-default}"
shift 1
function runShell() {
python -m wattpilot.wattpilotshell "${@}"
}
function runShellOnly() {
WATTPILOT_AUTOCONNECT=false MQTT_ENABLED=false HA_ENABLED=false WATTPILOT_LOGLEVEL=WARN runShell "${@}"
}
function runShellWithProps() {
PROPS="${1:-}"
echo "Enabled properties: ${PROPS}"
MQTT_ENABLED=true HA_ENABLED=true MQTT_PROPERTIES="${PROPS}" HA_PROPERTIES="${PROPS}" runShell
}
function runShellWithAllProps() {
PROP_FILTER="${1:-.*}"
PROPS=$(gojq --yaml-input -r -c '.properties[] | (.key, .childProps?[]?.key?)' "${WPCONFIG_FILE}" | grep "^${PROP_FILTER}" | xargs echo)
runShellWithProps "${PROPS}"
}
case "${cmd}" in
default)
runShell "${@}"
;;
shell-only)
runShellOnly "${@}"
;;
server)
WATTPILOT_AUTOCONNECT=true MQTT_ENABLED=true HA_ENABLED=true runShell "server"
;;
save)
logfile=work/status-$(date +"%Y-%m-%d_%H-%M-%S")-${1:-adhoc}.log
mkdir -p work
WATTPILOT_LOGLEVEL=WARNING MQTT_ENABLED=false HA_ENABLED=false runShell "values" >>${logfile} 2>&1
WATTPILOT_LOGLEVEL=WARNING MQTT_ENABLED=false HA_ENABLED=false runShell "rawvalues" >>${logfile} 2>&1
WATTPILOT_LOGLEVEL=WARNING MQTT_ENABLED=false HA_ENABLED=false runShell "properties" >>${logfile} 2>&1
;;
ha)
runShellWithProps
;;
ha-all)
runShellWithAllProps
;;
ha-test-props)
runShellWithProps "alw loe nrg fhz spl3 acu ama cdi ffna fna"
;;
ha-test-array)
runShellWithProps "nrg"
;;
ha-test-boolean)
runShellWithProps "alw loe"
;;
ha-test-float)
runShellWithProps "fhz spl3"
;;
ha-test-integer)
runShellWithProps "acu ama"
;;
ha-test-object)
runShellWithProps "cdi"
;;
ha-test-string)
runShellWithProps "ffna fna"
;;
update-docs)
python gen-apidocs.py >API.md
(
echo "# Wattpilot Shell Commands"
for cmd in $(
runShellOnly "help" \
| grep -v -E '^(===+|.*:)$' \
| xargs -n 1 echo \
| grep -E -v '^EOF$' \
| sort \
); do
echo ""
echo "## ${cmd}"
echo ""
echo "\`\`\`bash"
runShellOnly "help ${cmd}"
echo "\`\`\`"
done
) >ShellCommands.md
(
echo "# Wattpilot Shell Environment Variables"
echo ""
runShellOnly docs
) >ShellEnvVariables.md
;;
validate-yaml)
echo -n "Properties with missing mandatory fields: "
gojq --yaml-input -c '[.properties[],.childProps[]? | select(.key==null or .jsonType==null)]' <"${WPCONFIG_FILE}"
echo -n "Child properties with missing jsonType: "
gojq --yaml-input -c '[.properties[] | . as $ppd | .childProps[]? | . as $cpd | select(.jsonType==null and $ppd.itemType==null) | .key]' <"${WPCONFIG_FILE}"
;;
*)
echo "Unknown command: ${cmd}"
exit 1
;;
esac