1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-15 07:10:33 +01:00
esphome/esphome/components/optolink/optolink_sensor_base.h

48 lines
1014 B
C++

#pragma once
#include "esphome/core/log.h"
#include <VitoWiFi.h>
namespace esphome {
namespace optolink {
class Optolink;
class OptolinkSensorBase {
protected:
Optolink *optolink_;
bool writeable_;
IDatapoint *datapoint_ = nullptr;
uint32_t address_;
int bytes_;
int div_ratio_ = 1;
void setup_datapoint();
void update_datapoint(float value);
public:
OptolinkSensorBase(Optolink *optolink, bool writeable = false) {
optolink_ = optolink;
writeable_ = writeable;
}
void set_address(uint32_t address) { address_ = address; }
void set_bytes(int bytes) { bytes_ = bytes; }
void set_div_ratio(int div_ratio) { div_ratio_ = div_ratio; }
protected:
virtual const std::string &get_sensor_name() = 0;
virtual void value_changed(float state) = 0;
};
class conv2_100_F : public DPType {
public:
void encode(uint8_t *out, DPValue in);
DPValue decode(const uint8_t *in);
const size_t getLength() const { return 2; }
};
} // namespace optolink
} // namespace esphome