instead of reading the main config's powermeter struct(s), the individual power meters now are instanciated using a copy of their respective config. this allows to instanciate different power meters with different configs. as a first step, this simplifies instanciating power meters for test purposes.
38 lines
959 B
C++
38 lines
959 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <variant>
|
|
#include <memory>
|
|
#include <stdint.h>
|
|
#include "HttpGetter.h"
|
|
#include "Configuration.h"
|
|
#include "PowerMeterProvider.h"
|
|
|
|
using Auth_t = HttpRequestConfig::Auth;
|
|
using Unit_t = PowerMeterHttpJsonValue::Unit;
|
|
|
|
class PowerMeterHttpJson : public PowerMeterProvider {
|
|
public:
|
|
explicit PowerMeterHttpJson(PowerMeterHttpJsonConfig const& cfg)
|
|
: _cfg(cfg) { }
|
|
|
|
bool init() final;
|
|
void loop() final;
|
|
float getPowerTotal() const final;
|
|
void doMqttPublish() const final;
|
|
|
|
using power_values_t = std::array<float, POWERMETER_HTTP_JSON_MAX_VALUES>;
|
|
using poll_result_t = std::variant<power_values_t, String>;
|
|
poll_result_t poll();
|
|
|
|
private:
|
|
PowerMeterHttpJsonConfig const _cfg;
|
|
|
|
uint32_t _lastPoll;
|
|
|
|
power_values_t _powerValues;
|
|
|
|
std::array<std::unique_ptr<HttpGetter>, POWERMETER_HTTP_JSON_MAX_VALUES> _httpGetters;
|
|
};
|