Skip to content

Commit ef61d12

Browse files
committed
[logging] adjust msg & enable debug log
1 parent 263c086 commit ef61d12

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

tesla_ble_mqtt/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
WARNING: broken for standalone deployment, stay on 0.0.6
88
OK for HA Addon
99

10-
- logging adjustment and fix debug
10+
- logging msg adjustments & fix logic for log.debug
11+
- logging add logic for log.debug to properly work
1112

1213
## 0.0.7
1314

tesla_ble_mqtt/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Tesla Local Commands"
2-
version: "0.0.7"
2+
version: "0.0.7a"
33
slug: "tesla_local_commands"
44
description: "Local BLE calls to control your Tesla."
55
# url: "tbc"

tesla_ble_mqtt/rootfs/app/run.sh

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ send_key() {
6464
EXIT_STATUS=$?
6565
set -e
6666
if [ $EXIT_STATUS -eq 0 ]; then
67-
bashio::log.yellow "KEY SENT TO VEHICLE: PLEASE CHECK YOU TESLA'S SCREEN AND ACCEPT WITH YOUR CARD"
67+
bashio::log.notice "KEY SENT TO VEHICLE: PLEASE CHECK YOU TESLA'S SCREEN AND ACCEPT WITH YOUR CARD"
6868
break
6969
else
7070
bashio::log.error "tesla-control could not send the pubkey; make sure the car is awake and sufficiently close to the bluetooth device. Retrying in $SEND_CMD_RETRY_DELAY"
@@ -74,33 +74,23 @@ send_key() {
7474
}
7575

7676
listen_to_ble() {
77-
PRESENCE_TIMEOUT=5
7877
bashio::log.info "Listening to BLE for presence"
78+
PRESENCE_TIMEOUT=5
7979
set +e
80-
if [ $? -eq 0 ]; then
81-
bashio::log.green "$BLE_MAC presence detected"
82-
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/bin
83-
ry_sensor/presence -m ON
84-
else
85-
bashio::log.yellow "$BLE_MAC presence not detected or issue in command, retrying now"
86-
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/bin
87-
ary_sensor/presence -m OFF
88-
fi
89-
9080
bluetoothctl --timeout $PRESENCE_TIMEOUT scan on | grep $BLE_MAC
9181
EXIT_STATUS=$?
9282
set -e
93-
bashio::log.info "$BLE_MAC presence detected"
94-
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/binary_sensor/presence -m ON
95-
96-
bashio::log.warning "$BLE_MAC presence not detected or issue in command, will retry later"
97-
bashio::log.info "Updating topic tesla_ble/binary_sensor/presence OFF"
98-
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/binary_sensor/presence -m OFF
99-
bashio::log.debug "Topic tesla_ble/binary_sensor/presence already OFF"
83+
if [ $EXIT_STATUS -eq 0 ]; then
84+
bashio::log.info "$BLE_MAC presence detected"
85+
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/binary_sensor/presence -m ON
86+
else
87+
bashio::log.notice "$BLE_MAC presence not detected or issue in command"
88+
mosquitto_pub --nodelay -h $MQTT_IP -p $MQTT_PORT -u "$MQTT_USER" -P "$MQTT_PWD" -t tesla_ble/binary_sensor/presence -m OFF
10089
fi
90+
10191
}
10292

103-
bashio::log.yellow "Sourcing functions"
93+
bashio::log.notice "Sourcing functions"
10494
. /app/listen_to_mqtt.sh
10595
. /app/discovery.sh
10696

@@ -110,27 +100,18 @@ setup_auto_discovery
110100
bashio::log.info "Connecting to MQTT to discard any unread messages"
111101
mosquitto_sub -E -i tesla_ble_mqtt -h $MQTT_IP -p $MQTT_PORT -u $MQTT_USER -P $MQTT_PWD -t tesla_ble/+
112102

113-
if [ -z "$BLE_MAC" ]; then
114-
bashio::log.notice "BLE_MAC being undefined, presence detection for the car will not run"
115-
counter=-1
116-
bashio::log.info "Entering main MQTT loop"
117-
else
118-
bashio::log.info "BLE_MAC is defined, initializing BLE listening loop counter"
119-
bashio::log.info "Entering main MQTT & BLE listening loop"
120-
counter=0
121-
fi
122-
103+
bashio::log.info "Initialize BLE listening loop counter"
104+
counter=0
105+
bashio::log.info "Entering main MQTT & BLE listening loop"
123106
while true
124107
do
125108
set +e
126109
listen_to_mqtt
127-
if [ $counter -ge 0 ]; then
128-
((counter++))
129-
if [[ $counter -gt 90 ]]; then
130-
bashio::log.info "Reached 90 MQTT loops (~3min): Launch BLE scanning for car presence"
131-
listen_to_ble
132-
counter=0
133-
fi
110+
((counter++))
111+
if [[ $counter -gt 90 ]]; then
112+
bashio::log.info "Reached 90 MQTT loops (~3min): Launch BLE scanning for car presence"
113+
listen_to_ble
114+
counter=0
134115
fi
135116
sleep 2
136117
done

0 commit comments

Comments
 (0)