rename subscribes to subscribe_format

This commit is contained in:
proddy
2021-03-28 16:53:01 +02:00
parent 2a070ef55f
commit 1938c93faf
7 changed files with 24 additions and 23 deletions

View File

@@ -175,10 +175,10 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
</SelectValidator> </SelectValidator>
<SelectValidator name="subscribe_format" <SelectValidator name="subscribe_format"
label="Subscribe Format" label="Subscribe Format"
value={data.subscribes} value={data.subscribe_format}
fullWidth fullWidth
variant="outlined" variant="outlined"
onChange={handleValueChange('subscribes')} onChange={handleValueChange('subscribe_format')}
margin="normal"> margin="normal">
<MenuItem value={0}>general device topic</MenuItem> <MenuItem value={0}>general device topic</MenuItem>
<MenuItem value={1}>individual topics, main heating circuit</MenuItem> <MenuItem value={1}>individual topics, main heating circuit</MenuItem>

View File

@@ -41,5 +41,5 @@ export interface MqttSettings {
ha_enabled: boolean; ha_enabled: boolean;
ha_climate_format: number; ha_climate_format: number;
nested_format: boolean; nested_format: boolean;
subscribes: number; subscribe_format: number;
} }

View File

@@ -182,7 +182,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["ha_climate_format"] = settings.ha_climate_format; root["ha_climate_format"] = settings.ha_climate_format;
root["ha_enabled"] = settings.ha_enabled; root["ha_enabled"] = settings.ha_enabled;
root["nested_format"] = settings.nested_format; root["nested_format"] = settings.nested_format;
root["subscribes"] = settings.subscribes; root["subscribe_format"] = settings.subscribe_format;
} }
StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) { StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) {
@@ -214,7 +214,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT; newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT;
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED; newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT; newSettings.nested_format = root["nested_format"] | EMSESP_DEFAULT_NESTED_FORMAT;
newSettings.subscribes = root["subscribes"] | 0; newSettings.subscribe_format = root["subscribe_format"] | EMSESP_DEFAULT_SUBSCRIBE_FORMAT;
if (newSettings.mqtt_qos != settings.mqtt_qos) { if (newSettings.mqtt_qos != settings.mqtt_qos) {
emsesp::EMSESP::mqtt_.set_qos(newSettings.mqtt_qos); emsesp::EMSESP::mqtt_.set_qos(newSettings.mqtt_qos);
@@ -230,7 +230,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
changed = true; changed = true;
} }
if (newSettings.subscribes != settings.subscribes) { if (newSettings.subscribe_format != settings.subscribe_format) {
changed = true; changed = true;
} }

View File

@@ -69,6 +69,7 @@ static String generateClientId() {
#define EMSESP_DEFAULT_HA_ENABLED false #define EMSESP_DEFAULT_HA_ENABLED false
#define EMSESP_DEFAULT_PUBLISH_TIME 10 #define EMSESP_DEFAULT_PUBLISH_TIME 10
#define EMSESP_DEFAULT_NESTED_FORMAT true #define EMSESP_DEFAULT_NESTED_FORMAT true
#define EMSESP_DEFAULT_SUBSCRIBE_FORMAT 0
class MqttSettings { class MqttSettings {
public: public:
@@ -104,7 +105,7 @@ class MqttSettings {
uint8_t ha_climate_format; uint8_t ha_climate_format;
bool ha_enabled; bool ha_enabled;
bool nested_format; bool nested_format;
uint8_t subscribes; uint8_t subscribe_format;
static void read(MqttSettings & settings, JsonObject & root); static void read(MqttSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, MqttSettings & settings); static StateUpdateResult update(JsonObject & root, MqttSettings & settings);

View File

@@ -37,7 +37,7 @@ class DummySettings {
uint8_t ha_climate_format = 1; uint8_t ha_climate_format = 1;
bool ha_enabled = true; bool ha_enabled = true;
String base = "ems-esp"; String base = "ems-esp";
uint8_t subscribes = 0; uint8_t subscribe_format = 0;
String hostname = "ems-esp"; String hostname = "ems-esp";
String jwtSecret = "ems-esp"; String jwtSecret = "ems-esp";

View File

@@ -40,7 +40,7 @@ uint8_t Mqtt::bool_format_;
uint8_t Mqtt::ha_climate_format_; uint8_t Mqtt::ha_climate_format_;
bool Mqtt::ha_enabled_; bool Mqtt::ha_enabled_;
bool Mqtt::nested_format_; bool Mqtt::nested_format_;
uint8_t Mqtt::subscribes_; uint8_t Mqtt::subscribe_format_;
std::deque<Mqtt::QueuedMqttMessage> Mqtt::mqtt_messages_; std::deque<Mqtt::QueuedMqttMessage> Mqtt::mqtt_messages_;
std::vector<Mqtt::MQTTSubFunction> Mqtt::mqtt_subfunctions_; std::vector<Mqtt::MQTTSubFunction> Mqtt::mqtt_subfunctions_;
@@ -110,7 +110,7 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper
// register the individual commands too (e.g. ems-esp/boiler/wwonetime) // register the individual commands too (e.g. ems-esp/boiler/wwonetime)
// https://github.com/emsesp/EMS-ESP32/issues/31 // https://github.com/emsesp/EMS-ESP32/issues/31
std::string topic(MQTT_TOPIC_MAX_SIZE, '\0'); std::string topic(MQTT_TOPIC_MAX_SIZE, '\0');
if (subscribes_ == 2 && flag == MqttSubFlag::FLAG_HC) { if (subscribe_format_ == 2 && flag == MqttSubFlag::FLAG_HC) {
topic = cmd_topic + "/hc1/" + uuid::read_flash_string(cmd); topic = cmd_topic + "/hc1/" + uuid::read_flash_string(cmd);
queue_subscribe_message(topic); queue_subscribe_message(topic);
topic = cmd_topic + "/hc2/" + uuid::read_flash_string(cmd); topic = cmd_topic + "/hc2/" + uuid::read_flash_string(cmd);
@@ -119,7 +119,7 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper
queue_subscribe_message(topic); queue_subscribe_message(topic);
topic = cmd_topic + "/hc4/" + uuid::read_flash_string(cmd); topic = cmd_topic + "/hc4/" + uuid::read_flash_string(cmd);
queue_subscribe_message(topic); queue_subscribe_message(topic);
} else if (subscribes_ && flag != MqttSubFlag::FLAG_NOSUB) { } else if (subscribe_format_ && flag != MqttSubFlag::FLAG_NOSUB) {
topic = cmd_topic + "/" + uuid::read_flash_string(cmd); topic = cmd_topic + "/" + uuid::read_flash_string(cmd);
queue_subscribe_message(topic); queue_subscribe_message(topic);
} }
@@ -142,7 +142,7 @@ void Mqtt::resubscribe() {
} }
for (const auto & cf : Command::commands()) { for (const auto & cf : Command::commands()) {
std::string topic(MQTT_TOPIC_MAX_SIZE, '\0'); std::string topic(MQTT_TOPIC_MAX_SIZE, '\0');
if (subscribes_ == 2 && cf.flag_ == MqttSubFlag::FLAG_HC) { if (subscribe_format_ == 2 && cf.flag_ == MqttSubFlag::FLAG_HC) {
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc1/" + uuid::read_flash_string(cf.cmd_); topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc1/" + uuid::read_flash_string(cf.cmd_);
queue_subscribe_message(topic); queue_subscribe_message(topic);
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc2/" + uuid::read_flash_string(cf.cmd_); topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc2/" + uuid::read_flash_string(cf.cmd_);
@@ -151,7 +151,7 @@ void Mqtt::resubscribe() {
queue_subscribe_message(topic); queue_subscribe_message(topic);
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc4/" + uuid::read_flash_string(cf.cmd_); topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc4/" + uuid::read_flash_string(cf.cmd_);
queue_subscribe_message(topic); queue_subscribe_message(topic);
} else if (subscribes_ && cf.flag_ != MqttSubFlag::FLAG_NOSUB) { } else if (subscribe_format_ && cf.flag_ != MqttSubFlag::FLAG_NOSUB) {
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/" + uuid::read_flash_string(cf.cmd_); topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/" + uuid::read_flash_string(cf.cmd_);
queue_subscribe_message(topic); queue_subscribe_message(topic);
} }
@@ -227,12 +227,12 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
shell.printfln(F(" %s/%s"), mqtt_base_.c_str(), mqtt_subfunction.topic_.c_str()); shell.printfln(F(" %s/%s"), mqtt_base_.c_str(), mqtt_subfunction.topic_.c_str());
} }
for (const auto & cf : Command::commands()) { for (const auto & cf : Command::commands()) {
if (subscribes_ == 2 && cf.flag_ == MqttSubFlag::FLAG_HC) { if (subscribe_format_ == 2 && cf.flag_ == MqttSubFlag::FLAG_HC) {
shell.printfln(F(" %s/%s/hc1/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str()); shell.printfln(F(" %s/%s/hc1/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str());
shell.printfln(F(" %s/%s/hc2/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str()); shell.printfln(F(" %s/%s/hc2/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str());
shell.printfln(F(" %s/%s/hc3/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str()); shell.printfln(F(" %s/%s/hc3/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str());
shell.printfln(F(" %s/%s/hc4/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str()); shell.printfln(F(" %s/%s/hc4/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str());
} else if (subscribes_ && cf.flag_ != MqttSubFlag::FLAG_NOSUB) { } else if (subscribe_format_ && cf.flag_ != MqttSubFlag::FLAG_NOSUB) {
shell.printfln(F(" %s/%s/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str()); shell.printfln(F(" %s/%s/%s"), mqtt_base_.c_str(), EMSdevice::device_type_2_device_name(cf.device_type_).c_str(), uuid::read_flash_string(cf.cmd_).c_str());
} }
} }
@@ -294,7 +294,7 @@ void Mqtt::on_message(const char * fulltopic, const char * payload, size_t len)
strlcpy(topic, &fulltopic[1 + strlen(mqtt_base_.c_str())], 100); strlcpy(topic, &fulltopic[1 + strlen(mqtt_base_.c_str())], 100);
// strip the topic substrings // strip the topic substrings
char * topic_end = strchr(topic,'/'); char * topic_end = strchr(topic, '/');
if (topic_end != nullptr) { if (topic_end != nullptr) {
topic_end[0] = '\0'; topic_end[0] = '\0';
} }
@@ -461,7 +461,7 @@ void Mqtt::load_settings() {
dallas_format_ = mqttSettings.dallas_format; dallas_format_ = mqttSettings.dallas_format;
bool_format_ = mqttSettings.bool_format; bool_format_ = mqttSettings.bool_format;
nested_format_ = mqttSettings.nested_format; nested_format_ = mqttSettings.nested_format;
subscribes_ = mqttSettings.subscribes; subscribe_format_ = mqttSettings.subscribe_format;
// convert to milliseconds // convert to milliseconds
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000; publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;

View File

@@ -275,7 +275,7 @@ class Mqtt {
static uint8_t ha_climate_format_; static uint8_t ha_climate_format_;
static bool ha_enabled_; static bool ha_enabled_;
static bool nested_format_; static bool nested_format_;
static uint8_t subscribes_; static uint8_t subscribe_format_;
}; };
} // namespace emsesp } // namespace emsesp