Skip to content

Commit

Permalink
rename subscribes to subscribe_format
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Mar 28, 2021
1 parent 2a070ef commit 1938c93
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions interface/src/mqtt/MqttSettingsForm.tsx
Expand Up @@ -175,10 +175,10 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
</SelectValidator>
<SelectValidator name="subscribe_format"
label="Subscribe Format"
value={data.subscribes}
value={data.subscribe_format}
fullWidth
variant="outlined"
onChange={handleValueChange('subscribes')}
onChange={handleValueChange('subscribe_format')}
margin="normal">
<MenuItem value={0}>general device topic</MenuItem>
<MenuItem value={1}>individual topics, main heating circuit</MenuItem>
Expand Down
2 changes: 1 addition & 1 deletion interface/src/mqtt/types.ts
Expand Up @@ -41,5 +41,5 @@ export interface MqttSettings {
ha_enabled: boolean;
ha_climate_format: number;
nested_format: boolean;
subscribes: number;
subscribe_format: number;
}
8 changes: 4 additions & 4 deletions lib/framework/MqttSettingsService.cpp
Expand Up @@ -182,7 +182,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["ha_climate_format"] = settings.ha_climate_format;
root["ha_enabled"] = settings.ha_enabled;
root["nested_format"] = settings.nested_format;
root["subscribes"] = settings.subscribes;
root["subscribe_format"] = settings.subscribe_format;
}

StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) {
Expand Down Expand Up @@ -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_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;
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) {
emsesp::EMSESP::mqtt_.set_qos(newSettings.mqtt_qos);
Expand All @@ -230,10 +230,10 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
changed = true;
}

if (newSettings.subscribes != settings.subscribes) {
if (newSettings.subscribe_format != settings.subscribe_format) {
changed = true;
}

if (newSettings.ha_climate_format != settings.ha_climate_format) {
emsesp::EMSESP::mqtt_.ha_climate_format(newSettings.ha_climate_format);
changed = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/framework/MqttSettingsService.h
Expand Up @@ -69,6 +69,7 @@ static String generateClientId() {
#define EMSESP_DEFAULT_HA_ENABLED false
#define EMSESP_DEFAULT_PUBLISH_TIME 10
#define EMSESP_DEFAULT_NESTED_FORMAT true
#define EMSESP_DEFAULT_SUBSCRIBE_FORMAT 0

class MqttSettings {
public:
Expand Down Expand Up @@ -104,7 +105,7 @@ class MqttSettings {
uint8_t ha_climate_format;
bool ha_enabled;
bool nested_format;
uint8_t subscribes;
uint8_t subscribe_format;

static void read(MqttSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, MqttSettings & settings);
Expand Down
2 changes: 1 addition & 1 deletion lib_standalone/ESP8266React.h
Expand Up @@ -37,7 +37,7 @@ class DummySettings {
uint8_t ha_climate_format = 1;
bool ha_enabled = true;
String base = "ems-esp";
uint8_t subscribes = 0;
uint8_t subscribe_format = 0;

String hostname = "ems-esp";
String jwtSecret = "ems-esp";
Expand Down
26 changes: 13 additions & 13 deletions src/mqtt.cpp
Expand Up @@ -40,7 +40,7 @@ uint8_t Mqtt::bool_format_;
uint8_t Mqtt::ha_climate_format_;
bool Mqtt::ha_enabled_;
bool Mqtt::nested_format_;
uint8_t Mqtt::subscribes_;
uint8_t Mqtt::subscribe_format_;

std::deque<Mqtt::QueuedMqttMessage> Mqtt::mqtt_messages_;
std::vector<Mqtt::MQTTSubFunction> Mqtt::mqtt_subfunctions_;
Expand Down Expand Up @@ -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)
// https://github.com/emsesp/EMS-ESP32/issues/31
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);
queue_subscribe_message(topic);
topic = cmd_topic + "/hc2/" + uuid::read_flash_string(cmd);
Expand All @@ -119,7 +119,7 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper
queue_subscribe_message(topic);
topic = cmd_topic + "/hc4/" + uuid::read_flash_string(cmd);
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);
queue_subscribe_message(topic);
}
Expand All @@ -142,16 +142,16 @@ void Mqtt::resubscribe() {
}
for (const auto & cf : Command::commands()) {
std::string topic(MQTT_TOPIC_MAX_SIZE, '\0');
if (subscribes_ == 2 && cf.flag_ == MqttSubFlag::FLAG_HC) {
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc1/" + uuid::read_flash_string(cf.cmd_);
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_);
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_);
queue_subscribe_message(topic);
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc3/" + uuid::read_flash_string(cf.cmd_);
topic = EMSdevice::device_type_2_device_name(cf.device_type_) + "/hc3/" + uuid::read_flash_string(cf.cmd_);
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);
} 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_);
queue_subscribe_message(topic);
}
Expand Down Expand Up @@ -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());
}
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/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/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());
}
}
Expand Down Expand Up @@ -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);

// strip the topic substrings
char * topic_end = strchr(topic,'/');
char * topic_end = strchr(topic, '/');
if (topic_end != nullptr) {
topic_end[0] = '\0';
}
Expand Down Expand Up @@ -461,7 +461,7 @@ void Mqtt::load_settings() {
dallas_format_ = mqttSettings.dallas_format;
bool_format_ = mqttSettings.bool_format;
nested_format_ = mqttSettings.nested_format;
subscribes_ = mqttSettings.subscribes;
subscribe_format_ = mqttSettings.subscribe_format;

// convert to milliseconds
publish_time_boiler_ = mqttSettings.publish_time_boiler * 1000;
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt.h
Expand Up @@ -275,7 +275,7 @@ class Mqtt {
static uint8_t ha_climate_format_;
static bool ha_enabled_;
static bool nested_format_;
static uint8_t subscribes_;
static uint8_t subscribe_format_;
};

} // namespace emsesp
Expand Down

0 comments on commit 1938c93

Please sign in to comment.