it was colliding with math log, renamed to applog

This commit is contained in:
2025-12-28 13:40:01 +01:00
parent 14b03f45f4
commit d873837660
8 changed files with 33 additions and 34 deletions

View File

@@ -1,8 +1,7 @@
#include <libwebsockets.h>
#include <nlohmann/json.hpp>
#include <hass.hpp>
#include <log.hpp>
#include <nlohmann/json.hpp>
#include <string>
HomeAssistant::HomeAssistant(std::string addr, std::string ent) {
@@ -17,7 +16,7 @@ HomeAssistant::~HomeAssistant() {
void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in) {
switch (reason) {
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: {
log(LOG::ERR, "websocket conn error: {}", in ? in : "(null)");
applog(LOG::ERR, "websocket conn error: {}", in ? in : "(null)");
return;
}
@@ -34,7 +33,7 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
}
if (ha_type == "auth_ok") {
log(LOG::INF, "subscribing to entity \"{}\"", entity);
applog(LOG::INF, "subscribing to entity \"{}\"", entity);
json.clear();
json["id"] = id++;
json["type"] = "subscribe_entities";
@@ -45,30 +44,30 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
if (ha_type == "result") {
if (json["success"].get<bool>() != true)
log(LOG::ERR, "api said success was \"false\" on message id {}", id - 1);
applog(LOG::ERR, "api said success was \"false\" on message id {}", id - 1);
break;
}
if (ha_type == "event") {
json = json["event"];
if (json.contains("a"))
if(json.contains("a"))
state = std::stof(json["a"][entity]["s"].get<std::string>());
if (json.contains("c"))
if(json.contains("c"))
state = std::stof(json["c"][entity]["+"]["s"].get<std::string>());
break;
}
log(LOG::WRN, "unhandled event: {}", (char*)in);
applog(LOG::WRN, "unhandled event: {}", (char*)in);
break;
}
case LWS_CALLBACK_CLIENT_ESTABLISHED: {
log(LOG::INF, "Websocket connected");
applog(LOG::INF, "Websocket connected");
break;
}
case LWS_CALLBACK_CLIENT_CLOSED: {
log(LOG::INF, "Websocket closed");
applog(LOG::INF, "Websocket closed");
return;
}
@@ -127,7 +126,7 @@ int HomeAssistant::connect() {
context = lws_create_context(&info);
if (!context) {
log(LOG::ERR, "error creating context");
applog(LOG::ERR, "error creating context");
return -1;
}
@@ -144,7 +143,7 @@ int HomeAssistant::connect() {
websock = lws_client_connect_via_info(&i);
if (!websock) {
log(LOG::ERR, "error creating lws client");
applog(LOG::ERR, "error creating lws client");
return -1;
}
return 0;