Skip to content

Commit 9004fda

Browse files
committed
BASELINE: Implement Home Assistant Discovery Manager
- Added HassDiscoveryManager class to manage Home Assistant entity discovery. - Introduced methods for publishing system entities, creating external devices, and managing entity lifecycle. - Implemented validation and error handling for entities. - Created unit tests for HassDiscoveryManager and related classes to ensure functionality and adherence to SOLID principles. core: Add sync and version management scripts - Added sync-upstream.sh for synchronizing with the upstream repository. - Introduced version-manager.sh for managing versioning of the OpenMQTTGateway fork. test: Add unit tests for HassDiscoveryManager - Created test_hass_discovery.cpp to validate the functionality of the new discovery system. - Included tests for entity validation, topic building, and device management. Refactor HassDiscovery to use dependency injection for settings and MQTT publisher (step 2) - Updated HassDevice to accept ISettingsProvider in constructors and methods. - Modified HassTopicBuilder to utilize settings provider for topic generation. - Enhanced HassEntity and its derived classes (HassButton, HassSensor, HassSwitch) to include IMqttPublisher for message publishing. - Refactored HassDiscoveryManager to initialize with ISettingsProvider and IMqttPublisher, replacing global variables. - Implemented legacy adapter classes for ISettingsProvider and IMqttPublisher to maintain backward compatibility. - Updated example usage in examples.cpp to demonstrate new dependency injection patterns. - Removed legacy global variable dependencies and replaced with modern interface implementations.
1 parent 8c5fc8e commit 9004fda

31 files changed

