tasmota: refactor to remove all the duplicated code in switch&dimmer
This commit is contained in:
parent
a1e013892e
commit
dde29e9982
|
@ -283,35 +283,25 @@ switch() {
|
|||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title Tasmota Switch: $DEVICE"
|
||||
echo "graph_args --base 1000 -l 0"
|
||||
fi
|
||||
|
||||
for v in POWER POWER{1,2,3,4,5,6,7,8,9} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
for v in POWER POWER{1,2,3,4,5,6,7,8,9} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "$axis.label $lab"
|
||||
echo "$axis.type GAUGE"
|
||||
echo "$axis.min 0"
|
||||
fi
|
||||
done
|
||||
else
|
||||
for v in POWER POWER{1,2,3,4,5,6,7,8,9} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
|
||||
else
|
||||
case "$res" in
|
||||
ON)
|
||||
res=1
|
||||
|
@ -326,50 +316,41 @@ switch() {
|
|||
|
||||
echo "$axis.value $res"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
dimmer() {
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title Tasmota Dimmer: $DEVICE"
|
||||
echo "graph_args --base 1000 -l 0"
|
||||
fi
|
||||
|
||||
for v in Channel{1,2,3,4} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
for v in Channel{1,2,3,4} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "$axis.label $lab"
|
||||
echo "$axis.type GAUGE"
|
||||
echo "$axis.min 0"
|
||||
fi
|
||||
done
|
||||
else
|
||||
for v in Channel{1,2,3,4} ; do
|
||||
axis=$( echo "$v" | cut -d= -f 1 )
|
||||
lab=$( echo "$v" | cut -d= -f 2 )
|
||||
get_status 11 ".StatusSTS.$v"
|
||||
if [ "$res" != U ] || [ -e $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen ] ; then
|
||||
# if we've ever seen an axis, then we want to keep
|
||||
# telling munin we are capable of reading that axis,
|
||||
# even if the device is currently unpowered
|
||||
mkdir -p $MUNIN_PLUGSTATE/tasmota
|
||||
touch $MUNIN_PLUGSTATE/tasmota/$DEVICE.$FUNCTION.$v.seen
|
||||
|
||||
else
|
||||
if [ "$res" = U ] ; then
|
||||
res=0 # assume 0 power, since if it doesn't have power to get wifi, then it's not going to have power output
|
||||
fi
|
||||
|
||||
echo "$axis.value $res"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
case "$FUNCTION" in
|
||||
|
|
Loading…
Reference in New Issue