[DISC] make mi scale weighing_mode and unit enum (#1766)
* make mi scale weighing_mode and unit enum * lint
This commit is contained in:
1 parent
c4a84651d4
commit
00b2ec93cb
3 files changed
+26
-3
No files matched your search
@@ -1108,6 +1108,24 @@ void launchBTDiscovery(bool overrideDiscovery) {
|
||||
Gateway_AnnouncementMsg, will_Message, false, subjectMQTTtoBTset,
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassNone, "off", "on");
|
||||
} else if ((p->sensorModel_id == TheengsDecoder::XMTZC04HM || p->sensorModel_id == TheengsDecoder::XMTZC05HM) &&
|
||||
strcmp(prop.key().c_str(), "weighing_mode") == 0) {
|
||||
createDiscovery("sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
will_Topic, "enum", value_template.c_str(),
|
||||
"", "", prop.value()["unit"],
|
||||
0, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassMeasurement, nullptr, nullptr, "[\"person\",\"object\"]");
|
||||
} else if ((p->sensorModel_id == TheengsDecoder::XMTZC04HM || p->sensorModel_id == TheengsDecoder::XMTZC05HM) &&
|
||||
strcmp(prop.key().c_str(), "unit") == 0) {
|
||||
createDiscovery("sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
will_Topic, "enum", value_template.c_str(),
|
||||
"", "", prop.value()["unit"],
|
||||
0, "", "", false, "",
|
||||
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
|
||||
stateClassMeasurement, nullptr, nullptr, "[\"lb\",\"kg\",\"jin\"]");
|
||||
} else if (strcmp(prop.key().c_str(), "device") != 0 || strcmp(prop.key().c_str(), "mac") != 0) { // Exception on device and mac as these ones are not sensors
|
||||
createDiscovery("sensor",
|
||||
discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(),
|
||||
|
||||
@@ -239,7 +239,7 @@ void createDiscovery(const char* sensor_type,
|
||||
int off_delay,
|
||||
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic,
|
||||
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd,
|
||||
const char* state_class, const char* state_off, const char* state_on) {
|
||||
const char* state_class, const char* state_off, const char* state_on, const char* enum_options) {
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject sensor = jsonBuffer.to<JsonObject>();
|
||||
|
||||
@@ -344,6 +344,10 @@ void createDiscovery(const char* sensor_type,
|
||||
sensor["cmd_t"] = command_topic; //command_topic
|
||||
}
|
||||
|
||||
if (enum_options != nullptr) {
|
||||
sensor["options"] = enum_options;
|
||||
}
|
||||
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
|
||||
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
|
||||
JsonArray identifiers = device.createNestedArray("ids");
|
||||
|
||||
@@ -88,7 +88,7 @@ extern void createDiscovery(const char* sensor_type,
|
||||
int off_delay,
|
||||
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* command_topic,
|
||||
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_mac, bool retainCmd,
|
||||
const char* state_class, const char* state_off = nullptr, const char* state_on = nullptr);
|
||||
const char* state_class, const char* state_off = nullptr, const char* state_on = nullptr, const char* enum_options = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Create a message for Discovery Device Trigger. For HA @see https://www.home-assistant.io/integrations/device_trigger.mqtt/
|
||||
@@ -196,7 +196,8 @@ const char* availableHASSClasses[] = {"battery",
|
||||
"current",
|
||||
"energy",
|
||||
"power_factor",
|
||||
"voltage"};
|
||||
"voltage",
|
||||
"enum"};
|
||||
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379
|
||||
// List of units available in Home Assistant
|
||||
|
||||
Reference in new issue
Block a user