Bug fixes and switch

This commit is contained in:
T
2025-03-20 16:49:53 +01:00
parent 2c29ef0e71
commit 76f27cdfeb
5 changed files with 120 additions and 62 deletions

View File

@@ -2,7 +2,14 @@
#include "esphome/core/component.h"
#include "esphome/components/uart/uart.h"
#ifdef USE_SELECT
#undef USE_SENSOR
#undef USE_BINARY_SENSOR
#undef USE_TEXT_SENSOR
#undef USE_SELECT
#undef USE_SWITCH
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
#ifdef USE_BINARY_SENSOR
@@ -14,13 +21,17 @@
#ifdef USE_SELECT
#include "esphome/components/select/select.h"
#endif
#ifdef USE_SWITCH
#include "esphome/components/switch/switch.h"
#endif
namespace esphome {
namespace optoma_rs232 {
// clang-format off
class DummySensor { public: template<typename M> static void publish_state(M) {} };
class DummySelect {};
class DummySelect : public DummySensor {};
class DummySwitch : public DummySensor {};
// clang-format on
enum Inputs {
@@ -37,19 +48,23 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
float get_setup_priority() const override { return setup_priority::DATA; }
void update() override;
void beamer_input_select_changed(const std::string &, size_t);
void beamer_power_switch_changed(bool);
// clang-format off
#ifndef USE_SENSOR
#define SUB_SENSOR(name) protected: DummySensor *name##_sensor_{nullptr}; public:
#define SUB_SENSOR(name) protected: DummySensor *name## _sensor_{nullptr}; public:
#endif
#ifndef USE_BINARY_SENSOR
#define SUB_BINARY_SENSOR(name) protected: DummySensor *name##_binary_sensor_{nullptr}; public:
#define SUB_BINARY_SENSOR(name) protected: DummySensor *name## _binary_sensor_{nullptr}; public:
#endif
#ifndef USE_TEXT_SENSOR
#define SUB_TEXT_SENSOR(name) protected: DummySensor *name##_text_sensor_{nullptr}; public:
#define SUB_TEXT_SENSOR(name) protected: DummySensor *name## _text_sensor_{nullptr}; public:
#endif
#ifndef USE_SELECT
#define SUB_SELECT(name) protected: DummySelect *name##_select_{nullptr}; public:
#define SUB_SELECT(name) protected: DummySelect *name## _select_{nullptr}; public:
#endif
#ifndef USE_SWITCH
#define SUB_SWITCH(name) protected: DummySwitch *name## _switch_{nullptr}; public:
#endif
// clang-format on
@@ -60,6 +75,7 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
SUB_BINARY_SENSOR(beamer_power)
SUB_TEXT_SENSOR(beamer_input)
SUB_SELECT(beamer_input)
SUB_SWITCH(beamer_power)
protected:
Inputs current_input_{UNKNOWN};
@@ -74,6 +90,7 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
size_t cursor_ = 0;
void publish_input_(const std::string &state) const;
void publish_power_(bool state) const;
};
#ifdef USE_SELECT
@@ -82,6 +99,12 @@ class InputSelect : public select::Select, public Parented<OptomaRS232Component>
void control(const std::string &value) override;
};
#endif
#ifdef USE_SWITCH
class PowerSwitch : public switch_::Switch, public Parented<OptomaRS232Component> {
protected:
void write_state(bool state) override;
};
#endif
} // namespace optoma_rs232
} // namespace esphome