mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-26 08:39:09 +03:00
@@ -650,7 +650,7 @@ void AnalogSensor::remove_ha_topic(const int8_t type, const uint8_t gpio) const
|
|||||||
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
||||||
} else if (type >= AnalogType::PWM_0 && type <= AnalogType::PWM_2) {
|
} else if (type >= AnalogType::PWM_0 && type <= AnalogType::PWM_2) {
|
||||||
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
||||||
} else if (type >= AnalogType::RGB) {
|
} else if (type == AnalogType::RGB) {
|
||||||
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
snprintf(topic, sizeof(topic), "number/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
||||||
} else if (type == AnalogType::DIGITAL_IN) {
|
} else if (type == AnalogType::DIGITAL_IN) {
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
snprintf(topic, sizeof(topic), "binary_sensor/%s/%s_%02d/config", Mqtt::basename().c_str(), F_(analogsensor), gpio);
|
||||||
@@ -682,7 +682,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
if (Mqtt::is_nested()) {
|
if (Mqtt::is_nested()) {
|
||||||
char s[10];
|
char s[10];
|
||||||
JsonObject dataSensor = obj[Helpers::smallitoa(s, sensor.gpio())].to<JsonObject>();
|
JsonObject dataSensor = obj[Helpers::smallitoa(s, sensor.gpio())].to<JsonObject>();
|
||||||
dataSensor["name"] = sensor.name();
|
dataSensor["name"] = (const char *)sensor.name();
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
if (sensor.type() == AnalogType::PULSE || (sensor.type() == AnalogType::DIGITAL_OUT && sensor.gpio() != 25 && sensor.gpio() != 26)) {
|
if (sensor.type() == AnalogType::PULSE || (sensor.type() == AnalogType::DIGITAL_OUT && sensor.gpio() != 25 && sensor.gpio() != 26)) {
|
||||||
#else
|
#else
|
||||||
@@ -739,7 +739,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
config["~"] = Mqtt::base();
|
config["~"] = Mqtt::base();
|
||||||
config["uniq_id"] = uniq_s;
|
config["uniq_id"] = uniq_s;
|
||||||
config["name"] = sensor.name();
|
config["name"] = (const char *)sensor.name();
|
||||||
|
|
||||||
if (sensor.uom() != DeviceValueUOM::NONE && sensor.type() != AnalogType::DIGITAL_OUT) {
|
if (sensor.uom() != DeviceValueUOM::NONE && sensor.type() != AnalogType::DIGITAL_OUT) {
|
||||||
config["unit_of_meas"] = EMSdevice::uom_to_string(sensor.uom());
|
config["unit_of_meas"] = EMSdevice::uom_to_string(sensor.uom());
|
||||||
@@ -856,8 +856,8 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
|
|||||||
|
|
||||||
// note we don't add the device and state classes here, as we do in the custom entity service
|
// note we don't add the device and state classes here, as we do in the custom entity service
|
||||||
void AnalogSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
void AnalogSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
||||||
output["name"] = sensor.name();
|
output["name"] = (const char *)sensor.name();
|
||||||
output["fullname"] = sensor.name();
|
output["fullname"] = (const char *)sensor.name();
|
||||||
output["gpio"] = sensor.gpio();
|
output["gpio"] = sensor.gpio();
|
||||||
output["type"] = F_(number);
|
output["type"] = F_(number);
|
||||||
output["analog"] = FL_(list_sensortype)[sensor.type()];
|
output["analog"] = FL_(list_sensortype)[sensor.type()];
|
||||||
|
|||||||
@@ -418,8 +418,8 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
|||||||
// note we don't add the device and state classes here, as we do in the custom entity service
|
// note we don't add the device and state classes here, as we do in the custom entity service
|
||||||
void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
||||||
output["id"] = sensor.id();
|
output["id"] = sensor.id();
|
||||||
output["name"] = sensor.name();
|
output["name"] = (const char *)sensor.name();
|
||||||
output["fullname"] = sensor.name();
|
output["fullname"] = (const char *)sensor.name();
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
char val[10];
|
char val[10];
|
||||||
output["value"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
output["value"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||||
@@ -488,7 +488,7 @@ void TemperatureSensor::publish_values(const bool force) {
|
|||||||
char val[10];
|
char val[10];
|
||||||
if (Mqtt::is_nested()) {
|
if (Mqtt::is_nested()) {
|
||||||
JsonObject dataSensor = doc[sensor.id()].to<JsonObject>();
|
JsonObject dataSensor = doc[sensor.id()].to<JsonObject>();
|
||||||
dataSensor["name"] = sensor.name();
|
dataSensor["name"] = (const char *)sensor.name();
|
||||||
dataSensor["temp"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
dataSensor["temp"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||||
} else {
|
} else {
|
||||||
doc[sensor.name()] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
doc[sensor.name()] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||||
@@ -542,7 +542,7 @@ void TemperatureSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
config["uniq_id"] = uniq_s;
|
config["uniq_id"] = uniq_s;
|
||||||
config["def_ent_id"] = (std::string) "sensor." + uniq_s;
|
config["def_ent_id"] = (std::string) "sensor." + uniq_s;
|
||||||
config["name"] = sensor.name();
|
config["name"] = (const char *)sensor.name();
|
||||||
|
|
||||||
// dev section with model is only created on the 1st sensor
|
// dev section with model is only created on the 1st sensor
|
||||||
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Temperature Sensors", nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_dev_created);
|
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Temperature Sensors", nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_dev_created);
|
||||||
|
|||||||
@@ -465,9 +465,7 @@ void WebCustomEntityService::publish(const bool force) {
|
|||||||
|
|
||||||
Mqtt::add_ha_classes(config.as<JsonObject>(), EMSdevice::DeviceType::SYSTEM, entityItem.value_type, entityItem.uom);
|
Mqtt::add_ha_classes(config.as<JsonObject>(), EMSdevice::DeviceType::SYSTEM, entityItem.value_type, entityItem.uom);
|
||||||
|
|
||||||
if (!ha_created) {
|
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Custom Entities", nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_created);
|
||||||
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Custom Entities", nullptr, "EMS-ESP", EMSESP_APP_VERSION, true);
|
|
||||||
}
|
|
||||||
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
||||||
|
|
||||||
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|||||||
@@ -276,9 +276,7 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
config["cmd_t"] = command_topic;
|
config["cmd_t"] = command_topic;
|
||||||
|
|
||||||
Mqtt::add_ha_bool(config.as<JsonObject>());
|
Mqtt::add_ha_bool(config.as<JsonObject>());
|
||||||
if (!ha_created) {
|
Mqtt::add_ha_dev_section(config.as<JsonObject>(), F_(scheduler), nullptr, "EMS-ESP", EMSESP_APP_VERSION, !ha_created);
|
||||||
Mqtt::add_ha_dev_section(config.as<JsonObject>(), F_(scheduler), nullptr, "EMS-ESP", EMSESP_APP_VERSION, true);
|
|
||||||
}
|
|
||||||
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
Mqtt::add_ha_avty_section(config.as<JsonObject>(), stat_t, val_cond);
|
||||||
|
|
||||||
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
ha_created |= Mqtt::queue_ha(topic, config.as<JsonObject>());
|
||||||
|
|||||||
Reference in New Issue
Block a user