move hass config to main

This commit is contained in:
2026-01-03 17:37:08 +01:00
parent b8589181a7
commit 42d3d4359b
5 changed files with 47 additions and 36 deletions

View File

@@ -21,6 +21,9 @@ class Application {
std::string sys_sensor;
std::string sys_ifname;
std::string home_dir;
std::string hass_url;
std::string hass_entity;
std::string hass_token;
};
explicit Application(Config config);
@@ -30,7 +33,7 @@ class Application {
private:
struct Sensors {
sys::TimeDate td;
double avg[3] = {0.0f};
double loadavg[3] = {0.0f};
sys::Memory ram;
sys::Disk home;
sys::Network net;
@@ -38,11 +41,11 @@ class Application {
cpu::cpuSensors cpu;
gpu::gpuSensors gpu;
double hass_state = 0.0f;
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
};
struct Control {
std::binary_semaphore display{0};
std::mutex sensors; // making sure the sensors struct isnt accessed by multiple threads at once
sigset_t sigset;
};

View File

@@ -6,27 +6,29 @@
#include <cstdint>
#include <string>
#define HASS_TOKEN "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MzUxMTZiY2VjNTg0MTI3OGI4YmU0NTY4ZGQ5MzIyYiIsImlhdCI6MTc1NzQzMDI0MCwiZXhwIjoyMDcyNzkwMjQwfQ.6wKTlxEA0FLWfv-qW35vewUSvTxdVrZWqFwHT5Khu6E"
class HomeAssistant {
private:
std::string address;
std::string entity;
uint16_t id = 2;
std::string tx;
struct lws_context* context = nullptr;
lws* websock = nullptr;
void event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in);
static int callback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len);
public:
HomeAssistant(const std::string& addr, const std::string& ent);
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