Skip to content

Commit

Permalink
Upgrade Theengs Gateway to 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem committed Dec 11, 2023
1 parent 271f83f commit 0053687
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ You can show the snap's configuration with:
```shell
$ snap get -d theengs-gateway
{
"bindkeys": "",
"ble": {
"adapter": "",
"scan-duration": 5,
Expand All @@ -57,8 +58,11 @@ $ snap get -d theengs-gateway
"discovery-topic": "homeassistant/sensor",
"hass-discovery": 1
},
"identities": "",
"log-level": "INFO",
"mqtt": {
"enable-tls": 0,
"enable-ws": 0,
"host": "",
"pass": "",
"port": 1883,
Expand Down
96 changes: 96 additions & 0 deletions scripts/bin/management-script
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ DEFAULT_PRESENCE_TOPIC="home/TheengsGateway/presence"
DEFAULT_PRESENCE="0"
DEFAULT_LWT_TOPIC="home/TheengsGateway/LWT"
DEFAULT_PUBLISH_ADVDATA="0"
DEFAULT_ENABLE_TLS="0"
DEFAULT_ENABLE_WS="0"
DEFAULT_BINDKEYS=""
DEFAULT_IDENTITIES=""

# ADAPTER
adapter() {
Expand Down Expand Up @@ -503,3 +507,95 @@ previous_publish_advdata() {
set_previous_publish_advdata() {
snapctl set private.mqtt.publish-advdata="$1"
}

# ENABLE_TLS
enable_tls() {
enable_tls_enable="$(snapctl get mqtt.enable-tls)"
if [ -z "$enable_tls_enable" ]; then
enable_tls_enable="$DEFAULT_ENABLE_TLS"
set_enable_tls "$enable_tls_enable"
set_previous_enable_tls "$enable_tls_enable"
fi
echo "$enable_tls_enable"
}

set_enable_tls() {
snapctl set mqtt.enable-tls="$1"
}

previous_enable_tls() {
snapctl get private.mqtt.enable-tls
}

set_previous_enable_tls() {
snapctl set private.mqtt.enable-tls="$1"
}

# ENABLE_WS
enable_ws() {
enable_ws_enable="$(snapctl get mqtt.enable-ws)"
if [ -z "$enable_ws_enable" ]; then
enable_ws_enable="$DEFAULT_ENABLE_WS"
set_enable_ws "$enable_ws_enable"
set_previous_enable_ws "$enable_ws_enable"
fi
echo "$enable_ws_enable"
}

set_enable_ws() {
snapctl set mqtt.enable-ws="$1"
}

previous_enable_ws() {
snapctl get private.mqtt.enable-ws
}

set_previous_enable_ws() {
snapctl set private.mqtt.enable-ws="$1"
}

# BINDKEYS
bindkeys() {
bindkeys_addresses="$(snapctl get bindkeys)"
if [ -z "$bindkeys_addresses" ]; then
bindkeys_addresses="$DEFAULT_BINDKEYS"
set_bindkeys "$bindkeys_addresses"
set_previous_bindkeys "$bindkeys_addresses"
fi
echo "$bindkeys_addresses"
}

set_bindkeys() {
snapctl set bindkeys="$1"
}

previous_bindkeys() {
snapctl get private.bindkeys
}

set_previous_bindkeys() {
snapctl set private.bindkeys="$1"
}

# IDENTITIES
identities() {
identities_addresses="$(snapctl get identities)"
if [ -z "$identities_addresses" ]; then
identities_addresses="$DEFAULT_IDENTITIES"
set_identities "$identities_addresses"
set_previous_identities "$identities_addresses"
fi
echo "$identities_addresses"
}

set_identities() {
snapctl set identities="$1"
}

previous_identities() {
snapctl get private.identities
}

set_previous_identities() {
snapctl set private.identities="$1"
}
10 changes: 9 additions & 1 deletion scripts/bin/theengs-gateway-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ LWT_TOPIC="$(lwt_topic)"
export LWT_TOPIC
PUBLISH_ADVDATA="$(publish_advdata)"
export PUBLISH_ADVDATA
ENABLE_TLS="$(enable_tls)"
export ENABLE_TLS
ENABLE_WS="$(enable_ws)"
export ENABLE_WS
BINDKEYS="$(bindkeys)"
export BINDKEYS
IDENTITIES="$(identities)"
export IDENTITIES

"$SNAP/bin/TheengsGateway" -H "$HOST" -P "$PORT" -u "$USER" -p "$PASS" -pt "$PUB_TOPIC" -st "$SUB_TOPIC" -sd "$SCAN_DUR" -tb "$TIME_BETWEEN" -ll "$LOG_LEVEL" -Dt "$DISCOVERY_TOPIC" -D "$DISCOVERY" -Dh "$HASS_DISCOVERY" -Dn "$DISCOVERY_DEVICE_NAME" -Df "$DISCOVERY_FILTER" -a "$ADAPTER" -ts "$TIME_SYNC" -tf "$TIME_FORMAT" -prt "$PRESENCE_TOPIC" -pr "$PRESENCE" -Lt "$LWT_TOPIC" -padv "$PUBLISH_ADVDATA"
"$SNAP/bin/TheengsGateway" -H "$HOST" -P "$PORT" -u "$USER" -p "$PASS" -pt "$PUB_TOPIC" -st "$SUB_TOPIC" -sd "$SCAN_DUR" -tb "$TIME_BETWEEN" -ll "$LOG_LEVEL" -Dt "$DISCOVERY_TOPIC" -D "$DISCOVERY" -Dh "$HASS_DISCOVERY" -Dn "$DISCOVERY_DEVICE_NAME" -Df "$DISCOVERY_FILTER" -a "$ADAPTER" -ts "$TIME_SYNC" -tf "$TIME_FORMAT" -prt "$PRESENCE_TOPIC" -pr "$PRESENCE" -Lt "$LWT_TOPIC" -padv "$PUBLISH_ADVDATA" -tls "$ENABLE_TLS" -ws "$ENABLE_WS" -bk "$BINDKEYS" -id "$IDENTITIES"
60 changes: 60 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,63 @@ handle_publish_advdata_config() {
restart_gateway_if_running
}
handle_publish_advdata_config

handle_enable_tls_config() {
enable_tls="$(enable_tls)"
previous_enable_tls="$(previous_enable_tls)"

if [ "$enable_tls" = "$previous_enable_tls" ]; then
return 0
fi

set_enable_tls "$enable_tls"
set_previous_enable_tls "$enable_tls"

restart_gateway_if_running
}
handle_enable_tls_config

handle_enable_ws_config() {
enable_ws="$(enable_ws)"
previous_enable_ws="$(previous_enable_ws)"

if [ "$enable_ws" = "$previous_enable_ws" ]; then
return 0
fi

set_enable_ws "$enable_ws"
set_previous_enable_ws "$enable_ws"

restart_gateway_if_running
}
handle_enable_ws_config

handle_bindkeys_config() {
bindkeys="$(bindkeys)"
previous_bindkeys="$(previous_bindkeys)"

if [ "$bindkeys" = "$previous_bindkeys" ]; then
return 0
fi

set_bindkeys "$bindkeys"
set_previous_bindkeys "$bindkeys"

restart_gateway_if_running
}
handle_bindkeys_config

handle_identities_config() {
identities="$(identities)"
previous_identities="$(previous_identities)"

if [ "$identities" = "$previous_identities" ]; then
return 0
fi

set_identities "$identities"
set_previous_identities "$identities"

restart_gateway_if_running
}
handle_identities_config
34 changes: 21 additions & 13 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |
LYWSDCGQ, and Mi Flora. It translates these data into a readable JSON
format and pushes those to an MQTT broker.
icon: snap/local/logo-Theengs.png
version: 1.1.0
version: 1.2.0
license: GPL-3.0
contact: [email protected]
website: https://github.com/theengs/gateway-snap
Expand All @@ -28,34 +28,42 @@ parts:
theengs-decoder:
plugin: python
source: https://github.com/theengs/decoder.git
source-tag: v1.5.0
source-tag: v1.6.4
override-pull: |
craftctl default
sed -i "s/version_tag/1.5.0/g" $CRAFT_PART_SRC/setup.py
sed -i "s/ shutil.rmtree('TheengsDecoder.egg-info')//g" $CRAFT_PART_SRC/setup.py
rm $SNAPCRAFT_PART_SRC/pyproject.toml # Use pre-built system-site requirements
cd python
cp -r ../src .
rm pyproject.toml # Use pre-built system-site requirements
build-packages:
- build-essential
- python3-skbuild # Use scikit-build and setuptools from repo
- python3-setuptools # as they are a combination that is known working
- python3-skbuild # Use scikit-build
- python3-setuptools # and setuptools from Ubuntu repository
- python3-setuptools-scm # as they are a combination that is known working
build-environment:
- PARTS_PYTHON_VENV_ARGS: "--system-site-packages" # Use the above packages
python-packages: # Replace default value [pip, setuptools, wheel]
- pip
- wheel
stage:
- lib/python3.10/site-packages/TheengsDecoder/*
- lib/python3.10/site-packages/TheengsDecoder-1.5.0.dist-info/*
- lib/python3.10/site-packages/TheengsDecoder-1.6.4.dist-info/*
theengs-gateway:
after:
- theengs-decoder
plugin: python
source: https://github.com/theengs/gateway.git
source-tag: v1.1.0
override-pull: |
craftctl default
sed -i "s/version_tag/$SNAPCRAFT_PROJECT_VERSION/g" $CRAFT_PART_SRC/setup.py
sed -i 's/ "TheengsDecoder>=1.5.0",/"importlib_metadata",/g' $CRAFT_PART_SRC/setup.py
source-tag: v1.2.0
build-packages:
- libssl-dev
- build-essential
- python3-skbuild # Use scikit-build
- python3-setuptools # and setuptools from Ubuntu repository
- python3-setuptools-scm # as they are a combination that is known working
build-environment:
- PARTS_PYTHON_VENV_ARGS: "--system-site-packages" # Use the above packages
python-packages: # Replace default value [pip, setuptools, wheel]
- pip
- wheel
scripts:
plugin: dump
source: scripts
Expand Down

0 comments on commit 0053687

Please sign in to comment.