* pylontech HA integration: remove unused method/variable * make MqttHandlePylontechHassClass::publishConfig() private. there are no outside users of that method. * rename to MqttHandleBatteryHass * battery HA integration: merge methods and bring back forceUpdate(). even though the forceUpdate() method was not in use before, it makes sense to implement it and use it when the battery config changes. rather than controlling a separate flag, it now changes the _doPublish flag of the class, which also triggers publishing the device config to Home Assistant when an MQTT connection problem was detected. since both situations are now handled similarly, we can merge the loop() and publishConfig() methods. * battery: provider specific sensors for HA * move Battery MQTT loop to BatteryStats the BatteryStats class should handle the MQTT publishing, including the interval. for the calculation of a reasonable Home Assistent expiration value this class now also knows the maximum publish interval. * JK BMS: fix publishing values for Home Assistent Home Assistent values expire, because we set them to expire after three MQTT publish durations. for that reason, we need to re-publish all values after our self-inflicted full publish interval. * define JK BMS sensors for Home Assistent closes #482.
37 lines
834 B
C++
37 lines
834 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <TaskSchedulerDeclarations.h>
|
|
|
|
#include "BatteryStats.h"
|
|
|
|
class BatteryProvider {
|
|
public:
|
|
// returns true if the provider is ready for use, false otherwise
|
|
virtual bool init(bool verboseLogging) = 0;
|
|
|
|
virtual void deinit() = 0;
|
|
virtual void loop() = 0;
|
|
virtual std::shared_ptr<BatteryStats> getStats() const = 0;
|
|
};
|
|
|
|
class BatteryClass {
|
|
public:
|
|
void init(Scheduler&);
|
|
void updateSettings();
|
|
|
|
std::shared_ptr<BatteryStats const> getStats() const;
|
|
private:
|
|
void loop();
|
|
|
|
Task _loopTask;
|
|
|
|
mutable std::mutex _mutex;
|
|
std::unique_ptr<BatteryProvider> _upProvider = nullptr;
|
|
};
|
|
|
|
extern BatteryClass Battery;
|