mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-30 10:13:04 +05:00
feat: publish MQTT field changes with periodic refresh
Track 89 settings and state fields with partial structure snapshots and a fixed-capacity map of publication timestamps. Publish changed or expired values in bounded passes, updating snapshots only after successful queue acceptance and keeping failed fields eligible for retry. Refresh fields after reconnecting and affected temperatures after unit or Equitherm mode changes. Keep the status heartbeat independent, cache DHW limits for MQTT and API consumers, and clear non-finite retained readings. Default the forced publication interval to 60 seconds and accept 15 to 3600 seconds in the API and UI. Set Home Assistant state expiration to twice this interval and refresh discovery when the interval changes. Remove network connection and dedicated fault/diagnostic availability publications. Use existing active states and RSSI for HA availability.
This commit is contained in:
1 parent
a629589122
commit
d40b7cb85a
8 files changed
+1056
-192
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
template <std::size_t Capacity>
|
||||
class StructTimestampMap {
|
||||
public:
|
||||
// Adding a key can move entries; use the reference before the next insertion.
|
||||
unsigned long& get(const void* field) {
|
||||
const auto end = times.begin() + count;
|
||||
const auto entry = std::lower_bound(times.begin(), end, field, [](const auto& item, const void* ptr) {
|
||||
return reinterpret_cast<std::uintptr_t>(item.first) < reinterpret_cast<std::uintptr_t>(ptr);
|
||||
});
|
||||
|
||||
if (entry != end && entry->first == field) {
|
||||
return entry->second;
|
||||
}
|
||||
|
||||
assert(count < times.size());
|
||||
std::move_backward(entry, end, end + 1);
|
||||
*entry = {field, 0};
|
||||
++count;
|
||||
return entry->second;
|
||||
}
|
||||
|
||||
void reset(std::initializer_list<const void*> fields) {
|
||||
for (const void* field : fields) {
|
||||
get(field) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void resetAll() {
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
times[index].second = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::pair<const void*, unsigned long>, Capacity> times{};
|
||||
std::size_t count = 0;
|
||||
};
|
||||
Reference in new issue
Block a user