Adds more code to HA_AUTODISCOVERY setting

This commit is contained in:
Paul Brand 2024-08-27 22:16:03 +02:00
parent 2ddbb9d0d4
commit feb726162f

View file

@ -25,10 +25,12 @@ static void publish_values(void) {
publish_cell_voltages(); publish_cell_voltages();
} }
#ifdef HA_AUTODISCOVERY
static String generateCellVoltageAutoConfigTopic(int cell_number, const char* hostname) { static String generateCellVoltageAutoConfigTopic(int cell_number, const char* hostname) {
return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/cell_voltage" + String(cell_number) + return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/cell_voltage" + String(cell_number) +
"/config"; "/config";
} }
#endif // HA_AUTODISCOVERY
static void publish_cell_voltages(void) { static void publish_cell_voltages(void) {
#ifdef HA_AUTODISCOVERY #ifdef HA_AUTODISCOVERY
@ -106,6 +108,7 @@ struct SensorConfig {
const char* device_class; const char* device_class;
}; };
#ifdef HA_AUTODISCOVERY
SensorConfig sensorConfigs[] = { SensorConfig sensorConfigs[] = {
{"SOC", "Battery Emulator SOC (scaled)", "{{ value_json.SOC }}", "%", "battery"}, {"SOC", "Battery Emulator SOC (scaled)", "{{ value_json.SOC }}", "%", "battery"},
{"SOC_real", "Battery Emulator SOC (real)", "{{ value_json.SOC_real }}", "%", "battery"}, {"SOC_real", "Battery Emulator SOC (real)", "{{ value_json.SOC_real }}", "%", "battery"},
@ -122,6 +125,7 @@ SensorConfig sensorConfigs[] = {
static String generateCommonInfoAutoConfigTopic(const char* object_id, const char* hostname) { static String generateCommonInfoAutoConfigTopic(const char* object_id, const char* hostname) {
return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/" + String(object_id) + "/config"; return String("homeassistant/sensor/battery-emulator_") + String(hostname) + "/" + String(object_id) + "/config";
} }
#endif // HA_AUTODISCOVERY
static void publish_common_info(void) { static void publish_common_info(void) {
static JsonDocument doc; static JsonDocument doc;