OpenDTU-old/include/PowerMeterProvider.h
Bernhard Kirchen 33683d26c8 powermeter refactor: rename providers in enum
the enum values did not change, but their name (only relevant in the
code) are now more expressive.
2024-06-26 20:51:56 +02:00

47 lines
1.0 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Configuration.h"
class PowerMeterProvider {
public:
virtual ~PowerMeterProvider() { }
enum class Type : unsigned {
MQTT = 0,
SDM1PH = 1,
SDM3PH = 2,
HTTP_JSON = 3,
SERIAL_SML = 4,
SMAHM2 = 5,
HTTP_SML = 6
};
// returns true if the provider is ready for use, false otherwise
virtual bool init() = 0;
virtual void deinit() = 0;
virtual void loop() = 0;
virtual float getPowerTotal() const = 0;
uint32_t getLastUpdate() const { return _lastUpdate; }
bool isDataValid() const;
void mqttLoop() const;
protected:
PowerMeterProvider() {
auto const& config = Configuration.get();
_verboseLogging = config.PowerMeter.VerboseLogging;
}
void gotUpdate() { _lastUpdate = millis(); }
bool _verboseLogging;
private:
virtual void doMqttPublish() const = 0;
uint32_t _lastUpdate = 0;
mutable uint32_t _lastMqttPublish = 0;
};