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

Restructure battery interfaces implementations #1451

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

schlimmchen
Copy link
Member

Especially the BatteryStats source code file was way too large. This restructuring should not change anything for the user, but will ease maintenance. It shall be the blueprint for structuring source code for other multi-provider-features like the solar charger.

* split source code into individual files, per interface type.
* sort files into subfolder.
* introduce and use namespaces.
@schlimmchen schlimmchen marked this pull request as draft December 13, 2024 14:31
@schlimmchen
Copy link
Member Author

@AndreasBoehm I appreciate your feedback, but I am unsure whether I want to do this or #1221 first (they conflict each other).

object["name"] = "Battery(" + _serial + ")";

auto const& config = Configuration.get();
if (config.Battery.Provider == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be part of the JK BMS Battery Stats class instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I moved whole functions around, I did not notice this. Yes, this must be cleaned up. Not sure how... I'll look into it.

Comment on lines +12 to +13
publishSensor("Voltage", "mdi:battery-charging", "voltage", "voltage", "measurement", "V");
publishSensor("Current", "mdi:current-dc", "current", "current", "measurement", "A");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of the generic BatteryNs::HassIntegration based on isVoltageValid and isCurrentValid? (This comment might apply to some more sensors)

Comment on lines +11 to +12
publishSensor("Battery voltage", NULL, "voltage", "voltage", "measurement", "V");
publishSensor("Battery current", NULL, "current", "current", "measurement", "A");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those prefixed with Battery? was it like this before? Should we change it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can risk making this the same as in the other providers. When/if we move these to the parent class, there is no way around it anyways.

src/battery/Controller.cpp Show resolved Hide resolved
public:
void publishSensors() const final
{
::BatteryNs::HassIntegration::publishSensors();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that we will publish sensors that won't get any data. Or did i understand i get it wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the manufacturer, the data age, and the soc auto-discoverable. I don't know what we set as the manufacturer, but the data age makes sense and I guess SoC is a mandatory value for the mqtt battery interface? I guess this is fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we should not republish data from mqtt providers. We applied the same logic for the mqtt powermeter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants