smarter cmake, conditional hass, still need to do conditional gzip logging
This commit is contained in:
25
src/app.cpp
25
src/app.cpp
@@ -63,8 +63,11 @@ void Application::Crash(const int ret) {
|
||||
kill(m_mainPid, SIGINT);
|
||||
}
|
||||
|
||||
void Application::hassThread(const std::stop_token& st) {
|
||||
|
||||
void Application::hassThread(const std::stop_token& st) { //NOLINT
|
||||
applog(LOG::START, "Thread started");
|
||||
#ifdef ENABLE_HOME_ASSISTANT
|
||||
static double power;
|
||||
HomeAssistant::Config config;
|
||||
config.address = m_config.hass.url;
|
||||
config.entity = m_config.hass.entity;
|
||||
@@ -74,12 +77,23 @@ void Application::hassThread(const std::stop_token& st) {
|
||||
pc_power.connect();
|
||||
while (!st.stop_requested()) {
|
||||
pc_power.service();
|
||||
{
|
||||
std::lock_guard lock(m_control.sensors);
|
||||
m_sensors.hass_state = pc_power.state;
|
||||
if (power != pc_power.state) {
|
||||
power = pc_power.state;
|
||||
{
|
||||
std::lock_guard lock(m_control.sensors);
|
||||
m_sensors.hass_state = power;
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
#else
|
||||
(void)st;
|
||||
applog(LOG::WRN, "feature disabled at compile time, probably no libwebsockets on host. exiting thread");
|
||||
{
|
||||
std::lock_guard lock(m_control.sensors);
|
||||
m_sensors.hass_state = -1.0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::sensorsThread(const std::stop_token& st) {
|
||||
@@ -169,7 +183,8 @@ void Application::displayThread(const std::stop_token& st) {
|
||||
|
||||
lcd.writeBuf(1, 0, utils::pad(std::to_string(m_sensors.cpu.tctl) + "/" + std::to_string(m_sensors.cpu.tccd1) + LCDDisplay::cc(0), 8, utils::just::left));
|
||||
lcd.writeBuf(1, 7, utils::pad(utils::pBytes(m_sensors.ram.used, true), 6, utils::just::left));
|
||||
lcd.writeBuf(1, 13, utils::pad(utils::pNum(m_sensors.hass_state) + "W", 4));
|
||||
if (m_sensors.hass_state >= 0)
|
||||
lcd.writeBuf(1, 13, utils::pad(utils::pNum(m_sensors.hass_state) + "W", 4));
|
||||
lcd.writeBuf(1, 19, std::to_string(m_sensors.sys.t_sensor) + LCDDisplay::cc(0)); // t_sensor temp
|
||||
lcd.writeBuf(1, 32 - gpu_temps.size(), utils::pad(utils::pBytes(m_sensors.gpu.vram_used), 6));
|
||||
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + LCDDisplay::cc(0));
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
|
||||
#ifdef ENABLE_HOME_ASSISTANT
|
||||
|
||||
HomeAssistant::HomeAssistant(const Config& config) {
|
||||
m_config = config;
|
||||
}
|
||||
@@ -158,3 +160,5 @@ void HomeAssistant::service(const int timeout_ms) const {
|
||||
void HomeAssistant::disconnect() const {
|
||||
lws_context_destroy(context);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user