Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for compilation errors when HA_AUTODISCOVERY is commented out #834

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Software/src/devboard/mqtt/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static void publish_values(void) {
}

#ifdef HA_AUTODISCOVERY

static bool ha_common_info_published = false;
static bool ha_cell_voltages_published = false;
static bool ha_events_published = false;
Expand Down Expand Up @@ -132,6 +131,7 @@ void set_common_discovery_attributes(JsonDocument& doc) {
doc["payload_not_available"] = "offline";
doc["enabled_by_default"] = true;
}
#endif // HA_AUTODISCOVERY

void set_battery_attributes(JsonDocument& doc, const DATALAYER_BATTERY_TYPE& battery, const String& suffix) {
doc["SOC" + suffix] = ((float)battery.status.reported_soc) / 100.0;
Expand All @@ -155,6 +155,7 @@ void set_battery_attributes(JsonDocument& doc, const DATALAYER_BATTERY_TYPE& bat
doc["max_charge_power" + suffix] = ((float)battery.status.max_charge_power_W);
}

#ifdef HA_AUTODISCOVERY
void set_battery_voltage_attributes(JsonDocument& doc, int i, int cellNumber, const String& state_topic,
const String& object_id_prefix, const String& battery_name_suffix) {
doc["name"] = "Battery" + battery_name_suffix + " Cell Voltage " + String(cellNumber);
Expand All @@ -166,7 +167,6 @@ void set_battery_voltage_attributes(JsonDocument& doc, int i, int cellNumber, co
doc["unit_of_measurement"] = "V";
doc["value_template"] = "{{ value_json.cell_voltages[" + String(i) + "] }}";
}

#endif // HA_AUTODISCOVERY

static std::vector<EventData> order_events;
Expand Down Expand Up @@ -425,6 +425,7 @@ void mqtt_message_received(char* topic, int topic_len, char* data, int data_len)
}
#endif // REMOTE_BMS_RESET

#ifdef HA_AUTODISCOVERY
if (strncmp(topic, generateButtonTopic("PAUSE").c_str(), topic_len) == 0) {
setBatteryPause(true, false);
}
Expand All @@ -442,8 +443,11 @@ void mqtt_message_received(char* topic, int topic_len, char* data, int data_len)
if (strncmp(topic, generateButtonTopic("STOP").c_str(), topic_len) == 0) {
setBatteryPause(true, false, true);
}
#endif // HA_AUTODISCOVERY
}



static void mqtt_event_handler(void* handler_args, esp_event_base_t base, int32_t event_id, void* event_data) {
esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data;
switch ((esp_mqtt_event_id_t)event_id) {
Expand Down
Loading