начинает создавать библиотеку HA
This commit is contained in:
36
lib/HomeAssistantDevices/HADevice.hpp
Normal file
36
lib/HomeAssistantDevices/HADevice.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
class HADevice {
|
||||
protected:
|
||||
PubSubClient &client;
|
||||
const char *name;
|
||||
const char *unique_id;
|
||||
const char *device_type;
|
||||
|
||||
static constexpr const char *base_topic = "homeassistant";
|
||||
|
||||
char *device_topic = nullptr;
|
||||
unsigned int device_topic_size = 0;
|
||||
|
||||
char *config_topic = nullptr;
|
||||
unsigned int config_topic_size = 0;
|
||||
|
||||
char *state_topic = nullptr;
|
||||
unsigned int state_topic_size = 0;
|
||||
|
||||
char *buffer;
|
||||
unsigned int buffer_size = MQTT_MAX_PACKET_SIZE;
|
||||
|
||||
void setupDeviceTopic();
|
||||
void setupConfigTopic();
|
||||
void setupStateTopic();
|
||||
|
||||
public:
|
||||
HADevice(PubSubClient &client, const char *device_type, const char *name,
|
||||
const char *unique_id);
|
||||
virtual void sendConfig() = 0;
|
||||
virtual void sendState() = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user