-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from tesla-local-control/multi-cars
Prep for multi-cars, libproduct, liblog and more
- Loading branch information
Showing
5 changed files
with
171 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Optional for car presence detection; If multiple cars, separate with , or | or white space | ||
# | ||
BLE_MAC_LIST= | ||
|
||
# Default 5 (seconds) | ||
# | ||
BLE_CMD_RETRY_DELAY= | ||
|
||
### Default false | ||
# | ||
DEBUG= | ||
|
||
# Hostname or IP address | ||
# | ||
MQTT_SERVER= | ||
|
||
# Service port # or name | ||
# | ||
MQTT_PORT=1883 | ||
|
||
# If no username provided, anonymous mode. | ||
# | ||
MQTT_USERNAME= | ||
|
||
# If you have special characters, wrap with ' at both ends; escape ' if needed | ||
# | ||
MQTT_PASSWORD= | ||
|
||
# Default 120 (seconds) | ||
# | ||
PRESENCE_DETECTION_LOOP_DELAY= | ||
|
||
# Default 240 (seconds) | ||
# | ||
PRESENCE_DETECTION_TTL= | ||
|
||
# Mandatory; if multiple VINs separate with , or | or white space | ||
# | ||
VIN_LIST= | ||
|
||
# Your timezone | ||
# Ref: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | ||
# | ||
TZ='Europe/London' | ||
|
||
|
||
# | ||
# WARNING; If you run Home Assistant, keep this true unless you know what you're doing | ||
# | ||
ENABLE_HA_FEATURES=true |
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,27 @@ | ||
# shellcheck shell=dash | ||
# | ||
# functions for colored output | ||
# | ||
if [ "$COLOR" = "false" ]; then | ||
NOCOLOR='\033[0m' | ||
GREEN=$NOCOLOR | ||
CYAN=$NOCOLOR | ||
YELLOW=$NOCOLOR | ||
MAGENTA=$NOCOLOR | ||
RED=$NOCOLOR | ||
else | ||
NOCOLOR='\033[0m' | ||
GREEN='\033[0;32m' | ||
CYAN='\033[0;36m' | ||
YELLOW='\033[1;32m' | ||
MAGENTA='\033[0;35m' | ||
RED='\033[0;31m' | ||
fi | ||
|
||
# shellcheck disable=SC1089 | ||
function log_debug { [ "$DEBUG" = "true" ] && echo -e "${NOCOLOR}$1" || true; } | ||
function log_info { echo -e "${GREEN}$1${NOCOLOR}"; } | ||
function log_notice { echo -e "${CYAN}$1${NOCOLOR}"; } | ||
function log_warning { echo -e "${YELLOW}$1${NOCOLOR}"; } | ||
function log_error { echo -e "${MAGENTA}$1${NOCOLOR}"; } | ||
function log_fatal { echo -e "${RED}$1${NOCOLOR}"; } |
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,64 @@ | ||
function validateEnvVars() { | ||
exitOnError=0 | ||
|
||
BLE_MAC_PATTERN='^([0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){5})(\|[0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){5})*$' | ||
VIN_PATTERN='^([A-HJ-NPR-Z0-9]{17})(\|[A-HJ-NPR-Z0-9]{17})*$' | ||
INT0PLUS_PATTERN='^[0-9]+$' | ||
INT1PLUS_PATTERN='^[1-9][0-9]*$' | ||
# Hostname & IPv4 Address | ||
MQTT_SERVER_PATTERN='^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\b|\b([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$' | ||
|
||
if ! echo $VIN_LIST | grep -Eq "$VIN_PATTERN"; then | ||
log_fatal "Fatal; VIN_LIST:$VIN_LIST is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $BLE_MAC_LIST | grep -Eq "$BLE_MAC_PATTERN"; then | ||
log_fatal "Fatal; BLE_MAC_LIST:$BLE_MAC_LIST is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $PRESENCE_DETECTION_LOOP_DELAY | grep -Eq "$INT1PLUS_PATTERN"; then | ||
log_fatal "Fatal; PRESENCE_DETECTION_LOOP_DELAY:$PRESENCE_DETECTION_LOOP_DELAY is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $BLE_CMD_RETRY_DELAY | grep -Eq "$INT1PLUS_PATTERN"; then | ||
log_fatal "Fatal; BLE_CMD_RETRY_DELAY:$BLE_CMD_RETRY_DELAY is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $PRESENCE_DETECTION_TTL | grep -Eq "$INT0PLUS_PATTERN"; then | ||
log_fatal "Fatal; PRESENCE_DETECTION_TTL:$PRESENCE_DETECTION_TTL is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $MQTT_SERVER | grep -Eq "$MQTT_SERVER_PATTERN"; then | ||
log_fatal "Fatal; MQTT_SERVER:$MQTT_SERVER is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if ! echo $MQTT_PORT | grep -Eq "$INT1PLUS_PATTERN"; then | ||
log_fatal "Fatal; MQTT_PORT:$MQTT_PORT is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
if [ "$DEBUG" != 'true' ] && [ "$DEBUG" != 'false' ]; then | ||
log_fatal "Fatal; DEBUG:$DEBUG is not compliant, please check this setting" | ||
exitOnError=1 | ||
fi | ||
|
||
[ $exitOnError -ne 0 ] \ | ||
&& touch /data/.exitOnError \ | ||
&& exit 99 | ||
|
||
} | ||
|
||
function initProduct() { | ||
export COLOR=${COLOR:=true} | ||
|
||
# Source Logging Library | ||
. /app/liblog.sh | ||
|
||
validateEnvVars | ||
} |