+4664
-143
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: 🚀 Custom Release Build
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*-o*" # Matches tags like v1.8.0-o1, v1.8.1-o2, etc.
7+
workflow_dispatch:
8+
inputs:
9+
version_type:
10+
description: "Version bump type"
11+
required: true
12+
default: "patch"
13+
type: choice
14+
options:
15+
- patch
16+
- minor
17+
- major
18+
19+
env:
20+
CUSTOM_SUFFIX: "o"
21+
22+
jobs:
23+
version-bump:
24+
if: github.event_name == 'workflow_dispatch'
25+
runs-on: ubuntu-latest
26+
outputs:
27+
new_version: ${{ steps.bump.outputs.new_version }}
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
fetch-depth: 0
33+
34+
- name: Setup PowerShell
35+
shell: pwsh
36+
run: |
37+
# Install required modules if needed
38+
Write-Host "PowerShell setup complete"
39+
40+
- name: Bump Version
41+
id: bump
42+
shell: pwsh
43+
run: |
44+
$newVersion = .\scripts\version-manager.ps1 ${{ github.event.inputs.version_type }}
45+
echo "new_version=$newVersion" >> $env:GITHUB_OUTPUT
46+
47+
- name: Commit and Push
48+
run: |
49+
git config --local user.email "[email protected]"
50+
git config --local user.name "GitHub Action"
51+
git push origin HEAD:${{ github.ref_name }}
52+
53+
build:
54+
needs: [version-bump]
55+
if: always() && !cancelled()
56+
runs-on: ubuntu-latest
57+
strategy:
58+
matrix:
59+
environment:
60+
- esp32dev-all-test
61+
- esp32-theengs-bridge
62+
- esp8266-rf
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
69+
- name: Cache pip
70+
uses: actions/cache@v4
71+
with:
72+
path: ~/.cache/pip
73+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
74+
75+
- name: Cache PlatformIO
76+
uses: actions/cache@v4
77+
with:
78+
path: ~/.platformio
79+
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
80+
81+
- name: Set up Python
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: "3.11"
85+
86+
- name: Install PlatformIO
87+
run: |
88+
python -m pip install --upgrade pip
89+
pip install --upgrade platformio
90+
91+
- name: Build firmware
92+
run: pio run -e ${{ matrix.environment }}
93+
94+
- name: Run tests
95+
run: pio test -e test
96+
97+
- name: Upload artifacts
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: firmware-${{ matrix.environment }}
101+
path: .pio/build/${{ matrix.environment }}/firmware.*
102+
103+
release:
104+
needs: [build]
105+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- name: Download artifacts
111+
uses: actions/download-artifact@v4
112+
with:
113+
path: artifacts
114+
115+
- name: Create Release
116+
uses: softprops/action-gh-release@v1
117+
with:
118+
files: artifacts/**/*
119+
body: |
120+
## Custom OpenMQTTGateway Build ${{ github.ref_name }}
121+
122+
### Features
123+
- Custom RF signal filtering
124+
- Enhanced BLE connectivity
125+
- Optimized for specific hardware configurations
126+
127+
### Changes
128+
- Based on upstream OpenMQTTGateway
129+
- Custom modifications for enhanced performance
130+
131+
### Installation
132+
1. Download the appropriate firmware for your board
133+
2. Flash using your preferred method (OTA, esptool, etc.)
134+
135+
### Support
136+
For issues specific to these custom builds, please open an issue in this repository.
137+
prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') }}
138+
env:
139+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ sdkconfig.*
1717
__pycache__
1818
*.pem
1919
managed_components
20+
21+
.github/chatmodes
22+
.github/instructions
23+
.github/prompts
24+
.github/*instructions.md

docs/BRANCHING_STRATEGY.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# OpenMQTTGateway Fork - Branching Strategy
2+
3+
## Overview
4+
This document outlines the branching strategy for the custom OpenMQTTGateway fork, maintaining synchronization with the upstream repository while developing custom features.
5+
6+
## Repository Structure
7+
8+
### Remotes
9+
- **origin**: `[email protected]:Odyno/OpenMQTTGateway.git` (your fork)
10+
- **upstream**: `https://github.com/1technophile/OpenMQTTGateway.git` (upstream)
11+
12+
### Branch Hierarchy
13+
14+
```
15+
origin/main (production-ready custom build)
16+
├── origin/development (integration branch)
17+
│ ├── feature/filter_rf_signal (current feature)
18+
│ ├── feature/enhanced_ble
19+
│ └── feature/custom_sensors
20+
├── origin/release/x.x.x-o (release branches)
21+
└── sync/upstream-YYYY-MM-DD (upstream sync branches)
22+
23+
upstream/development (upstream main branch)
24+
```
25+
26+
## Branch Types
27+
28+
### 1. Main Branches
29+
30+
#### `main`
31+
- **Purpose**: Production-ready custom build
32+
- **Protection**: Protected, requires PR and tests
33+
- **Deployment**: Automatically builds and creates releases
34+
- **Merges from**: `development` via tested PRs only
35+
36+
#### `development`
37+
- **Purpose**: Integration of custom features with upstream
38+
- **Protection**: Requires PR review
39+
- **Testing**: All tests must pass
40+
- **Merges from**: Feature branches and sync branches
41+
42+
### 2. Feature Branches
43+
44+
#### Pattern: `feature/[description]`
45+
- **Examples**:
46+
- `feature/filter_rf_signal`
47+
- `feature/enhanced_ble_scanning`
48+
- `feature/custom_sensor_support`
49+
- **Lifetime**: Created from `development`, merged back via PR
50+
- **Testing**: Must include tests for new functionality
51+
52+
### 3. Sync Branches
53+
54+
#### Pattern: `sync/upstream-YYYY-MM-DD`
55+
- **Purpose**: Merge upstream changes safely
56+
- **Created by**: `scripts/sync-upstream.ps1`
57+
- **Process**:
58+
1. Create from `development`
59+
2. Merge `upstream/development`
60+
3. Resolve conflicts if any
61+
4. Test custom features still work
62+
5. Create PR to `development`
63+
64+
### 4. Release Branches
65+
66+
#### Pattern: `release/x.x.x-o[n]`
67+
- **Purpose**: Prepare releases with custom suffix
68+
- **Examples**: `release/1.8.0-o1`, `release/1.8.1-o2`
69+
- **Process**:
70+
1. Branch from `development`
71+
2. Version bump with `scripts/version-manager.ps1`
72+
3. Final testing
73+
4. Merge to `main`
74+
5. Tag and release
75+
76+
## Versioning Strategy
77+
78+
### Version Format: `X.Y.Z-o[N]`
79+
- **X.Y.Z**: Upstream version base
80+
- **-o**: Odyno custom build identifier
81+
- **[N]**: Optional sequential number for same upstream version
82+
83+
### Examples:
84+
- `1.8.0-o1` - First custom build based on upstream 1.8.0
85+
- `1.8.0-o2` - Second custom build with additional features
86+
- `1.8.1-o` - Custom build based on upstream 1.8.1
87+
88+
## Workflow Procedures
89+
90+
### 1. Daily Development
91+
92+
```powershell
93+
# Start new feature
94+
git checkout development
95+
git pull origin development
96+
git checkout -b feature/my-new-feature
97+
98+
# Develop and test
99+
# ... make changes ...
100+
pio test
101+
102+
# Push and create PR
103+
git push origin feature/my-new-feature
104+
# Create PR via GitHub UI: feature/my-new-feature -> development
105+
```
106+
107+
### 2. Upstream Synchronization (Weekly/Monthly)
108+
109+
```powershell
110+
# Check for upstream changes
111+
.\scripts\sync-upstream.ps1 -Interactive
112+
113+
# If conflicts, resolve manually then:
114+
git add .
115+
git commit -m "resolve: merge conflicts with upstream"
116+
git push origin sync/upstream-YYYY-MM-DD
117+
118+
# Create PR: sync/upstream-YYYY-MM-DD -> development
119+
```
120+
121+
### 3. Release Process
122+
123+
```powershell
124+
# Create release branch
125+
git checkout development
126+
git pull origin development
127+
git checkout -b release/1.8.0-o1
128+
129+
# Bump version
130+
.\scripts\version-manager.ps1 minor
131+
132+
# Test thoroughly
133+
pio test
134+
pio run -e esp32dev-all-test
135+
136+
# Merge to main
137+
git checkout main
138+
git merge release/1.8.0-o1 --no-ff
139+
140+
# Create tag and release
141+
.\scripts\version-manager.ps1 tag
142+
git push origin main --tags
143+
```
144+
145+
## Automation
146+
147+
### GitHub Actions
148+
- **Custom Release**: Triggered on version tags (`v*-o*`)
149+
- **PR Testing**: Runs on all PRs to `main` and `development`
150+
- **Upstream Sync**: Weekly check for upstream changes
151+
152+
### Scripts
153+
- `scripts/sync-upstream.ps1` - Upstream synchronization
154+
- `scripts/version-manager.ps1` - Version management
155+
- `scripts/test-custom-features.ps1` - Custom feature validation
156+
157+
## Best Practices
158+
159+
### 1. Keep Custom Changes Modular
160+
- Use preprocessor directives (`#ifdef CUSTOM_FEATURE`)
161+
- Separate custom code in dedicated files when possible
162+
- Document custom modifications clearly
163+
164+
### 2. Test Strategy
165+
- All custom features must have tests
166+
- Test suite runs on multiple ESP32/ESP8266 environments
167+
- Integration tests for MQTT and custom protocols
168+
169+
### 3. Documentation
170+
- Update `README.md` for custom features
171+
- Maintain `CHANGELOG.md` for releases
172+
- Document configuration changes
173+
174+
### 4. Conflict Resolution
175+
- Prefer upstream changes unless they break custom features
176+
- Document why upstream changes were rejected
177+
- Keep custom patches minimal and focused
178+
179+
## Emergency Procedures
180+
181+
### Hotfix Process
182+
1. Branch from `main`: `hotfix/critical-fix`
183+
2. Make minimal changes
184+
3. Test thoroughly
185+
4. Merge to both `main` and `development`
186+
5. Tag new patch version
187+
188+
### Rollback Process
189+
1. Identify last known good tag
190+
2. Create branch from tag: `rollback/to-v1.8.0-o1`
191+
3. Test and deploy
192+
4. Investigate and fix issues in development
193+
194+
## Monitoring and Metrics
195+
196+
### Key Metrics
197+
- Upstream sync frequency (target: weekly)
198+
- Custom feature test coverage (target: >80%)
199+
- Release frequency (target: monthly for features, as-needed for fixes)
200+
- Merge conflict resolution time (target: <24h)
201+
202+
### Tools
203+
- GitHub Actions for CI/CD
204+
- PlatformIO for testing
205+
- GitHub Issues for tracking
206+
- GitHub Projects for feature planning

0 commit comments

Comments
 (0)