Skip to content

Commit ffec57e

Browse files
authored
[feat] Info Bluetooth Adapter (#88) (#90)
1 parent 1f973ff commit ffec57e

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

mqtt-discovery.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function setupHADeviceControlsCard() {
104104
"payload_press": "wake",
105105
"qos": "'${QOS_LEVEL}'",
106106
"unique_id": "'${DEV_ID}'_wake"
107-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/wake/config -l
107+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/wake/config -l
108108

109109
echo '{
110110
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -121,7 +121,7 @@ function setupHADeviceControlsCard() {
121121
"payload_press": "flash-lights",
122122
"qos": "'${QOS_LEVEL}'",
123123
"unique_id": "'${DEV_ID}'_flash-lights"
124-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/flash-lights/config -l
124+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/flash-lights/config -l
125125

126126
echo '{
127127
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -138,7 +138,7 @@ function setupHADeviceControlsCard() {
138138
"payload_press": "honk",
139139
"qos": "'${QOS_LEVEL}'",
140140
"unique_id": "'${DEV_ID}'_honk"
141-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/honk/config -l
141+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/honk/config -l
142142

143143
echo '{
144144
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -155,7 +155,7 @@ function setupHADeviceControlsCard() {
155155
"payload_press": "lock",
156156
"qos": "'${QOS_LEVEL}'",
157157
"unique_id": "'${DEV_ID}'_lock"
158-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/lock/config -l
158+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/lock/config -l
159159

160160
echo '{
161161
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -172,7 +172,7 @@ function setupHADeviceControlsCard() {
172172
"payload_press": "unlock",
173173
"qos": "'${QOS_LEVEL}'",
174174
"unique_id": "'${DEV_ID}'_unlock"
175-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/unlock/config -l
175+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/unlock/config -l
176176

177177
echo '{
178178
"command_topic": "'${TOPIC_ROOT}'/auto-seat-and-climate",
@@ -189,7 +189,7 @@ function setupHADeviceControlsCard() {
189189
"payload_press": "auto-seat-and-climate",
190190
"qos": "'${QOS_LEVEL}'",
191191
"unique_id": "'${DEV_ID}'_auto_seat-climate"
192-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/auto-seat-and-climate/config -l
192+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/auto-seat-and-climate/config -l
193193

194194
echo '{
195195
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -206,7 +206,7 @@ function setupHADeviceControlsCard() {
206206
"payload_press": "climate-off",
207207
"qos": "'${QOS_LEVEL}'",
208208
"unique_id": "'${DEV_ID}'_climate-off"
209-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/climate-off/config -l
209+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/climate-off/config -l
210210

211211
echo '{
212212
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -223,7 +223,7 @@ function setupHADeviceControlsCard() {
223223
"payload_press": "climate-on",
224224
"qos": "'${QOS_LEVEL}'",
225225
"unique_id": "'${DEV_ID}'_climate-on"
226-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/climate-on/config -l
226+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/climate-on/config -l
227227

228228
echo '{
229229
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -240,7 +240,7 @@ function setupHADeviceControlsCard() {
240240
"payload_press": "trunk-open",
241241
"qos": "'${QOS_LEVEL}'",
242242
"unique_id": "'${DEV_ID}'_trunk-open"
243-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/trunk-open/config -l
243+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/trunk-open/config -l
244244

245245
echo '{
246246
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -257,7 +257,7 @@ function setupHADeviceControlsCard() {
257257
"payload_press": "trunk-close",
258258
"qos": "'${QOS_LEVEL}'",
259259
"unique_id": "'${DEV_ID}'_trunk-close"
260-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/trunk-close/config -l
260+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/trunk-close/config -l
261261

262262
echo '{
263263
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -274,7 +274,7 @@ function setupHADeviceControlsCard() {
274274
"payload_press": "frunk-open",
275275
"qos": "'${QOS_LEVEL}'",
276276
"unique_id": "'${DEV_ID}'_frunk-open"
277-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/frunk-open/config -l
277+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/frunk-open/config -l
278278

279279
echo '{
280280
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -291,7 +291,7 @@ function setupHADeviceControlsCard() {
291291
"payload_press": "charging-start",
292292
"qos": "'${QOS_LEVEL}'",
293293
"unique_id": "'${DEV_ID}'_charging-start"
294-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/charging-start/config -l
294+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/charging-start/config -l
295295

296296
echo '{
297297
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -308,7 +308,7 @@ function setupHADeviceControlsCard() {
308308
"payload_press": "charging-stop",
309309
"qos": "'${QOS_LEVEL}'",
310310
"unique_id": "'${DEV_ID}'_charging-stop"
311-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/charging-stop/config -l
311+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/charging-stop/config -l
312312

313313
echo '{
314314
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -325,7 +325,7 @@ function setupHADeviceControlsCard() {
325325
"payload_press": "charge-port-open",
326326
"qos": "'${QOS_LEVEL}'",
327327
"unique_id": "'${DEV_ID}'_charge-port-open"
328-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/charge-port-open/config -l
328+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/charge-port-open/config -l
329329

330330
echo '{
331331
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -342,7 +342,7 @@ function setupHADeviceControlsCard() {
342342
"payload_press": "charge-port-close",
343343
"qos": "'${QOS_LEVEL}'",
344344
"unique_id": "'${DEV_ID}'_charge-port-close"
345-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/charge-port-close/config -l
345+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/charge-port-close/config -l
346346

347347
echo '{
348348
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -359,7 +359,7 @@ function setupHADeviceControlsCard() {
359359
"payload_press": "windows-close",
360360
"qos": "'${QOS_LEVEL}'",
361361
"unique_id": "'${DEV_ID}'_windows-close"
362-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/windows-close/config -l
362+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/windows-close/config -l
363363

364364
echo '{
365365
"command_topic": "'${TOPIC_ROOT}'/command",
@@ -376,7 +376,7 @@ function setupHADeviceControlsCard() {
376376
"payload_press": "windows-vent",
377377
"qos": "'${QOS_LEVEL}'",
378378
"unique_id": "'${DEV_ID}'_windows-vent"
379-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/windows-vent/config -l
379+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/windows-vent/config -l
380380

381381
echo '{
382382
"command_topic": "'${TOPIC_ROOT}'/charging-set-amps",
@@ -397,7 +397,7 @@ function setupHADeviceControlsCard() {
397397
"unit_of_measurement": "A",
398398
"qos": "'${QOS_LEVEL}'",
399399
"icon": "mdi:current-ac"
400-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID}/charging-set-amps/config -l
400+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID}/charging-set-amps/config -l
401401

402402
echo '{
403403
"command_topic": "'${TOPIC_ROOT}'/charging-set-amps-override",
@@ -419,7 +419,7 @@ function setupHADeviceControlsCard() {
419419
"qos": "'${QOS_LEVEL}'",
420420
"icon": "mdi:current-ac",
421421
"entity_category": "diagnostic"
422-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID}/charging-set-amps-override/config -l
422+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID}/charging-set-amps-override/config -l
423423

424424
echo '{
425425
"command_topic": "'${TOPIC_ROOT}'/charging-set-limit",
@@ -440,7 +440,7 @@ function setupHADeviceControlsCard() {
440440
"unit_of_measurement": "%",
441441
"qos": "'${QOS_LEVEL}'",
442442
"icon": "mdi:battery-90"
443-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID}/charging-set-limit/config -l
443+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID}/charging-set-limit/config -l
444444

445445
echo '{
446446
"command_topic": "'${TOPIC_ROOT}'/climate-set-temp",
@@ -461,7 +461,7 @@ function setupHADeviceControlsCard() {
461461
"unit_of_measurement": "°C",
462462
"qos": "'${QOS_LEVEL}'",
463463
"icon": "mdi:temperature"
464-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/number/${DEV_ID}/climate-temp/config -l
464+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/number/${DEV_ID}/climate-temp/config -l
465465

466466
echo '{
467467
"command_topic": "'${TOPIC_ROOT}'/steering-wheel-heater",
@@ -478,7 +478,7 @@ function setupHADeviceControlsCard() {
478478
"device_class": "switch",
479479
"qos": "'${QOS_LEVEL}'",
480480
"unique_id": "'${DEV_ID}'_steering-wheel-heater"
481-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/switch/${DEV_ID}/steering-wheel-heater/config -l
481+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEV_ID}/steering-wheel-heater/config -l
482482

483483
echo '{
484484
"command_topic": "'${TOPIC_ROOT}'/sentry-mode",
@@ -495,7 +495,7 @@ function setupHADeviceControlsCard() {
495495
"device_class": "switch",
496496
"qos": "'${QOS_LEVEL}'",
497497
"unique_id": "'${DEV_ID}'_sentry-mode"
498-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/switch/${DEV_ID}/sentry-mode/config -l
498+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/switch/${DEV_ID}/sentry-mode/config -l
499499

500500
echo '{
501501
"command_topic": "'${TOPIC_ROOT}'/heater-seat-front-left",
@@ -513,7 +513,7 @@ function setupHADeviceControlsCard() {
513513
"qos": "'${QOS_LEVEL}'",
514514
"icon": "mdi:car-seat-heater",
515515
"unique_id": "'${DEV_ID}'_heater-seat-front-left"
516-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/select/${DEV_ID}/heater-seat-front-left/config -l
516+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/select/${DEV_ID}/heater-seat-front-left/config -l
517517

518518
echo '{
519519
"command_topic": "'${TOPIC_ROOT}'/heater-seat-front-right",
@@ -531,7 +531,7 @@ function setupHADeviceControlsCard() {
531531
"qos": "'${QOS_LEVEL}'",
532532
"icon": "mdi:car-seat-heater",
533533
"unique_id": "'${DEV_ID}'_heater-seat-front-right"
534-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/select/${DEV_ID}/heater-seat-front-right/config -l
534+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/select/${DEV_ID}/heater-seat-front-right/config -l
535535

536536
log_debug "Leaving setupHADeviceControlsCard() vin:$vin"
537537
}
@@ -564,7 +564,7 @@ function setupHADeviceGenerateKeysButton() {
564564
"unique_id": "'${DEV_ID}'_generate-keys",
565565
"entity_category": "config",
566566
"sw_version": "'${SW_VERSION}'"
567-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/generate-keys/config -l
567+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/generate-keys/config -l
568568

569569
log_debug "setupHADeviceGenerateKeysButton() leaving vin:$vin"
570570

@@ -631,7 +631,7 @@ function setupHADevicePresenceSensor {
631631
"device_class": "presence",
632632
"name": "Presence",
633633
"unique_id": "'${DEV_ID}'_presence"
634-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/binary_sensor/${DEV_ID}/presence/config -l
634+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 36 10 -t homeassistant/binary_sensor/${DEV_ID}/presence/config -l
635635

636636
log_debug "setupHADevicePresenceSensor() leaving vin:$vin"
637637

@@ -665,7 +665,7 @@ function setupHADeviceDeployKeyButton() {
665665
"qos": "'${QOS_LEVEL}'",
666666
"unique_id": "'${DEV_ID}'_deploy-key",
667667
"entity_category": "config"
668-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/deploy-key/config -l
668+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/deploy-key/config -l
669669

670670
log_debug "setupHADeviceDeployKeyButton() leaving vin:$vin"
671671

@@ -699,7 +699,7 @@ function setupHADeviceInfoBTadapter() {
699699
"qos": "'${QOS_LEVEL}'",
700700
"unique_id": "'${DEV_ID}'_info-bt-adapter",
701701
"entity_category": "diagnostic"
702-
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub -t homeassistant/button/${DEV_ID}/info-bt-adapter/config -l
702+
}' | sed ':a;N;$!ba;s/\n//g' | retryMQTTpub 6 10 -t homeassistant/button/${DEV_ID}/scan-bleln-macaddr/config -l
703703

704704
log_debug "setupHADeviceInfoBTadapter() leaving vin:$vin"
705705

mqtt.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ else
1515
fi
1616

1717
retryMQTTpub() {
18+
retryMQTTAttemptCount=$1
19+
retryMQTTpubDelay=$2
20+
shift
21+
shift
1822
args=$*
19-
retryMQTTAttemptCount=6
20-
retryMQTTpubDelay=10
2123

2224
log_debug "retryMQTTpub; entering..."
2325

@@ -31,7 +33,7 @@ retryMQTTpub() {
3133
cmdCounterLoop=0
3234
while [ $((cmdCounterLoop += 1)) -lt $retryMQTTAttemptCount ]; do
3335

34-
log_debug "retryMQTTpub; calling mosquitto_pub $args"
36+
log_debug "Attempt $cmdCounterLoop/${retryMQTTAttemptCount} retryMQTTpub; calling mosquitto_pub $args"
3537
set +e
3638
echo "$topic_json" | eval $MOSQUITTO_PUB_BASE $args
3739
exit_code=$?

0 commit comments

Comments
 (0)