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

bcpearce / hass-motion-detection-addon / 21126887229

19 Jan 2026 05:54AM UTC coverage: 17.99% (-32.0%) from 49.971%
21126887229

Pull #26

github

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

292 of 1865 branches covered (15.66%)

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%)

28.54 hits per line

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

0.0
/src/VideoSource/Http.cxx
1
#include "Logger.h"
2

3
#include "VideoSource/Http.h"
4

5
#include <chrono>
6
#include <exception>
7
#include <format>
8
#include <ranges>
9
#include <span>
10

11
#include <opencv2/imgcodecs.hpp>
12

13
#include "Util/BufferOperations.h"
14
#include "Util/CurlWrapper.h"
15

16
namespace video_source {
17

UNCOV
18
HttpVideoSource::HttpVideoSource(const boost::url &url,
×
UNCOV
19
                                 const std::string &token)
×
UNCOV
20
    : url_{url} {
×
UNCOV
21
  wCurl_(curl_easy_setopt, CURLOPT_URL, url_.c_str());
×
UNCOV
22
  wCurl_(curl_easy_setopt, CURLOPT_WRITEFUNCTION, util::FillBufferCallback);
×
UNCOV
23
  wCurl_(curl_easy_setopt, CURLOPT_WRITEDATA, &buf_);
×
24

UNCOV
25
  if (!token.empty()) {
×
26
    wCurl_(curl_easy_setopt, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
×
27
    wCurl_(curl_easy_setopt, CURLOPT_XOAUTH2_BEARER, token.c_str());
×
28
  }
UNCOV
29
}
×
30

31
HttpVideoSource::HttpVideoSource(const boost::url &url,
×
32
                                 const std::string &username,
33
                                 const std::string &password)
×
34
    : HttpVideoSource(url) {
×
35
  errBuf_.fill('\0');
×
36
  wCurl_(curl_easy_setopt, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
×
37
  wCurl_(curl_easy_setopt, CURLOPT_USERNAME, username.c_str());
×
38
  wCurl_(curl_easy_setopt, CURLOPT_PASSWORD, password.c_str());
×
39
}
×
40

UNCOV
41
void HttpVideoSource::StartStream(unsigned long long maxFrames) {
×
UNCOV
42
  if (isActive_) {
×
43
    throw std::runtime_error("HTTP stream is already running");
×
44
  }
45

UNCOV
46
  isActive_ = true;
×
UNCOV
47
  while (isActive_.load() && GetFrameCount() < maxFrames) {
×
48
    try {
UNCOV
49
      GetNextFrame();
×
50
    } catch (const std::exception &e) {
×
51
      LOGGER->error("Error getting frame from {}: {}", url_, e.what());
×
52
    }
×
UNCOV
53
    std::this_thread::sleep_for(delayBetweenFrames);
×
54
  }
UNCOV
55
  isActive_ = false;
×
UNCOV
56
}
×
57

UNCOV
58
void HttpVideoSource::StopStream() { isActive_.store(false); }
×
59

UNCOV
60
Frame HttpVideoSource::GetNextFrame() {
×
UNCOV
61
  if (wCurl_) {
×
UNCOV
62
    buf_.clear();
×
63

UNCOV
64
    wCurl_(curl_easy_setopt, CURLOPT_TIMEOUT, timeout.count());
×
UNCOV
65
    const auto res = wCurl_(curl_easy_perform);
×
66

UNCOV
67
    if (res == CURLE_OK) {
×
UNCOV
68
      int code{0};
×
UNCOV
69
      wCurl_(curl_easy_getinfo, CURLINFO_RESPONSE_CODE, &code);
×
70

UNCOV
71
      if (code == 200) {
×
72
        // Good case, expect an image
UNCOV
73
        auto frame = GetCurrentFrame();
×
UNCOV
74
        cv::imdecode(buf_, cv::IMREAD_COLOR, &frame.img);
×
UNCOV
75
        ++frame.id;
×
UNCOV
76
        frame.timeStamp = std::chrono::steady_clock::now();
×
UNCOV
77
        VideoSource::SetFrame(frame);
×
UNCOV
78
        return frame;
×
UNCOV
79
      } else {
×
80
        // Bad case, expect a string
81
        std::string_view msg(buf_.data(), buf_.size());
×
82
        throw std::runtime_error(std::format("http error: ({}) {}", code, msg));
×
83
      }
84
    } else {
85
      const std::string_view errMsg(errBuf_.data(), CURL_ERROR_SIZE);
×
86
      throw std::runtime_error(
87
          std::format("libcurl: ({}) {}", int(res), errMsg));
×
88
    }
89
  }
90
  throw std::runtime_error(
91
      std::format("Failed to get image at {}", url_.c_str()));
×
92
}
93

94
} // namespace video_source
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