feat(gateway): implement GatewayController and enhance GatewayRuntime
- Added GatewayController class to manage gateway operations, including command handling, scene and group management, and BLE state management. - Introduced methods for scene and group storage, including loading, saving, and deleting scenes/groups. - Enhanced GatewayRuntime with BLE management capabilities, including methods to check and set BLE state, and to generate BLE gateway names. - Implemented utility functions for string normalization and CSV parsing. - Added notification sinks for various events in the GatewayController. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -99,10 +99,13 @@ class GatewayRuntime {
|
||||
void setCommandAddressResolver(std::function<uint8_t(uint8_t gw, uint8_t raw_addr)> resolver);
|
||||
|
||||
GatewayDeviceInfo deviceInfo() const;
|
||||
bool bleEnabled() const;
|
||||
bool setBleEnabled(bool enabled);
|
||||
std::string gatewayName(uint8_t gateway_id) const;
|
||||
bool setGatewayName(uint8_t gateway_id, std::string_view name);
|
||||
std::string gatewaySerialHex(uint8_t gateway_id) const;
|
||||
std::string bleMacHex() const;
|
||||
std::string bleGatewayName(uint8_t gateway_id, std::string_view gateway_name) const;
|
||||
std::string defaultBleGatewayName() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -312,6 +312,18 @@ GatewayDeviceInfo GatewayRuntime::deviceInfo() const {
|
||||
return info;
|
||||
}
|
||||
|
||||
bool GatewayRuntime::bleEnabled() const {
|
||||
return ble_enabled_;
|
||||
}
|
||||
|
||||
bool GatewayRuntime::setBleEnabled(bool enabled) {
|
||||
if (!settings_.setBleEnabled(enabled)) {
|
||||
return false;
|
||||
}
|
||||
ble_enabled_ = enabled;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string GatewayRuntime::gatewayName(uint8_t gateway_id) const {
|
||||
return settings_.getGatewayName(gateway_id, defaultGatewayName(gateway_id));
|
||||
}
|
||||
@@ -342,6 +354,17 @@ std::string GatewayRuntime::bleMacHex() const {
|
||||
return toHex(serialBytes());
|
||||
}
|
||||
|
||||
std::string GatewayRuntime::bleGatewayName(uint8_t gateway_id, std::string_view gateway_name) const {
|
||||
std::string normalized(gateway_name);
|
||||
if (normalized.size() > kMaxGatewayNameBytes) {
|
||||
normalized.resize(kMaxGatewayNameBytes);
|
||||
}
|
||||
if (!normalized.empty() && normalized != defaultGatewayName(gateway_id)) {
|
||||
return normalized;
|
||||
}
|
||||
return defaultBleGatewayName();
|
||||
}
|
||||
|
||||
std::string GatewayRuntime::defaultBleGatewayName() const {
|
||||
return "DALIGW_" + bleMacHex();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user