publishh autodiscovery topics after reconnect
This commit is contained in:
2
Config.h
2
Config.h
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NUKI_HUB_VERSION "8.7"
|
#define NUKI_HUB_VERSION "8.8-pre-1"
|
||||||
|
|
||||||
#define MQTT_QOS_LEVEL 1
|
#define MQTT_QOS_LEVEL 1
|
||||||
#define MQTT_CLEAN_SESSIONS false
|
#define MQTT_CLEAN_SESSIONS false
|
||||||
@@ -375,6 +375,10 @@ bool Network::reconnect()
|
|||||||
}
|
}
|
||||||
delay(1000);
|
delay(1000);
|
||||||
_mqttConnectionState = 2;
|
_mqttConnectionState = 2;
|
||||||
|
for(const auto& callback : _reconnectedCallbacks)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -938,3 +942,8 @@ void Network::setKeepAliveCallback(std::function<void()> reconnectTick)
|
|||||||
{
|
{
|
||||||
_keepAliveCallback = reconnectTick;
|
_keepAliveCallback = reconnectTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::addReconnectedCallback(std::function<void()> reconnectedCallback)
|
||||||
|
{
|
||||||
|
_reconnectedCallbacks.push_back(reconnectedCallback);
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
uint16_t subscribe(const char* topic, uint8_t qos);
|
uint16_t subscribe(const char* topic, uint8_t qos);
|
||||||
|
|
||||||
void setKeepAliveCallback(std::function<void()> reconnectTick);
|
void setKeepAliveCallback(std::function<void()> reconnectTick);
|
||||||
|
void addReconnectedCallback(std::function<void()> reconnectedCallback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
||||||
@@ -91,7 +92,8 @@ private:
|
|||||||
unsigned long _lastMaintenanceTs = 0;
|
unsigned long _lastMaintenanceTs = 0;
|
||||||
unsigned long _lastRssiTs = 0;
|
unsigned long _lastRssiTs = 0;
|
||||||
long _rssiPublishInterval = 0;
|
long _rssiPublishInterval = 0;
|
||||||
std::function<void()> _keepAliveCallback;
|
std::function<void()> _keepAliveCallback = nullptr;
|
||||||
|
std::vector<std::function<void()>> _reconnectedCallbacks;
|
||||||
|
|
||||||
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ void NetworkLock::initialize()
|
|||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_network->addReconnectedCallback([&]()
|
||||||
|
{
|
||||||
|
_reconnected = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
|
||||||
@@ -557,3 +562,10 @@ String NetworkLock::concat(String a, String b)
|
|||||||
c.concat(b);
|
c.concat(b);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NetworkLock::reconnected()
|
||||||
|
{
|
||||||
|
bool r = _reconnected;
|
||||||
|
_reconnected = false;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public:
|
|||||||
|
|
||||||
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
|
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
|
||||||
|
|
||||||
|
bool reconnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
||||||
|
|
||||||
@@ -66,6 +68,7 @@ private:
|
|||||||
bool _firstTunerStatePublish = true;
|
bool _firstTunerStatePublish = true;
|
||||||
unsigned long _lastMaintenanceTs = 0;
|
unsigned long _lastMaintenanceTs = 0;
|
||||||
bool _haEnabled= false;
|
bool _haEnabled= false;
|
||||||
|
bool _reconnected = false;
|
||||||
|
|
||||||
String _keypadCommandName = "";
|
String _keypadCommandName = "";
|
||||||
String _keypadCommandCode = "";
|
String _keypadCommandCode = "";
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ void NetworkOpener::initialize()
|
|||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
|
||||||
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_network->addReconnectedCallback([&]()
|
||||||
|
{
|
||||||
|
_reconnected = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkOpener::update()
|
void NetworkOpener::update()
|
||||||
@@ -600,3 +605,10 @@ String NetworkOpener::concat(String a, String b)
|
|||||||
c.concat(b);
|
c.concat(b);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NetworkOpener::reconnected()
|
||||||
|
{
|
||||||
|
bool r = _reconnected;
|
||||||
|
_reconnected = false;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
@@ -41,6 +41,8 @@ public:
|
|||||||
|
|
||||||
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
|
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
|
||||||
|
|
||||||
|
bool reconnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
||||||
|
|
||||||
@@ -70,6 +72,8 @@ private:
|
|||||||
|
|
||||||
bool _firstTunerStatePublish = true;
|
bool _firstTunerStatePublish = true;
|
||||||
bool _haEnabled= false;
|
bool _haEnabled= false;
|
||||||
|
bool _reconnected = false;
|
||||||
|
|
||||||
String _keypadCommandName = "";
|
String _keypadCommandName = "";
|
||||||
String _keypadCommandCode = "";
|
String _keypadCommandCode = "";
|
||||||
uint _keypadCommandId = 0;
|
uint _keypadCommandId = 0;
|
||||||
|
|||||||
@@ -167,7 +167,10 @@ void NukiOpenerWrapper::update()
|
|||||||
setupHASS();
|
setupHASS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(_hassEnabled && _configRead && _network->reconnected())
|
||||||
|
{
|
||||||
|
setupHASS();
|
||||||
|
}
|
||||||
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
|
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
|
||||||
{
|
{
|
||||||
_nextRssiTs = ts + _rssiPublishInterval;
|
_nextRssiTs = ts + _rssiPublishInterval;
|
||||||
|
|||||||
@@ -168,6 +168,10 @@ void NukiWrapper::update()
|
|||||||
setupHASS();
|
setupHASS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(_hassEnabled && _configRead && _network->reconnected())
|
||||||
|
{
|
||||||
|
setupHASS();
|
||||||
|
}
|
||||||
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
|
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
|
||||||
{
|
{
|
||||||
_nextRssiTs = ts + _rssiPublishInterval;
|
_nextRssiTs = ts + _rssiPublishInterval;
|
||||||
|
|||||||
Reference in New Issue
Block a user