• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bcpearce / hass-motion-detection-addon / 21126908333

19 Jan 2026 05:55AM UTC coverage: 18.037% (-31.9%) from 49.971%
21126908333

Pull #26

github

web-flow
Merge 1a90d6ebc into 0206cb867
Pull Request #26: Additional test coverage

276 of 1767 branches covered (15.62%)

Branch coverage included in aggregate %.

8 of 22 new or added lines in 3 files covered. (36.36%)

827 existing lines in 29 files now uncovered.

347 of 1687 relevant lines covered (20.57%)

27.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Callback/ThreadedHassHandler.cxx
1
#include "Logger.h"
2

3
#include "Callback/ThreadedHassHandler.h"
4

5
#include <chrono>
6
#include <format>
7
#include <iostream>
8
#include <string_view>
9

10
#include "Callback/Json.h"
11
#include "Util/BufferOperations.h"
12
#include "Util/CurlWrapper.h"
13

14
using namespace std::chrono_literals;
15
using namespace std::string_literals;
16
using namespace std::string_view_literals;
17

18
namespace callback {
19

UNCOV
20
ThreadedHassHandler::ThreadedHassHandler(const boost::url &url,
×
21
                                         const std::string &token,
UNCOV
22
                                         const std::string &entityId)
×
UNCOV
23
    : BaseHassHandler(url, token, entityId) {}
×
24

UNCOV
25
ThreadedHassHandler::~ThreadedHassHandler() noexcept { Stop(); }
×
26

UNCOV
27
void ThreadedHassHandler::Start() {
×
UNCOV
28
  util::CurlWrapper wCurl;
×
29

UNCOV
30
  PrepareGetRequest(wCurl, buf_);
×
UNCOV
31
  wCurl(curl_easy_perform);
×
UNCOV
32
  HandleGetResponse(wCurl, buf_);
×
33

UNCOV
34
  updaterThread_ = std::jthread(
×
UNCOV
35
      [this, wCurl = std::move(wCurl)](std::stop_token stopToken) mutable {
×
36
#ifdef _WIN32
37
        SetThreadDescription(GetCurrentThread(),
38
                             L"Home Assistant Handler Sensor Update Thread");
39
#endif
40
        using sc = std::chrono::steady_clock;
41

42
        // Delay updating the state initially as the feed is still stabilizing
43
        sc::time_point lastStateUpdate =
UNCOV
44
            sc::now() +
×
UNCOV
45
            std::chrono::duration_cast<std::chrono::seconds>(debounceTime);
×
UNCOV
46
        std::unique_lock lk(mtx_);
×
47
        do {
UNCOV
48
          cv_.wait_for(lk, 5s);
×
49

UNCOV
50
          const bool stateChanging = IsStateChanging();
×
UNCOV
51
          const bool debounce = (sc::now() - lastStateUpdate > debounceTime);
×
52

UNCOV
53
          if ((stateChanging && debounce) || IsStateBecomingUnknown()) {
×
UNCOV
54
            buf_.clear();
×
55
            try {
UNCOV
56
              thread_local std::string payload; // reusable buffer
×
UNCOV
57
              PreparePostRequest(wCurl, buf_, payload);
×
UNCOV
58
              wCurl(curl_easy_perform);
×
UNCOV
59
              HandlePostResponse(wCurl, buf_);
×
UNCOV
60
              lastStateUpdate = sc::now();
×
61
            } catch (const std::exception &e) {
×
62
              LOGGER->error(e.what());
×
63
            }
×
64
          }
UNCOV
65
        } while (!stopToken.stop_requested());
×
UNCOV
66
      });
×
UNCOV
67
}
×
68

UNCOV
69
void ThreadedHassHandler::Stop() { updaterThread_ = {}; }
×
70

UNCOV
71
void ThreadedHassHandler::UpdateState_Impl(std::string_view state,
×
72
                                           const json &attributes) {
UNCOV
73
  std::unique_lock lk(mtx_);
×
UNCOV
74
  UpdateStateInternal(state, attributes);
×
UNCOV
75
  cv_.notify_all();
×
UNCOV
76
}
×
77

78
} // namespace callback
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc