Files
esphome-dev/esphome/components/mhz19/mhz19.h
T
Andrew Zaborowski a62b6548d2 Make some Action methods protected
Apparently play()/stop() etc. are not meant to be called directly by
users of the class and if they're called directly that would not give
the expected result for the classes that have an empty play().

Make all methods except play_complex, stop_comples and is_running
protected.  While there also make RemoteTransmitterActionBase::encode
protected.
2020-05-01 12:44:30 +02:00

69 lines
1.9 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/uart/uart.h"
namespace esphome {
namespace mhz19 {
enum MHZ19ABCLogic { MHZ19_ABC_NONE = 0, MHZ19_ABC_ENABLED, MHZ19_ABC_DISABLED };
class MHZ19Component : public PollingComponent, public uart::UARTDevice {
public:
float get_setup_priority() const override;
void setup() override;
void update() override;
void dump_config() override;
void calibrate_zero();
void abc_enable();
void abc_disable();
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
void set_co2_sensor(sensor::Sensor *co2_sensor) { co2_sensor_ = co2_sensor; }
void set_abc_enabled(bool abc_enabled) { abc_boot_logic_ = abc_enabled ? MHZ19_ABC_ENABLED : MHZ19_ABC_DISABLED; }
protected:
bool mhz19_write_command_(const uint8_t *command, uint8_t *response);
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *co2_sensor_{nullptr};
MHZ19ABCLogic abc_boot_logic_{MHZ19_ABC_NONE};
};
template<typename... Ts> class MHZ19CalibrateZeroAction : public Action<Ts...> {
public:
MHZ19CalibrateZeroAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
protected:
void play_(Ts... x) override { this->mhz19_->calibrate_zero(); }
MHZ19Component *mhz19_;
};
template<typename... Ts> class MHZ19ABCEnableAction : public Action<Ts...> {
public:
MHZ19ABCEnableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
protected:
void play_(Ts... x) override { this->mhz19_->abc_enable(); }
MHZ19Component *mhz19_;
};
template<typename... Ts> class MHZ19ABCDisableAction : public Action<Ts...> {
public:
MHZ19ABCDisableAction(MHZ19Component *mhz19) : mhz19_(mhz19) {}
protected:
void play_(Ts... x) override { this->mhz19_->abc_disable(); }
MHZ19Component *mhz19_;
};
} // namespace mhz19
} // namespace esphome