34 lines
753 B
C++
34 lines
753 B
C++
#ifndef HASS_HPP
|
|
#define HASS_HPP
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
class HomeAssistant {
|
|
public:
|
|
struct Config {
|
|
std::string address;
|
|
std::string entity;
|
|
std::string token;
|
|
};
|
|
explicit HomeAssistant(const Config& config);
|
|
~HomeAssistant();
|
|
|
|
float state = 0.0f;
|
|
int connect();
|
|
void disconnect() const;
|
|
void service(int timeout_ms = 0) const;
|
|
|
|
private:
|
|
uint16_t id = 2;
|
|
std::string tx;
|
|
lws_context* context = nullptr;
|
|
lws* websock = nullptr;
|
|
void event_handler(lws* wsi, lws_callback_reasons reason, char* in);
|
|
static int callback(lws* wsi, lws_callback_reasons reason, void* user, void* in, size_t len);
|
|
Config m_config;
|
|
};
|
|
|
|
#endif |