Skip to content

Commit

Permalink
remove MqttOutput prefix from config
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Jan 16, 2025
1 parent 76e22c9 commit ba28884
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
18 changes: 9 additions & 9 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,19 @@ struct SOLARCHARGER_MQTT_CONFIG_T {
bool CalculateOutputPower;

enum WattageUnit { KiloWatts = 0, Watts = 1, MilliWatts = 2 };
char MqttOutputPowerTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char MqttOutputPowerJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
WattageUnit MqttOutputPowerUnit;
char PowerTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char PowerJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
WattageUnit PowerUnit;

enum VoltageUnit { Volts = 0, DeciVolts = 1, CentiVolts = 2, MilliVolts = 3 };
char MqttOutputVoltageTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char MqttOutputVoltageJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
VoltageUnit MqttOutputVoltageUnit;
char VoltageTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char VoltageJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
VoltageUnit VoltageTopicUnit;

enum AmperageUnit { Amps = 0, MilliAmps = 1 };
char MqttOutputCurrentTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char MqttOutputCurrentJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
AmperageUnit MqttOutputCurrentUnit;
char CurrentTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char CurrentJsonPath[MQTT_MAX_JSON_PATH_STRLEN + 1];
AmperageUnit CurrentUnit;
};
using SolarChargerMqttConfig = struct SOLARCHARGER_MQTT_CONFIG_T;

Expand Down
36 changes: 18 additions & 18 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ void ConfigurationClass::serializeSolarChargerConfig(SolarChargerConfig const& s
void ConfigurationClass::serializeSolarChargerMqttConfig(SolarChargerMqttConfig const& source, JsonObject& target)
{
target["calculate_output_power"] = source.CalculateOutputPower;
target["power_topic"] = source.MqttOutputPowerTopic;
target["power_path"] = source.MqttOutputPowerJsonPath;
target["power_unit"] = source.MqttOutputPowerUnit;
target["voltage_topic"] = source.MqttOutputVoltageTopic;
target["voltage_path"] = source.MqttOutputVoltageJsonPath;
target["voltage_unit"] = source.MqttOutputVoltageUnit;
target["current_topic"] = source.MqttOutputCurrentTopic;
target["current_path"] = source.MqttOutputCurrentJsonPath;
target["current_unit"] = source.MqttOutputCurrentUnit;
target["power_topic"] = source.PowerTopic;
target["power_path"] = source.PowerJsonPath;
target["power_unit"] = source.PowerUnit;
target["voltage_topic"] = source.VoltageTopic;
target["voltage_path"] = source.VoltageJsonPath;
target["voltage_unit"] = source.VoltageTopicUnit;
target["current_topic"] = source.CurrentTopic;
target["current_path"] = source.CurrentJsonPath;
target["current_unit"] = source.CurrentUnit;
}

void ConfigurationClass::serializePowerMeterMqttConfig(PowerMeterMqttConfig const& source, JsonObject& target)
Expand Down Expand Up @@ -406,15 +406,15 @@ void ConfigurationClass::deserializeSolarChargerConfig(JsonObject const& source,
void ConfigurationClass::deserializeSolarChargerMqttConfig(JsonObject const& source, SolarChargerMqttConfig& target)
{
target.CalculateOutputPower = source["calculate_output_power"];
strlcpy(target.MqttOutputPowerTopic, source["power_topic"] | "", sizeof(target.MqttOutputPowerTopic));
strlcpy(target.MqttOutputPowerJsonPath, source["power_path"] | "", sizeof(target.MqttOutputPowerJsonPath));
target.MqttOutputPowerUnit = source["power_unit"] | SolarChargerMqttConfig::WattageUnit::Watts;
strlcpy(target.MqttOutputVoltageTopic, source["voltage_topic"] | "", sizeof(target.MqttOutputVoltageTopic));
strlcpy(target.MqttOutputVoltageJsonPath, source["voltage_path"] | "", sizeof(target.MqttOutputVoltageJsonPath));
target.MqttOutputVoltageUnit = source["voltage_unit"] | SolarChargerMqttConfig::VoltageUnit::Volts;
strlcpy(target.MqttOutputCurrentTopic, source["current_topic"] | "", sizeof(target.MqttOutputCurrentTopic));
strlcpy(target.MqttOutputCurrentJsonPath, source["current_path"] | "", sizeof(target.MqttOutputCurrentJsonPath));
target.MqttOutputCurrentUnit = source["current_unit"] | SolarChargerMqttConfig::AmperageUnit::Amps;
strlcpy(target.PowerTopic, source["power_topic"] | "", sizeof(target.PowerTopic));
strlcpy(target.PowerJsonPath, source["power_path"] | "", sizeof(target.PowerJsonPath));
target.PowerUnit = source["power_unit"] | SolarChargerMqttConfig::WattageUnit::Watts;
strlcpy(target.VoltageTopic, source["voltage_topic"] | "", sizeof(target.VoltageTopic));
strlcpy(target.VoltageJsonPath, source["voltage_path"] | "", sizeof(target.VoltageJsonPath));
target.VoltageTopicUnit = source["voltage_unit"] | SolarChargerMqttConfig::VoltageUnit::Volts;
strlcpy(target.CurrentTopic, source["current_topic"] | "", sizeof(target.CurrentTopic));
strlcpy(target.CurrentJsonPath, source["current_path"] | "", sizeof(target.CurrentJsonPath));
target.CurrentUnit = source["current_unit"] | SolarChargerMqttConfig::AmperageUnit::Amps;
}

void ConfigurationClass::deserializePowerMeterMqttConfig(JsonObject const& source, PowerMeterMqttConfig& target)
Expand Down
18 changes: 9 additions & 9 deletions src/solarcharger/mqtt/Provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ bool Provider::init(bool verboseLogging)
_verboseLogging = verboseLogging;
auto const& config = Configuration.get().SolarCharger.Mqtt;

_outputPowerTopic = config.MqttOutputPowerTopic;
_outputCurrentTopic = config.MqttOutputCurrentTopic;
_outputPowerTopic = config.PowerTopic;
_outputCurrentTopic = config.CurrentTopic;

auto configValid = config.CalculateOutputPower ? !_outputCurrentTopic.isEmpty() : !_outputPowerTopic.isEmpty();

Expand All @@ -35,7 +35,7 @@ bool Provider::init(bool verboseLogging)
this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4,
std::placeholders::_5, std::placeholders::_6,
config.MqttOutputPowerJsonPath)
config.PowerJsonPath)
);

