Migrate MqttHandleHass to TaskScheduler
This commit is contained in:
parent
98c30d1042
commit
48a27fbfad
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
|
#include <TaskSchedulerDeclarations.h>
|
||||||
|
|
||||||
// mqtt discovery device classes
|
// mqtt discovery device classes
|
||||||
enum {
|
enum {
|
||||||
@ -50,12 +51,12 @@ const byteAssign_fieldDeviceClass_t deviceFieldAssignment[] = {
|
|||||||
|
|
||||||
class MqttHandleHassClass {
|
class MqttHandleHassClass {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init(Scheduler* scheduler);
|
||||||
void loop();
|
|
||||||
void publishConfig();
|
void publishConfig();
|
||||||
void forceUpdate();
|
void forceUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void loop();
|
||||||
void publish(const String& subtopic, const String& payload);
|
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 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);
|
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 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);
|
void createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv);
|
||||||
|
|
||||||
|
Task _loopTask;
|
||||||
|
|
||||||
bool _wasConnected = false;
|
bool _wasConnected = false;
|
||||||
bool _updateForced = false;
|
bool _updateForced = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,8 +9,12 @@
|
|||||||
|
|
||||||
MqttHandleHassClass MqttHandleHass;
|
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()
|
void MqttHandleHassClass::loop()
|
||||||
|
|||||||
@ -102,7 +102,7 @@ void setup()
|
|||||||
MqttHandleDtu.init();
|
MqttHandleDtu.init();
|
||||||
MqttHandleInverter.init();
|
MqttHandleInverter.init();
|
||||||
MqttHandleInverterTotal.init(&scheduler);
|
MqttHandleInverterTotal.init(&scheduler);
|
||||||
MqttHandleHass.init();
|
MqttHandleHass.init(&scheduler);
|
||||||
MessageOutput.println("done");
|
MessageOutput.println("done");
|
||||||
|
|
||||||
// Initialize WebApi
|
// Initialize WebApi
|
||||||
@ -161,8 +161,6 @@ void loop()
|
|||||||
yield();
|
yield();
|
||||||
MqttHandleInverter.loop();
|
MqttHandleInverter.loop();
|
||||||
yield();
|
yield();
|
||||||
MqttHandleHass.loop();
|
|
||||||
yield();
|
|
||||||
WebApi.loop();
|
WebApi.loop();
|
||||||
yield();
|
yield();
|
||||||
Display.loop();
|
Display.loop();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user