d1_mini_pro-sensor-mqtt/lib/HomeAssistantDevices/HADevice.hpp

36 lines
799 B
C++

#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;
};