Skip to content

Commit

Permalink
0.2.0 Add Network Backup and Restore
Browse files Browse the repository at this point in the history
  • Loading branch information
tube0013 committed Jan 9, 2024
1 parent 9aa1046 commit 2dd6337
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tzb-zigpy-cli-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.2.0
- Add Backup and Restore functions

## 0.1.0

- initial version
8 changes: 7 additions & 1 deletion tzb-zigpy-cli-tools/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Currently 4 commands are supported from zipy-cli
* **Energy Scan** - Perform an energy scan
* **Form** - Form a network on a new coordinator
* **Reset** - Resets the radio removing its network configuration
* **backup** - Backup Coordinator Network information to filename entereted
* **restore** - Restore Backup file specified to Coordinator

For Backup and Restore options, a folder will be created your Home Assistant config folder called tzb-zigpy-cli-tools
Under the Addon Advanced Options specify the name of the backup to create or restore - for example `backup.json`


# Start the addon
Start the Addon from the Info Tab.
Expand All @@ -57,5 +63,5 @@ Add-on configuration:
| radio_type | Type of radio / coordinator
| baudrate | Serial port baudrate (depends on firmware) |
| action | zigpy-cli command to run |

| backup_filename | Network backup filename |

12 changes: 9 additions & 3 deletions tzb-zigpy-cli-tools/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
version: 0.1.0
version: 0.2.0
slug: tzb-zigpy-cli-tools
name: TubesZB Zigpy-CLI Tools
description: TubesZB Zigpy-CLI Tools add-on
description: TubesZB Zigpy-CLI Toolsadd-on
url: >
https://tube0013/tubeszb_addons/tree/master/tzb-zigpy-cli-tools/
arch:
Expand All @@ -15,6 +15,11 @@ gpio: false
hassio_api: true
image: "ghcr.io/tube0013/{arch}-addon-tzb-zigpy-cli-tools"
init: false
map:
- share:rw
- config:rw
- all_addon_configs:rw

options:
network_device: null
device: null
Expand All @@ -28,7 +33,8 @@ schema:
network_device: str?
radio_type: list(znp|ezsp|deconz|xbee|zigate|zboss)
baudrate: list(57600|115200|230400|460800|921600)
action: list(info|energy-scan|reset|form)
action: list(info|energy-scan|reset|form|backup|restore)
backup_filename: str?
stage: stable
startup: once
boot: manual
34 changes: 30 additions & 4 deletions tzb-zigpy-cli-tools/rootfs/etc/s6-overlay/scripts/zigpy-cli-up
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare device_type
declare action
declare baudrate
declare radio_type
declare backup_filename
declare exit_status

function cleanup() {
Expand All @@ -24,6 +25,14 @@ trap cleanup EXIT

network_device=$(bashio::config 'network_device')

# Make folder for backups
if [ -d /config/tzb-zigpy-cli-tools ]; then
bashio::log.info "Directoty Exists"
else
mkdir /config/tzb-zigpy-cli-tools
bashio::log.info "Created /config/tzb-zigpy-cli-tools Directory"
fi

if bashio::config.true 'device_type'; then
device="socket://${network_device}"
else
Expand All @@ -33,10 +42,27 @@ fi
baudrate=$(bashio::config 'baudrate')
radio_type=$(bashio::config 'radio_type')
action=$(bashio::config 'action')
backup_filename=$(bashio::config 'backup_filename')

if (bashio::config.equals 'action' 'restore'); then
if [ ! -f /config/tzb-zigpy-cli-tools/${backup_filename} ]; then
bashio::log.warning "Backup File Not Found"
exit 0
fi
fi

bashio::log.info "Running zigpy - ${action} on ${device}"
zigpy radio --baudrate ${baudrate} ${radio_type} ${device} ${action}
exit 0

if ((bashio::config.equals 'action' 'backup') || (bashio::config.equals 'action' 'restore')) && (bashio::config.has_value 'backup_filename'); then
bashio::log.info "Running zigpy - ${action} on ${device} to /config/tzb-zigpy-cli-tools/${backup_filename}"
zigpy radio --baudrate ${baudrate} ${radio_type} ${device} ${action} /config/tzb-zigpy-cli-tools/${backup_filename}
elif ((bashio::config.equals 'action' 'backup') || (bashio::config.equals 'action' 'restore')) && (bashio::config.is_empty 'backup_filename'); then
bashio::log.warning "Not Backup File Specified"
exit 0
elif ((bashio::config.equals 'action' 'info') || (bashio::config.equals 'action' 'energy-scan') || (bashio::config.equals 'action' 'form') || (bashio::config.equals 'action' 'reset')); then
bashio::log.info "Running zigpy - ${action} on ${device}"
zigpy radio --baudrate ${baudrate} ${radio_type} ${device} ${action}
else
bashio::log.warning "No Action Specified"
exit 0
fi

bashio::log.info "Action Complete"

0 comments on commit 2dd6337

Please sign in to comment.