mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
@@ -46,6 +46,7 @@ const GeneralFileUpload: FC<UploadFileProps> = ({ uploadGeneralFile }) => {
|
|||||||
const response = await EMSESP.getSettings();
|
const response = await EMSESP.getSettings();
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
toast.error(LL.PROBLEM_LOADING());
|
toast.error(LL.PROBLEM_LOADING());
|
||||||
|
} else {
|
||||||
saveFile(response.data, 'settings');
|
saveFile(response.data, 'settings');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -71,6 +72,7 @@ const GeneralFileUpload: FC<UploadFileProps> = ({ uploadGeneralFile }) => {
|
|||||||
const response = await EMSESP.readSchedule();
|
const response = await EMSESP.readSchedule();
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
toast.error(LL.PROBLEM_LOADING());
|
toast.error(LL.PROBLEM_LOADING());
|
||||||
|
} else {
|
||||||
saveFile(response.data, 'schedule');
|
saveFile(response.data, 'schedule');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
if (len > 12 && (data[0] != 0xE9 || data[12] != 3)) {
|
if (len > 12 && (data[0] != 0xE9 || data[12] != 9)) {
|
||||||
handleError(request, 503); // service unavailable
|
handleError(request, 503); // service unavailable
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
|
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
|
||||||
|
|
||||||
char uniq_s[70];
|
char uniq_s[70];
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == Mqtt::entitiyFormat::MULTI_SHORT) {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%02d", Mqtt::basename().c_str(), sensor.gpio());
|
snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%02d", Mqtt::basename().c_str(), sensor.gpio());
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%02d", sensor.gpio());
|
snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%02d", sensor.gpio());
|
||||||
|
|||||||
@@ -528,7 +528,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}";
|
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}";
|
||||||
|
|
||||||
char uniq_s[70];
|
char uniq_s[70];
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == Mqtt::entitiyFormat::MULTI_SHORT) {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str());
|
snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str());
|
||||||
|
|||||||
10
src/mqtt.cpp
10
src/mqtt.cpp
@@ -612,7 +612,7 @@ void Mqtt::ha_status() {
|
|||||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
||||||
|
|
||||||
char uniq[70];
|
char uniq[70];
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == entitiyFormat::MULTI_SHORT) {
|
||||||
snprintf(uniq, sizeof(uniq), "%s_system_status", mqtt_basename_.c_str());
|
snprintf(uniq, sizeof(uniq), "%s_system_status", mqtt_basename_.c_str());
|
||||||
} else {
|
} else {
|
||||||
strcpy(uniq, "system_status");
|
strcpy(uniq, "system_status");
|
||||||
@@ -998,10 +998,10 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
|
|
||||||
// build unique identifier also used as object_id which also becomes the Entity ID in HA
|
// build unique identifier also used as object_id which also becomes the Entity ID in HA
|
||||||
char uniq_id[80];
|
char uniq_id[80];
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == entitiyFormat::MULTI_SHORT) {
|
||||||
// prefix base name to each uniq_id and use the shortname
|
// prefix base name to each uniq_id and use the shortname
|
||||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||||
} else if (Mqtt::entity_format() == 1) {
|
} else if (Mqtt::entity_format() == entitiyFormat::SINGLE_SHORT) {
|
||||||
// shortname, no mqtt base. This is the default version.
|
// shortname, no mqtt base. This is the default version.
|
||||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||||
} else {
|
} else {
|
||||||
@@ -1035,7 +1035,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
case DeviceValueType::SHORT:
|
case DeviceValueType::SHORT:
|
||||||
case DeviceValueType::USHORT:
|
case DeviceValueType::USHORT:
|
||||||
case DeviceValueType::ULONG:
|
case DeviceValueType::ULONG:
|
||||||
if (discovery_type() == 0) {
|
if (discovery_type() == discoveryType::HOMEASSISTANT) {
|
||||||
// Home Assistant
|
// Home Assistant
|
||||||
// number - https://www.home-assistant.io/integrations/number.mqtt
|
// number - https://www.home-assistant.io/integrations/number.mqtt
|
||||||
snprintf(topic, sizeof(topic), "number/%s", config_topic);
|
snprintf(topic, sizeof(topic), "number/%s", config_topic);
|
||||||
@@ -1368,7 +1368,7 @@ void Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
|
|||||||
|
|
||||||
snprintf(name_s, sizeof(name_s), "Hc%d", hc_num);
|
snprintf(name_s, sizeof(name_s), "Hc%d", hc_num);
|
||||||
|
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == entitiyFormat::MULTI_SHORT) {
|
||||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ struct MqttMessage {
|
|||||||
|
|
||||||
class Mqtt {
|
class Mqtt {
|
||||||
public:
|
public:
|
||||||
|
enum discoveryType : uint8_t { HOMEASSISTANT, DOMOTICZ };
|
||||||
|
enum entitiyFormat : uint8_t { SINGLE_LONG, SINGLE_SHORT, MULTI_SHORT };
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ void Shower::set_shower_state(bool state, bool force) {
|
|||||||
doc["name"] = "Shower Active";
|
doc["name"] = "Shower Active";
|
||||||
|
|
||||||
char str[70];
|
char str[70];
|
||||||
if (Mqtt::entity_format() == 2) {
|
if (Mqtt::entity_format() == Mqtt::entitiyFormat::MULTI_SHORT) {
|
||||||
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
|
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
|
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
|
||||||
|
|||||||
@@ -529,7 +529,8 @@ void System::loop() {
|
|||||||
|
|
||||||
// send MQTT info topic appended with the version information as JSON, as a retained flag
|
// send MQTT info topic appended with the version information as JSON, as a retained flag
|
||||||
void System::send_info_mqtt(const char * event_str, bool send_ntp) {
|
void System::send_info_mqtt(const char * event_str, bool send_ntp) {
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> doc;
|
// use dynamic json becaues it is called from NTP-callback from lwip task with small stack
|
||||||
|
DynamicJsonDocument doc = DynamicJsonDocument(EMSESP_JSON_SIZE_MEDIUM);
|
||||||
doc["event"] = event_str;
|
doc["event"] = event_str;
|
||||||
doc["version"] = EMSESP_APP_VERSION;
|
doc["version"] = EMSESP_APP_VERSION;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user