* 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.
26 lines
921 B
C++
26 lines
921 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <ArduinoJson.h>
|
|
#include <TaskSchedulerDeclarations.h>
|
|
|
|
class MqttHandleBatteryHassClass {
|
|
public:
|
|
void init(Scheduler& scheduler);
|
|
void forceUpdate() { _doPublish = true; }
|
|
|
|
private:
|
|
void loop();
|
|
void publish(const String& subtopic, const String& payload);
|
|
void publishBinarySensor(const char* caption, const char* icon, const char* subTopic, const char* payload_on, const char* payload_off);
|
|
void publishSensor(const char* caption, const char* icon, const char* subTopic, const char* deviceClass = NULL, const char* stateClass = NULL, const char* unitOfMeasurement = NULL);
|
|
void createDeviceInfo(JsonObject& object);
|
|
|
|
Task _loopTask;
|
|
|
|
bool _doPublish = true;
|
|
String serial = "0001"; // pseudo-serial, can be replaced in future with real serialnumber
|
|
};
|
|
|
|
extern MqttHandleBatteryHassClass MqttHandleBatteryHass;
|