diff --git a/Network.cpp b/Network.cpp index 80541de..1446cc9 100644 --- a/Network.cpp +++ b/Network.cpp @@ -292,12 +292,8 @@ void Network::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurnerSta if(_firstTunerStatePublish || keyTurnerState.criticalBatteryState != lastKeyTurnerState.criticalBatteryState) { - uint8_t level = (keyTurnerState.criticalBatteryState & 0b11111100) >> 1; bool critical = (keyTurnerState.criticalBatteryState & 0b00000001) > 0; - bool charging = (keyTurnerState.criticalBatteryState & 0b00000010) > 0; - publishInt(mqtt_topic_battery_level, level); // percent publishBool(mqtt_topic_battery_critical, critical); - publishBool(mqtt_topic_battery_charging, charging); } _firstTunerStatePublish = false; diff --git a/NetworkOpener.cpp b/NetworkOpener.cpp index e7d100d..fd8093a 100644 --- a/NetworkOpener.cpp +++ b/NetworkOpener.cpp @@ -157,21 +157,18 @@ void NetworkOpener::publishBatteryReport(const NukiOpener::BatteryReport& batter { publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0); publishInt(mqtt_topic_battery_drain, batteryReport.batteryDrain); // milliwatt seconds - publishFloat(mqtt_topic_battery_max_turn_current, (float)batteryReport.maxTurnCurrent / 1000.0); - publishInt(mqtt_topic_battery_lock_distance, batteryReport.lockDistance); // degrees } void NetworkOpener::publishConfig(const NukiOpener::Config &config) { publishBool(mqtt_topic_config_button_enabled, config.buttonEnabled == 1); - publishBool(mqtt_topic_config_led_enabled, config.ledEnabled == 1); - publishInt(mqtt_topic_config_led_brightness, config.ledBrightness); + publishBool(mqtt_topic_config_led_enabled, config.ledFlashEnabled == 1); } void NetworkOpener::publishAdvancedConfig(const NukiOpener::AdvancedConfig &config) { - publishBool(mqtt_topic_config_auto_unlock, config.autoUnLockDisabled == 0); - publishBool(mqtt_topic_config_auto_lock, config.autoLockEnabled == 1); +// publishBool(mqtt_topic_config_auto_unlock, config.autoUnLockDisabled == 0); +// publishBool(mqtt_topic_config_auto_lock, config.autoLockEnabled == 1); } void NetworkOpener::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *)) diff --git a/NukiOpenerWrapper.cpp b/NukiOpenerWrapper.cpp index 3f76e48..bf6450c 100644 --- a/NukiOpenerWrapper.cpp +++ b/NukiOpenerWrapper.cpp @@ -89,22 +89,22 @@ void NukiOpenerWrapper::update() unsigned long ts = millis(); -// if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) -// { -// _statusUpdated = false; -// _nextLockStateUpdateTs = ts + _intervalLockstate * 1000; -// updateKeyTurnerState(); -// } -// if(_nextBatteryReportTs == 0 || ts > _nextBatteryReportTs) -// { -// _nextBatteryReportTs = ts + _intervalBattery * 1000; -// updateBatteryState(); -// } -// if(_nextConfigUpdateTs == 0 || ts > _nextConfigUpdateTs) -// { -// _nextConfigUpdateTs = ts + _intervalConfig * 1000; -// updateConfig(); -// } + if(_statusUpdated || _nextLockStateUpdateTs == 0 || ts >= _nextLockStateUpdateTs) + { + _statusUpdated = false; + _nextLockStateUpdateTs = ts + _intervalLockstate * 1000; + updateKeyTurnerState(); + } + if(_nextBatteryReportTs == 0 || ts > _nextBatteryReportTs) + { + _nextBatteryReportTs = ts + _intervalBattery * 1000; + updateBatteryState(); + } + if(_nextConfigUpdateTs == 0 || ts > _nextConfigUpdateTs) + { + _nextConfigUpdateTs = ts + _intervalConfig * 1000; + updateConfig(); + } if(_nextLockAction != (NukiOpener::LockAction)0xff) { @@ -148,7 +148,7 @@ void NukiOpenerWrapper::unpair() void NukiOpenerWrapper::updateKeyTurnerState() { _nukiOpener.requestKeyTurnerState(&_keyTurnerState); -// _network->publishKeyTurnerState(_keyTurnerState, _lastKeyTurnerState); + _network->publishKeyTurnerState(_keyTurnerState, _lastKeyTurnerState); if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState) { @@ -167,15 +167,15 @@ void NukiOpenerWrapper::updateKeyTurnerState() void NukiOpenerWrapper::updateBatteryState() { _nukiOpener.requestBatteryReport(&_batteryReport); -// _network->publishBatteryReport(_batteryReport); + _network->publishBatteryReport(_batteryReport); } void NukiOpenerWrapper::updateConfig() { readConfig(); readAdvancedConfig(); -// _network->publishConfig(_nukiConfig); -// _network->publishAdvancedConfig(_nukiAdvancedConfig); + _network->publishConfig(_nukiConfig); + _network->publishAdvancedConfig(_nukiAdvancedConfig); } void NukiOpenerWrapper::updateAuthData() @@ -254,38 +254,10 @@ void NukiOpenerWrapper::onConfigUpdateReceived(const char *topic, const char *va if(strcmp(topic, mqtt_topic_config_led_enabled) == 0) { bool newValue = atoi(value) > 0; - if(!_nukiConfigValid || _nukiConfig.ledEnabled == newValue) return; + if(!_nukiConfigValid || _nukiConfig.ledFlashEnabled == newValue) return; _nukiOpener.enableLedFlash(newValue); _nextConfigUpdateTs = millis() + 300; } - else if(strcmp(topic, mqtt_topic_config_led_brightness) == 0) - { - int newValue = atoi(value); - if(!_nukiConfigValid || _nukiConfig.ledBrightness == newValue) return; - _nukiOpener.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; - _nukiOpener.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; - _nukiOpener.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; - _nukiOpener.enableAutoLock(newValue); - _nextConfigUpdateTs = millis() + 300; - } } const NukiOpener::KeyTurnerState &NukiOpenerWrapper::keyTurnerState()