Browse Source

Fix HA names (#1183)

webui
Xose Pérez 6 years ago
parent
commit
10ec1b2039
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      code/espurna/homeassistant.ino

+ 14
- 3
code/espurna/homeassistant.ino View File

@ -13,6 +13,17 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
bool _haEnabled = false;
bool _haSendFlag = false;
// -----------------------------------------------------------------------------
// UTILS
// -----------------------------------------------------------------------------
String _haFixName(String name) {
for (unsigned char i=0; i<name.length(); i++) {
if (!isalnum(name.charAt(i))) name.setCharAt(i, '_');
}
return name;
}
// -----------------------------------------------------------------------------
// SENSORS
// -----------------------------------------------------------------------------
@ -22,7 +33,7 @@ bool _haSendFlag = false;
void _haSendMagnitude(unsigned char i, JsonObject& config) {
unsigned char type = magnitudeType(i);
config["name"] = getSetting("hostname") + String(" ") + magnitudeTopic(type);
config["name"] = _haFixName(getSetting("hostname") + String(" ") + magnitudeTopic(type));
config.set("platform", "mqtt");
config["state_topic"] = mqttTopic(magnitudeTopicIndex(i).c_str(), false);
config["unit_of_measurement"] = magnitudeUnits(type);
@ -64,10 +75,10 @@ void _haSendSwitch(unsigned char i, JsonObject& config) {
String name = getSetting("hostname");
if (relayCount() > 1) {
name += String(" #") + String(i);
name += String("_") + String(i);
}
config.set("name", name);
config.set("name", _haFixName(name));
config.set("platform", "mqtt");
if (relayCount()) {


Loading…
Cancel
Save