Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkoff71 authored Nov 4, 2024
2 parents de17637 + e166717 commit 2f076d7
Show file tree
Hide file tree
Showing 77 changed files with 7,248 additions and 3,822 deletions.
16 changes: 5 additions & 11 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.

**Device information**
- Screenshot of Zigbee and Device tab from root page of device
- JSON object returned on [http://xzg.local/api?action=1&param=all](http://xzg.local/api?action=1&param=all)
*You **should** remove your credentials first*

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
Expand All @@ -23,16 +28,5 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
129 changes: 129 additions & 0 deletions .github/scripts/update_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import re

def read_hw_file(hw_file_path):
with open(hw_file_path, 'r') as file:
return file.read()

def parse_brd_configs(hw_content):
pattern = re.compile(r'BrdConfigStruct brdConfigs\[\] = \{(.*?)\};', re.DOTALL)
match = pattern.search(hw_content)
if match:
print("Found brdConfigs")
return match.group(1)
print("brdConfigs not found")
return ""

def extract_devices(brd_configs, mist_configs):
devices = []
device_pattern = re.compile(r'\{\s*"([^"]+)",\s*\.ethConfigIndex = (-?\d+),\s*\.zbConfigIndex = -?\d+,\s*\.mistConfigIndex = (-?\d+)\s*\}', re.DOTALL)
for device_match in device_pattern.finditer(brd_configs):
device_name = device_match.group(1)
eth_config_index = int(device_match.group(2))
mist_config_index = int(device_match.group(3))

eth_is = eth_config_index > -1
btn_is = mist_configs[mist_config_index]['btnPin'] > -1
led_is = mist_configs[mist_config_index]['ledModePin'] > -1 or mist_configs[mist_config_index]['ledPwrPin'] > -1

device = {
'name': device_name,
'eth': ':white_check_mark:' if eth_is else ':x:',
'button': ':white_check_mark:' if btn_is else ':x:',
'led': ':white_check_mark:' if led_is else ':x:',
'network_usb': ':white_check_mark:'
}
devices.append(device)
print(f"Extracted device: {device}")
return devices

def parse_mist_configs(hw_content):
pattern = re.compile(r'MistConfig mistConfigs\[\] = \{(.*?)\};', re.DOTALL)
match = pattern.search(hw_content)
if match:
print("Found mistConfigs")
mist_configs = match.group(1)
return extract_mist_configs(mist_configs)
print("mistConfigs not found")
return []

def extract_mist_configs(mist_configs):
configs = []
config_pattern = re.compile(r'\{\s*\.btnPin = (-?\d+),\s*\.btnPlr = \d+,\s*\.uartSelPin = -?\d+,\s*\.uartSelPlr = \d+,\s*\.ledModePin = (-?\d+),\s*\.ledModePlr = \d+,\s*\.ledPwrPin = (-?\d+),\s*\.ledPwrPlr = \d+\s*\}', re.DOTALL)
for config_match in config_pattern.finditer(mist_configs):
config = {
'btnPin': int(config_match.group(1)),
'ledModePin': int(config_match.group(2)),
'ledPwrPin': int(config_match.group(3)),
}
configs.append(config)
print(f"Extracted mistConfig: {config}")
return configs

def read_features_file(features_file_path):
with open(features_file_path, 'r') as file:
return file.read()

def extract_existing_links(features_content):
device_links = {}
table_pattern = re.compile(r'\| \[(.*?)\]\((.*?)\)', re.DOTALL)
for match in table_pattern.finditer(features_content):
device_name = match.group(1)
link = match.group(2)
device_links[device_name] = link
print(f"Found link: {device_name} -> {link}")
return device_links

def update_features_content(features_content, devices, device_links):
# Define the regular expression to match the whole Supported devices section
table_pattern = re.compile(r'(.*## 🎮 Supported devices)(\s+\| .+\|.+?)(\* Some devices do not support all features.*)', re.DOTALL)
match = table_pattern.search(features_content)
if match:

header = match.group(1)
footer = match.group(3)

updated_devices_table = "| Device Name | Button | ESP32 LEDs | Remote Network / USB mode selection | Ethernet |\n"
updated_devices_table += "| :---------------------------------------------------------- | :----------------: | :----------------: | :---------------------------------: | :----------------: |\n"

for device in devices:
device_name = device['name']
link = device_links.get(device_name, "")
if link:
device_name = f"[{device_name}]({link})"
device_row = f"| {device_name} | {device['button']} | {device['led']} | {device['network_usb']} | {device['eth']} |\n"
updated_devices_table += device_row

updated_features_content = header + "\n\n" + updated_devices_table + "\n" + footer
print("Updated features content")
return updated_features_content
print("Supported devices section not found")
return features_content

def write_features_file(features_file_path, updated_content):
with open(features_file_path, 'w') as file:
file.write(updated_content)
print(f"Updated features file: {features_file_path}")

def main():
hw_file_path = 'main_branch/src//const/hw.cpp'
features_file_path = 'mkdocs_branch/docs/features.md'

hw_content = read_hw_file(hw_file_path)
print(f"Read hw.cpp content: {len(hw_content)} characters")

brd_configs = parse_brd_configs(hw_content)
mist_configs = parse_mist_configs(hw_content)

devices = extract_devices(brd_configs, mist_configs)

features_content = read_features_file(features_file_path)
print(f"Read features.md content: {len(features_content)} characters")

device_links = extract_existing_links(features_content)

updated_content = update_features_content(features_content, devices, device_links)

write_features_file(features_file_path, updated_content)

if __name__ == "__main__":
main()
57 changes: 50 additions & 7 deletions .github/workflows/build_fw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: "recursive"
fetch-depth: 0

- name: Get Release tag
id: get_tag
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
python-version: "3.9"

- name: Install PlatformIO Core
run: pip install --upgrade platformio==6.1.11
run: pip install --upgrade platformio==6.1.15

- name: Build PlatformIO Project
run: pio run
Expand Down Expand Up @@ -97,6 +98,29 @@ jobs:
EOF
echo "Manifest file created."
- name: Get the latest commit SHA for the whole project
id: get_fw_commit_sha
run: echo "::set-output name=fw_commit_sha::$(git log -n 1 --pretty=format:%h)"

- name: Get the latest commit SHA in src/websrc
id: get_fs_commit_sha
run: echo "::set-output name=fs_commit_sha::$(git log -n 1 --pretty=format:%h -- src/websrc)"

- name: Create xzg.json for firmware update
run: |
cat << EOF > xzg.json
{
"name": "XZG Firmware",
"version": "${{ steps.get_tag.outputs.tag }}",
"fw_sha": "${{ steps.get_fw_commit_sha.outputs.fw_commit_sha }}",
"fs_sha": "${{ steps.get_fs_commit_sha.outputs.fs_commit_sha }}"
}
EOF
echo "xzg.json file created."
- name: Display xzg.json
run: cat xzg.json

- name: Release
uses: softprops/action-gh-release@v1
with:
Expand All @@ -106,6 +130,7 @@ jobs:
files: |
bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin
- name: Checkout releases branch
uses: actions/checkout@v3
Expand All @@ -120,14 +145,32 @@ jobs:
cp manifest.json releases/${{ steps.get_tag.outputs.tag }}/
echo "Files copied to releases directory."
- name: Prepare latest release directory
run: |
if [ -d releases/latest ]; then
rm -rf releases/latest
fi
mkdir -p releases/latest
- name: Copy file to latest release directory
run: |
cp xzg.json releases/latest/
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin releases/latest/XZG.ota.bin
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin releases/latest/XZG.fs.bin
echo "File copied to latest release directory."
- name: Commit and push files to releases branch
run: |
cd releases
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Add firmware and manifest for version ${{ steps.get_tag.outputs.tag }}"
git push origin releases
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "${{ steps.get_tag.outputs.tag }}"
git push origin releases
else
echo "No changes to commit"
fi
- name: Send Telegram Notification about release
uses: appleboy/telegram-action@master
Expand All @@ -142,7 +185,7 @@ jobs:
- name: Send Discord Notification about release
run: |
json_payload=$(jq -n --arg content "https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }}" '{content: $content}')
curl -H "Content-Type: application/json" \
-d "{\"content\": \"${{ env.commitMessage }}\n\nhttps://github.com/${{ github.repository }}/releases/tag/${{ env.tag }}\"}" \
${{ secrets.DISCORD_WEBHOOK }}
-d "$json_payload" \
${{ secrets.DISCORD_WEBHOOK }}
38 changes: 38 additions & 0 deletions .github/workflows/build_wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Wiki
on:
workflow_dispatch:
workflow_run:
workflows: ["Update devices in wiki"]
types:
- completed
push:
branches:
- mkdocs

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: mkdocs
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- run: pip install -r requirements.txt
- run: mkdocs gh-deploy --force
56 changes: 56 additions & 0 deletions .github/workflows/update_devices.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Update devices in wiki

permissions:
contents: write

on:
workflow_dispatch:
push:
branches:
- main
paths:
- src/const/hw.cpp

jobs:
update-devices:
runs-on: ubuntu-latest

steps:
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main
path: main_branch

- name: Checkout mkdocs branch
uses: actions/checkout@v2
with:
ref: mkdocs
path: mkdocs_branch

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Run update_devices.py
run: python main_branch/.github/scripts/update_devices.py

- name: Commit and push changes
run: |
cd mkdocs_branch
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if [[ -n $(git status --porcelain) ]]; then
git add docs/features.md
git commit -m 'Update features.md with new device data'
git push origin mkdocs
else
echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ todo*
!lib
!platformio.ini
**/__pycache__
tools/.no_web_update*
tools/.no_web_update*
managed_components
old?
data/*
/tools/webfilesbuilder/.npm_install_marker*
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(XZG)

Loading

0 comments on commit 2f076d7

Please sign in to comment.