add first advanced config entries
This commit is contained in:
@@ -17,5 +17,7 @@
|
||||
#define mqtt_topic_config_button_enabled "/configuration/buttonEnabled"
|
||||
#define mqtt_topic_config_led_enabled "/configuration/ledEnabled"
|
||||
#define mqtt_topic_config_led_brightness "/configuration/ledBrightness"
|
||||
#define mqtt_topic_config_auto_unlock "/configuration/autoUnlock"
|
||||
#define mqtt_topic_config_auto_lock "/configuration/autoLock"
|
||||
|
||||
#define mqtt_topic_presence "/presence/devices"
|
||||
|
||||
10
Network.cpp
10
Network.cpp
@@ -13,10 +13,12 @@ Network::Network(Preferences* preferences)
|
||||
{
|
||||
nwInst = this;
|
||||
|
||||
_configTopics.reserve(3);
|
||||
_configTopics.reserve(5);
|
||||
_configTopics.push_back(mqtt_topic_config_button_enabled);
|
||||
_configTopics.push_back(mqtt_topic_config_led_enabled);
|
||||
_configTopics.push_back(mqtt_topic_config_led_brightness);
|
||||
_configTopics.push_back(mqtt_topic_config_auto_unlock);
|
||||
_configTopics.push_back(mqtt_topic_config_auto_lock);
|
||||
}
|
||||
|
||||
void Network::initialize()
|
||||
@@ -277,6 +279,12 @@ void Network::publishConfig(const Nuki::Config &config)
|
||||
publishInt(mqtt_topic_config_led_brightness, config.ledBrightness);
|
||||
}
|
||||
|
||||
void Network::publishAdvancedConfig(const Nuki::AdvancedConfig &config)
|
||||
{
|
||||
publishBool(mqtt_topic_config_auto_unlock, config.autoUnLockDisabled == 0);
|
||||
publishBool(mqtt_topic_config_auto_lock, config.autoLockEnabled == 1);
|
||||
}
|
||||
|
||||
void Network::publishPresenceDetection(char *csv)
|
||||
{
|
||||
_presenceCsv = csv;
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void publishKeyTurnerState(const Nuki::KeyTurnerState& keyTurnerState, const Nuki::KeyTurnerState& lastKeyTurnerState);
|
||||
void publishBatteryReport(const Nuki::BatteryReport& batteryReport);
|
||||
void publishConfig(const Nuki::Config& config);
|
||||
void publishAdvancedConfig(const Nuki::AdvancedConfig& config);
|
||||
void publishPresenceDetection(char* csv);
|
||||
|
||||
void setLockActionReceivedCallback(void (*lockActionReceivedCallback)(const char* value));
|
||||
|
||||
@@ -152,7 +152,9 @@ void NukiWrapper::updateBatteryState()
|
||||
void NukiWrapper::updateConfig()
|
||||
{
|
||||
readConfig();
|
||||
readAdvancedConfig();
|
||||
_network->publishConfig(_nukiConfig);
|
||||
_network->publishAdvancedConfig(_nukiAdvancedConfig);
|
||||
}
|
||||
|
||||
Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str)
|
||||
@@ -203,6 +205,27 @@ void NukiWrapper::onConfigUpdateReceived(const char *topic, const char *value)
|
||||
_nukiBle.setLedBrightness(newValue);
|
||||
_nextConfigUpdateTs = millis() + 300;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_config_auto_unlock) == 0)
|
||||
{
|
||||
bool newValue = !(atoi(value) > 0);
|
||||
if(!_nukiAdvancedConfigValid || _nukiAdvancedConfig.autoUnLockDisabled == newValue) return;
|
||||
_nukiBle.disableAutoUnlock(newValue);
|
||||
_nextConfigUpdateTs = millis() + 300;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_config_auto_lock) == 0)
|
||||
{
|
||||
bool newValue = atoi(value) > 0;
|
||||
if(!_nukiAdvancedConfigValid || _nukiAdvancedConfig.autoLockEnabled == newValue) return;
|
||||
_nukiBle.enableAutoLock(newValue);
|
||||
_nextConfigUpdateTs = millis() + 300;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_config_auto_lock) == 0)
|
||||
{
|
||||
bool newValue = atoi(value) > 0;
|
||||
if(!_nukiAdvancedConfigValid || _nukiAdvancedConfig.autoLockEnabled == newValue) return;
|
||||
_nukiBle.enableAutoLock(newValue);
|
||||
_nextConfigUpdateTs = millis() + 300;
|
||||
}
|
||||
}
|
||||
|
||||
const Nuki::KeyTurnerState &NukiWrapper::keyTurnerState()
|
||||
@@ -230,6 +253,16 @@ void NukiWrapper::notify(Nuki::EventType eventType)
|
||||
|
||||
void NukiWrapper::readConfig()
|
||||
{
|
||||
Serial.print(F("Reading config. Result: "));
|
||||
Nuki::CmdResult result = _nukiBle.requestConfig(&_nukiConfig);
|
||||
_nukiConfigValid = result == Nuki::CmdResult::Success;
|
||||
Serial.println(result);
|
||||
}
|
||||
|
||||
void NukiWrapper::readAdvancedConfig()
|
||||
{
|
||||
Serial.print(F("Reading advanced config. Result: "));
|
||||
Nuki::CmdResult result = _nukiBle.requestAdvancedConfig(&_nukiAdvancedConfig);
|
||||
_nukiAdvancedConfigValid = result == Nuki::CmdResult::Success;
|
||||
Serial.println(result);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ private:
|
||||
void updateConfig();
|
||||
|
||||
void readConfig();
|
||||
void readAdvancedConfig();
|
||||
|
||||
Nuki::LockAction lockActionToEnum(const char* str); // char array at least 14 characters
|
||||
|
||||
@@ -52,7 +53,9 @@ private:
|
||||
Nuki::BatteryReport _lastBatteryReport;
|
||||
|
||||
Nuki::Config _nukiConfig = {0};
|
||||
Nuki::AdvancedConfig _nukiAdvancedConfig = {0};
|
||||
bool _nukiConfigValid = false;
|
||||
bool _nukiAdvancedConfigValid = false;
|
||||
|
||||
bool _paired = false;
|
||||
bool _statusUpdated = false;
|
||||
|
||||
Reference in New Issue
Block a user