Skip to content

Commit d31b3b2

Browse files
committed
Changed entity_id to name in DiscoveryComponent
1 parent fd894ea commit d31b3b2

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

MqttManager/MqttDiscoveryComponent.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
#include "MqttDiscoveryComponent.h"
22

3-
MqttDiscoveryComponent::MqttDiscoveryComponent(String component, String entity_id)
3+
MqttDiscoveryComponent::MqttDiscoveryComponent(String component, String name)
44
{
55
this->component = component;
6-
this->entity_id = entity_id;
6+
this->entity_id = name;
77

8-
String name = entity_id;
9-
name.replace("_", " ");
8+
this->entity_id.replace(" ", "_");
109

11-
this->setConfigurtionVariables("name", name);
10+
this->setConfigurtionVariable("name", name);
1211

1312
if (component == "light" || component == "switch")
1413
{
15-
this->setConfigurtionVariables("command_topic", discovery_prefix + "/" + component + "/" + entity_id + "/" + command_suffix);
14+
this->setConfigurtionVariable("command_topic", discovery_prefix + "/" + component + "/" + entity_id + "/" + command_suffix);
1615
}
1716
else
1817
{
19-
this->setConfigurtionVariables("command_topic", "");
18+
this->setConfigurtionVariable("command_topic", "");
2019
}
2120
}
2221

23-
void MqttDiscoveryComponent::setConfigurtionVariables(String configKey, String configValue)
22+
void MqttDiscoveryComponent::setConfigurtionVariable(String configKey, String configValue)
2423
{
2524
if (configValue.length() != 0)
2625
{

MqttManager/MqttDiscoveryComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class MqttDiscoveryComponent
1313
std::map<String, String> m_fields;
1414

1515
public:
16-
MqttDiscoveryComponent(String component, String entity_id);
17-
void setConfigurtionVariables(String configKey, String configValue);
16+
MqttDiscoveryComponent(String component, String name);
17+
void setConfigurtionVariable(String configKey, String configValue);
1818

1919
String discovery_prefix{"homeassistant"};
2020
String component;

MqttManager/MqttManager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ void MqttManager::setDeviceData(String deviceName, String hardware, String devic
6060

6161
if (m_mqttDiscoveryEnabled)
6262
{
63-
m_deviceNameSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_name");
63+
m_deviceNameSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " name");
6464
m_discoveryComponents.push_back(m_deviceNameSensor);
6565

66-
m_deviceIpSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_IP");
66+
m_deviceIpSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " IP");
6767
m_discoveryComponents.push_back(m_deviceIpSensor);
6868

69-
m_deviceMacSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_MAC");
69+
m_deviceMacSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " MAC");
7070
m_discoveryComponents.push_back(m_deviceMacSensor);
7171

72-
m_deviceHardwareSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_Hardware");
72+
m_deviceHardwareSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " Hardware");
7373
m_discoveryComponents.push_back(m_deviceHardwareSensor);
7474

75-
m_deviceFirmwareSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_Firmware");
75+
m_deviceFirmwareSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " Firmware");
7676
m_discoveryComponents.push_back(m_deviceFirmwareSensor);
7777

78-
m_deviceFirmwareVersionSensor = new MqttDiscoveryComponent("sensor", m_deviceName + "_Firmware_Version");
78+
m_deviceFirmwareVersionSensor = new MqttDiscoveryComponent("sensor", m_deviceName + " Firmware Version");
7979
m_discoveryComponents.push_back(m_deviceFirmwareVersionSensor);
8080
}
8181
}
@@ -265,6 +265,7 @@ void MqttManager::loop()
265265
{
266266
if (m_deviceStatusInfoTimer.check())
267267
{
268+
this->publishDiscoveryInfo();
268269
this->publishDeviceStatusInfo();
269270

270271
m_deviceStatusInfoTimer.start(); //restart timer

0 commit comments

Comments
 (0)