Migrate MqttHandleHass to TaskScheduler
This commit is contained in:
parent
98c30d1042
commit
48a27fbfad
@ -3,6 +3,7 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <Hoymiles.h>
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
|
||||
// mqtt discovery device classes
|
||||
enum {
|
||||
@ -50,12 +51,12 @@ const byteAssign_fieldDeviceClass_t deviceFieldAssignment[] = {
|
||||
|
||||
class MqttHandleHassClass {
|
||||
public:
|
||||
void init();
|
||||
void loop();
|
||||
void init(Scheduler* scheduler);
|
||||
void publishConfig();
|
||||
void forceUpdate();
|
||||
|
||||
private:
|
||||
void loop();
|
||||
void publish(const String& subtopic, const String& payload);
|
||||
void publishField(std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, byteAssign_fieldDeviceClass_t fieldType, bool clear = false);
|
||||
void publishInverterButton(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload);
|
||||
@ -63,6 +64,8 @@ private:
|
||||
void publishInverterBinarySensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off);
|
||||
void createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv);
|
||||
|
||||
Task _loopTask;
|
||||
|
||||
bool _wasConnected = false;
|
||||
bool _updateForced = false;
|
||||
};
|
||||
|
||||
@ -9,8 +9,12 @@
|
||||
|
||||
MqttHandleHassClass MqttHandleHass;
|
||||
|
||||
void MqttHandleHassClass::init()
|
||||
void MqttHandleHassClass::init(Scheduler* scheduler)
|
||||
{
|
||||
scheduler->addTask(_loopTask);
|
||||
_loopTask.setCallback(std::bind(&MqttHandleHassClass::loop, this));
|
||||
_loopTask.setIterations(TASK_FOREVER);
|
||||
_loopTask.enable();
|
||||
}
|
||||
|
||||
void MqttHandleHassClass::loop()
|
||||
|
||||
@ -102,7 +102,7 @@ void setup()
|
||||
MqttHandleDtu.init();
|
||||
MqttHandleInverter.init();
|
||||
MqttHandleInverterTotal.init(&scheduler);
|
||||
MqttHandleHass.init();
|
||||
MqttHandleHass.init(&scheduler);
|
||||
MessageOutput.println("done");
|
||||
|
||||
// Initialize WebApi
|
||||
@ -161,8 +161,6 @@ void loop()
|
||||
yield();
|
||||
MqttHandleInverter.loop();
|
||||
yield();
|
||||
MqttHandleHass.loop();
|
||||
yield();
|
||||
WebApi.loop();
|
||||
yield();
|
||||
Display.loop();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user