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 solarcharger classes #1457

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

Conversation

AndreasBoehm
Copy link
Member

@AndreasBoehm AndreasBoehm commented Dec 13, 2024

Based on the structure that @schlimmchen introduced here: #1451

I did not touch 'MqttHandleVedirect'. will be done in a stats related branch/PR.

@AndreasBoehm AndreasBoehm force-pushed the rename-vedirect-to-solarcharger branch from d4d9737 to d11be3b Compare December 23, 2024 12:02
@AndreasBoehm AndreasBoehm force-pushed the andreasboehm/feature/restructure-vedirect branch from e23be05 to 983abde Compare December 23, 2024 12:08
@AndreasBoehm AndreasBoehm marked this pull request as draft December 23, 2024 12:08
@AndreasBoehm AndreasBoehm force-pushed the rename-vedirect-to-solarcharger branch from d11be3b to a3d0408 Compare December 24, 2024 11:24
@AndreasBoehm AndreasBoehm force-pushed the rename-vedirect-to-solarcharger branch 2 times, most recently from 08e5b9a to 635a450 Compare January 4, 2025 15:24
@AndreasBoehm AndreasBoehm force-pushed the andreasboehm/feature/restructure-vedirect branch 5 times, most recently from 5723f4e to b630fb9 Compare January 4, 2025 22:19

void MqttHandleVedirectHassClass::init(Scheduler& scheduler)
void HassIntegration::publishSensors() const
Copy link
Member Author

Choose a reason for hiding this comment

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

@schlimmchen because we need details about the individual charge controller it might make sense to move this into Stats instead of having this separated. what do you think?

I did set this up separately, following your battery restructure, but for the batteries you don't need any data from the battery itself.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure that I can follow all the way... This is what I can say:

  1. As this class is specific to Victron charge controllers, I don't feel too bad having to ask for a Victron charge controller data structure here. So, I guess the method is fine here.
  2. Passing a std::optional<VeDirectMpptController::data_t> around, even as a reference, to only use the serial number from it (if I see it correctly), is not a good idea. You might be able to de-couple the publishSensor() method into the base class if you instead pass a serial number as a string.
  3. This whole setup is... questionable. What I mean is conditionally publishing the info for HA auto-discovery. What if this method is only executed before the first data is received from the charge controller? It is not executed periodically, for sure, but only once after reboot and when reconnecting to the MQTT broker (right?). So, this method would not even need a std::optional<VeDirectMpptController::data_t> but only the serial number if we published all sensors unconditionally. My hope is that HA is fine with published sensors that don't have a value at the respective MQTT topic. ChatGPT says the sensor is still created and visible and so one, but its value will "forever" read "unknown". Meh... So we have to deal with this and publish the sensors conditionally, which means we should also revisit this method regularly?

@AndreasBoehm AndreasBoehm force-pushed the andreasboehm/feature/restructure-vedirect branch 2 times, most recently from 8f5e560 to d5775dc Compare January 4, 2025 22:59
Comment on lines +25 to +27
// TODO(andreasboehm): _data and _lastUpdate in two different structures is not ideal and needs to change
mutable std::map<String, std::optional<VeDirectMpptController::data_t>> _data;
mutable std::map<String, uint32_t> _lastUpdate;
Copy link
Member Author

Choose a reason for hiding this comment

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

@schlimmchen any ideas without duplicating all data found in data_t?

Copy link
Member

Choose a reason for hiding this comment

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

Keep using a copy. This is a direct copy of _tmpFrame of VeDirectFrameHandler, isn't it? It is good that we keep at leas one immutable copy of the data around. VeDirectFrameHandler is messing with it's _tmpFrame in-situ...

BTW: In the long run I see DataPoints being used instead.

@AndreasBoehm AndreasBoehm force-pushed the rename-vedirect-to-solarcharger branch 2 times, most recently from 4811e65 to 9e73fcc Compare January 8, 2025 20:31
Base automatically changed from rename-vedirect-to-solarcharger to development January 8, 2025 20:46
@AndreasBoehm AndreasBoehm force-pushed the andreasboehm/feature/restructure-vedirect branch 2 times, most recently from 9ce82e7 to bf3d3f8 Compare January 9, 2025 07:10
did not touch 'MqttHandleVedirect'. will be done in a stats realted branch/PR

fix includes
@AndreasBoehm AndreasBoehm force-pushed the andreasboehm/feature/restructure-vedirect branch from bf3d3f8 to 585d262 Compare January 11, 2025 20:05
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