HASS auto discovery - Separate unit filtering from class (#1159)
This commit is contained in:
1 parent
5eea3d45cc
commit
5b42e024e2
2 files changed
+30
-1
No files matched your search
+10
-1
@@ -254,6 +254,15 @@ void createDiscovery(const char* sensor_type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We check if the class belongs to HAAS class list
|
||||||
|
bool HASSUnit = false;
|
||||||
|
int num_units = sizeof(availableHASSUnits) / sizeof(availableHASSUnits[0]);
|
||||||
|
for (int i = 0; i < num_units; i++) { // see class list and size into config_mqttDiscovery.h
|
||||||
|
if (strcmp(availableHASSUnits[i], unit_of_meas) == 0) {
|
||||||
|
HASSUnit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sensor["name"] = s_name; //name
|
sensor["name"] = s_name; //name
|
||||||
sensor["uniq_id"] = unique_id; //unique_id
|
sensor["uniq_id"] = unique_id; //unique_id
|
||||||
if (retainCmd)
|
if (retainCmd)
|
||||||
@@ -266,7 +275,7 @@ void createDiscovery(const char* sensor_type,
|
|||||||
sensor["pl_on"] = payload_on; // payload_on
|
sensor["pl_on"] = payload_on; // payload_on
|
||||||
if (payload_off[0])
|
if (payload_off[0])
|
||||||
sensor["pl_off"] = payload_off; //payload_off
|
sensor["pl_off"] = payload_off; //payload_off
|
||||||
if (unit_of_meas[0] && HASSClass)
|
if (unit_of_meas[0] && HASSUnit)
|
||||||
sensor["unit_of_meas"] = unit_of_meas; //unit_of_measurement*/
|
sensor["unit_of_meas"] = unit_of_meas; //unit_of_measurement*/
|
||||||
if (off_delay != 0)
|
if (off_delay != 0)
|
||||||
sensor["off_delay"] = off_delay; //off_delay
|
sensor["off_delay"] = off_delay; //off_delay
|
||||||
|
|||||||
@@ -216,4 +216,24 @@ const char* availableHASSClasses[] = {"battery",
|
|||||||
"power_factor",
|
"power_factor",
|
||||||
"voltage"};
|
"voltage"};
|
||||||
|
|
||||||
|
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379
|
||||||
|
// List of units available in Home Assistant
|
||||||
|
const char* availableHASSUnits[] = {"W",
|
||||||
|
"kW",
|
||||||
|
"V",
|
||||||
|
"A",
|
||||||
|
"W",
|
||||||
|
"°C",
|
||||||
|
"°F",
|
||||||
|
"ms",
|
||||||
|
"s",
|
||||||
|
"hPa"
|
||||||
|
"kg",
|
||||||
|
"lb",
|
||||||
|
"µS/cm",
|
||||||
|
"lx",
|
||||||
|
"%",
|
||||||
|
"dB",
|
||||||
|
"B"};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user