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

@@ -6,9 +6,8 @@
#include <nlohmann/json.hpp>
#include <string>
HomeAssistant::HomeAssistant(const std::string& addr, const std::string& ent) {
address = addr;
entity = ent;
HomeAssistant::HomeAssistant(const Config& config){
m_config = config;
}
HomeAssistant::~HomeAssistant() {
@@ -29,17 +28,17 @@ void HomeAssistant::event_handler(struct lws* wsi, const enum lws_callback_reaso
if (ha_type == "auth_required") {
json.clear();
json["type"] = "auth";
json["access_token"] = HASS_TOKEN;
json["access_token"] = m_config.token;
tx = json.dump();
break;
}
if (ha_type == "auth_ok") {
applog(LOG::INF, "subscribing to entity \"{}\"", entity);
applog(LOG::INF, "subscribing to entity \"{}\"", m_config.entity);
json.clear();
json["id"] = id++;
json["type"] = "subscribe_entities";
json["entity_ids"][0] = entity.c_str();
json["entity_ids"][0] = m_config.entity.c_str();
tx = json.dump();
break;
}
@@ -53,9 +52,9 @@ void HomeAssistant::event_handler(struct lws* wsi, const enum lws_callback_reaso
if (ha_type == "event") {
json = json["event"];
if (json.contains("a"))
state = std::stof(json["a"][entity]["s"].get<std::string>());
state = std::stof(json["a"][m_config.entity]["s"].get<std::string>());
if (json.contains("c"))
state = std::stof(json["c"][entity]["+"]["s"].get<std::string>());
state = std::stof(json["c"][m_config.entity]["+"]["s"].get<std::string>());
break;
}
@@ -134,7 +133,7 @@ int HomeAssistant::connect() {
i.context = context;
i.port = 443;
i.address = address.c_str();
i.address = m_config.address.c_str();
i.path = "/api/websocket";
i.host = i.address;
i.origin = i.address;