esphome-tw7100/tw7100.h

63 lines
2.8 KiB
C
Raw Normal View History

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/log.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/switch/switch.h"
2024-09-16 22:38:48 +02:00
#include "esphome/components/select/select.h"
#include "esphome/components/uart/uart.h"
2024-09-16 22:38:48 +02:00
#include "select/tw7100_select.h"
namespace esphome {
namespace tw7100 {
class tw7100Component : public PollingComponent, public uart::UARTDevice {
private:
unsigned long _max_loop_time = 30;
unsigned long _readStringUntil_timeout = _max_loop_time/5; // number of milliseconds to wait for the next char before aborting timed read
unsigned long _timeout_after_cmd = 1000;
public:
tw7100Component() = default;
std::string readStringUntil(char terminator);
void push_cmd(std::string cmd, std::string param);
void update_sensor(std::pair<std::string, std::string> data);
std::pair<std::string, std::string> parse_response(std::string data);
int timedRead(void);
void setup() override;
void update() override;
void loop() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::BUS; }
void set_powered(binary_sensor::BinarySensor *powered) { this->powered_ = powered; }
void set_has_signal(binary_sensor::BinarySensor *has_signal) { this->has_signal_ = has_signal; }
void set_lamp_hours(sensor::Sensor *lamp_hours) { this->lamp_hours_ = lamp_hours; }
void set_power_status(sensor::Sensor *power_status) { this->power_status_ = power_status; }
void set_signal_status(sensor::Sensor *signal_status) { this->signal_status_ = signal_status; }
void set_luminance_level(sensor::Sensor *luminance_level) { this->luminance_level_ = luminance_level; }
void set_serial(text_sensor::TextSensor *serial) { this->serial_ = serial; }
void set_set_power(switch_::Switch *switch_) { this->power_switch_ = switch_; }
void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; }
2024-09-16 22:38:48 +02:00
void set_set_source(tw7100::tw7100Select *source_) { this->source_select_ = source_; }
2024-09-17 00:58:39 +02:00
void set_set_luminance(tw7100::tw7100Select *luminance_) { this->luminance_select_ = luminance_; }
protected:
binary_sensor::BinarySensor *powered_{nullptr};
binary_sensor::BinarySensor *has_signal_{nullptr};
sensor::Sensor *lamp_hours_{nullptr};
sensor::Sensor *power_status_{nullptr};
sensor::Sensor *signal_status_{nullptr};
sensor::Sensor *luminance_level_{nullptr};
text_sensor::TextSensor *serial_{nullptr};
switch_::Switch *power_switch_{nullptr};
switch_::Switch *btaudio_switch_{nullptr};
2024-09-16 22:38:48 +02:00
tw7100::tw7100Select *source_select_{nullptr};
2024-09-17 00:58:39 +02:00
tw7100::tw7100Select *luminance_select_{nullptr};
};
} // namespace tw7100
} // namespace esphome