Skip to content

Commit

Permalink
relay: publish names to mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Jan 9, 2023
1 parent 657de76 commit 7514dee
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion code/espurna/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,16 @@ void _relayMqttReportAll() {
}
}

void _relayMqttReportDescription() {
static const char Topic[] = MQTT_TOPIC_DESCRIPTION "/" MQTT_TOPIC_RELAY;
for (size_t id = 0; id < _relays.size(); ++id) {
const auto name = espurna::relay::settings::name(id);
if (name.length()) {
mqttSend(Topic, id, name.c_str());
}
}
}

} // namespace

void relayStatusWrap(size_t id, PayloadStatus value, bool is_group_topic) {
Expand Down Expand Up @@ -2449,8 +2459,13 @@ void relayStatusWrap(size_t id, PayloadStatus value, bool is_group_topic) {
namespace {

bool _relayMqttHeartbeat(espurna::heartbeat::Mask mask) {
if (mask & espurna::heartbeat::Report::Relay)
if (mask & espurna::heartbeat::Report::Relay) {
_relayMqttReportAll();
}

if (mask & espurna::heartbeat::Report::Description) {
_relayMqttReportDescription();
}

return mqttConnected();
}
Expand Down

0 comments on commit 7514dee

Please sign in to comment.