if (_verboseLogging) {
Expand All @@ -52,7 +52,7 @@ bool Provider::init(bool verboseLogging)
this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4,
std::placeholders::_5, std::placeholders::_6,
config.MqttOutputCurrentJsonPath)
config.CurrentJsonPath)
);

if (_verboseLogging) {
Expand All @@ -61,7 +61,7 @@ bool Provider::init(bool verboseLogging)
}
}

_outputVoltageTopic = config.MqttOutputVoltageTopic;
_outputVoltageTopic = config.VoltageTopic;
if (!_outputVoltageTopic.isEmpty()) {
_subscribedTopics.push_back(_outputVoltageTopic);

Expand All @@ -70,7 +70,7 @@ bool Provider::init(bool verboseLogging)
this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4,
std::placeholders::_5, std::placeholders::_6,
config.MqttOutputVoltageJsonPath)
config.VoltageJsonPath)
);

if (_verboseLogging) {
Expand Down Expand Up @@ -102,7 +102,7 @@ void Provider::onMqttMessageOutputPower(espMqttClientTypes::MessageProperties co

auto const& config = Configuration.get().SolarCharger.Mqtt;
using Unit_t = SolarChargerMqttConfig::WattageUnit;
switch (config.MqttOutputPowerUnit) {
switch (config.PowerUnit) {
case Unit_t::MilliWatts:
*outputPower /= 1000;
break;
Expand Down Expand Up @@ -139,7 +139,7 @@ void Provider::onMqttMessageOutputVoltage(espMqttClientTypes::MessageProperties

auto const& config = Configuration.get().SolarCharger.Mqtt;
using Unit_t = SolarChargerMqttConfig::VoltageUnit;
switch (config.MqttOutputVoltageUnit) {
switch (config.VoltageTopicUnit) {
case Unit_t::DeciVolts:
*outputVoltage /= 10;
break;
Expand Down Expand Up @@ -182,7 +182,7 @@ void Provider::onMqttMessageOutputCurrent(espMqttClientTypes::MessageProperties

auto const& config = Configuration.get().SolarCharger.Mqtt;
using Unit_t = SolarChargerMqttConfig::AmperageUnit;
switch (config.MqttOutputVoltageUnit) {
switch (config.CurrentUnit) {
case Unit_t::MilliAmps:
*outputCurrent /= 1000;
break;
Expand Down

0 comments on commit ba28884

Please sign in to comment.