Repository navigation
Conversation
Odyno
force-pushed
the
feature/HassDiscoveryManager
branch
2 times, most recently
from
October 15, 2025 22:30
b7fb80c to
ebd7862
Compare
Odyno
force-pushed
the
feature/HassDiscoveryManager
branch
2 times, most recently
from
October 17, 2025 16:56
0425c9b to
fde06ee
Compare
- Introduced RFConfiguration class to encapsulate RF settings and operations. - Replaced direct usage of RFConfig structure with iRFConfig instance across multiple files. - Updated frequency handling in actuatorSomfy, gatewayPilight, gatewayRF, and gatewayRF2 to use iRFConfig. - Modified webUI to interact with iRFConfig for RF settings management. - Removed deprecated RFConfig structure and related functions. - Enhanced JSON handling for RF configuration loading and saving. - Improved logging for RF configuration operations.
- 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. Refactor MQTT Discovery and Add System Entity Publishing - Cleaned up includes in mqttDiscovery.cpp and organized them. - Added new function `publishSystemEntities()` to publish various system-related entities such as connectivity, uptime, memory, and IP. - Implemented a restart button and an erase credentials button for system management. - Updated the main MQTT discovery function to call the new system entities publishing function. - Introduced unit testing framework using Google Test and Google Mock. - Created test runner for unit tests and added initial dummy tests. - Added comprehensive unit tests for `HassValidators` to validate device classes and measurement units. - Implemented coverage report generation script for test coverage analysis. - Removed outdated test file `test_hass_discovery.cpp`. - Updated platformio.ini to include configurations for testing environments. Add unit tests for HassValidators to validate device classes and measurement units Add unit tests for HassEntity and HassTopicBuilder - Implemented comprehensive unit tests for the HassEntity class, covering entity configuration, publishing, and JSON generation. - Created a mock for IMqttPublisher and ISettingsProvider to facilitate testing. - Added tests for various scenarios including valid and invalid configurations, discovery topic generation, and MQTT publishing behavior. - Developed unit tests for the HassTopicBuilder class, ensuring correct topic construction for discovery, state, command, and availability topics. - Included edge case handling and performance tests for both classes. Refactor GitHub Actions workflow and enhance test documentation for HMD module Refactor unit tests for HassValidators - Organized and structured the test cases for device classes and measurement units. - Added tests for valid and invalid device classes, including edge cases. - Included tests for measurement units, ensuring correct validation and handling of special cases. - Verified performance of validation methods with a quick test. - Ensured consistency in counts of valid device classes and units. - Enhanced readability and maintainability of the test code. Enable C++17 standard globally in build flags for all environments Enable C++ exceptions for ESP8266 builds in platformio.ini Refactor conditional compilation logic and include directives for MQTT discovery Implement feature X to enhance user experience and fix bug Y in module Z Refactor MQTT Discovery to streamline legacy interface implementations and improve memory management
Odyno
force-pushed
the
feature/HassDiscoveryManager
branch
from
October 17, 2025 18:53
fde06ee to
1d7f5d0
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This module contains the refactored Home Assistant Discovery system for OpenMQTTGateway, implementing modern C++17 architecture following SOLID principles.
Overview
The HMD (Home Assistant Discovery Manager) module provides a comprehensive system for automatic discovery and configuration of IoT devices in Home Assistant. It replaces the legacy discovery system with a modern, modular, and efficient architecture.
Activation
The HMD module uses conditional compilation to coexist with the legacy discovery system:
ZmqttDiscovery2in your build configurationZmqttDiscovery(default behavior)ZmqttDiscovery2andZmqttDiscoveryare defined, HMD takes priority and legacy code is disabledArchitecture Overview
The module is organized following Single Responsibility Principle with each class handling a specific aspect of the discovery system:
Technical Requirements
Compiler Requirements
std::string_view,std::optional)-DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONSfor ESP8266)Build Configuration
The global build configuration in
platformio.iniensures C++17 support:Key Design Principles
1. Single Responsibility Principle (SRP)
2. Open/Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
ISettingsProvider,IMqttPublisher)5. Dependency Inversion Principle (DIP)
Core Components
Interfaces
ISettingsProvider
Provides access to configuration settings:
IMqttPublisher
Handles MQTT publishing operations:
Core Classes
HassValidators
HassTopicBuilder
HassDevice
Entity System
HassEntity (Abstract Base Class)
HassSensor
HassSwitch
HassButton
Manager
HassDiscoveryManager
Home Assistant Constants
All Home Assistant specific constants are centralized in
core/HassConstants.h:Device Classes (42+ constants)
Measurement Units (35+ constants)
Component Types
JSON Value Templates (25+ templates)
Usage Examples
Basic Sensor Creation
Creating External Device
Legacy Array Support
Memory Efficiency
The new architecture provides significant memory improvements:
Error Handling
The system provides robust error handling:
Performance Metrics
Target improvements achieved:
Testing
🧪 Comprehensive Test Suite
Comprehensive unit tests are available in
/test/unit/test_hmd/:🚀 CI/CD Integration Status: ✅ FULLY OPERATIONAL
Workflow:
.github/workflows/run-tests.ymlAutomatic Testing On:
main,development,feature/*branchesmain,developmentQuick Test Execution
See: Testing Documentation for complete details and CI/CD Integration Report for GitHub Actions status.
Contributing
When adding new entity types:
HassEntitybase classaddSpecificFields()methodHassDiscoveryManagerMigration from Legacy System
Phase 1: Core Infrastructure ✅
Phase 2: System Entities ✅
Phase 3: Conditional Compilation ✅
ZmqttDiscovery2flag for HMD activationPhase 4: Sensor Modules (In Progress)
Phase 5: Gateway Modules (Planned)
Deployment Status
Current Implementation
ZmqttDiscovery2)ZmqttDiscovery) remains active unlessZmqttDiscovery2is explicitly definedPlatform Compatibility
Enabling HMD in Your Build
environments.ini):platformio.ini):Checklist: