mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-31 10:08:27 +02:00
ac0d921413
* Socket refactor and SSL * esp-idf temp * Fixes * Echo component and noise * Add noise API transport support * Updates * ESP-IDF * Complete * Fixes * Fixes * Versions update * New i2c APIs * Complete i2c refactor * SPI migration * Revert ESP Preferences migration, too complex for now * OTA support * Remove echo again * Remove ssl again * GPIOFlags updates * Rename esphal and ICACHE_RAM_ATTR * Make ESP32 arduino compilable again * Fix GPIO flags * Complete pin registry refactor and fixes * Fixes to make test1 compile * Remove sdkconfig file * Ignore sdkconfig file * Fixes in reviewing * Make test2 compile * Make test4 compile * Make test5 compile * Run clang-format * Fix lint errors * Use esp-idf APIs instead of btStart * Another round of fixes * Start implementing ESP8266 * Make test3 compile * Guard esp8266 code * Lint * Reformat * Fixes * Fixes v2 * more fixes * ESP-IDF tidy target * Convert ARDUINO_ARCH_ESPxx * Update WiFiSignalSensor * Update time ifdefs * OTA needs millis from hal * RestartSwitch needs delay from hal * ESP-IDF Uart * Fix OTA blank password * Allow setting sdkconfig * Fix idf partitions and allow setting sdkconfig from yaml * Re-add read/write compat APIs and fix esp8266 uart * Fix esp8266 store log strings in flash * Fix ESP32 arduino preferences not initialized * Update ifdefs * Change how sdkconfig change is detected * Add checks to ci-custom and fix them * Run clang-format * Add esp-idf clang-tidy target and fix errors * Fixes from clang-tidy idf round 2 * Fixes from compiling tests with esp-idf * Run clang-format * Switch test5.yaml to esp-idf * Implement ESP8266 Preferences * Lint * Re-do PIO package version selection a bit * Fix arduinoespressif32 package version * Fix unit tests * Lint * Lint fixes * Fix readv/writev not defined * Fix graphing component * Re-add all old options from core/config.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
89 lines
3.6 KiB
C++
89 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#ifdef USE_ARDUINO
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/log.h"
|
|
#include "esphome/components/uart/uart.h"
|
|
#include "esphome/components/climate/climate.h"
|
|
#ifdef USE_REMOTE_TRANSMITTER
|
|
#include "esphome/components/remote_base/midea_protocol.h"
|
|
#include "esphome/components/remote_transmitter/remote_transmitter.h"
|
|
#endif
|
|
#include <Appliance/ApplianceBase.h>
|
|
#include <Helpers/Logger.h>
|
|
|
|
namespace esphome {
|
|
namespace midea {
|
|
|
|
using climate::ClimatePreset;
|
|
using climate::ClimateTraits;
|
|
using climate::ClimateMode;
|
|
using climate::ClimateSwingMode;
|
|
using climate::ClimateFanMode;
|
|
|
|
template<typename T>
|
|
class ApplianceBase : public Component, public uart::UARTDevice, public climate::Climate, public Stream {
|
|
static_assert(std::is_base_of<dudanov::midea::ApplianceBase, T>::value,
|
|
"T must derive from dudanov::midea::ApplianceBase class");
|
|
|
|
public:
|
|
ApplianceBase() {
|
|
this->base_.setStream(this);
|
|
this->base_.addOnStateCallback(std::bind(&ApplianceBase::on_status_change, this));
|
|
dudanov::midea::ApplianceBase::setLogger([](int level, const char *tag, int line, String format, va_list args) {
|
|
esp_log_vprintf_(level, tag, line, format.c_str(), args);
|
|
});
|
|
}
|
|
bool can_proceed() override {
|
|
return this->base_.getAutoconfStatus() != dudanov::midea::AutoconfStatus::AUTOCONF_PROGRESS;
|
|
}
|
|
float get_setup_priority() const override { return setup_priority::BEFORE_CONNECTION; }
|
|
void setup() override { this->base_.setup(); }
|
|
void loop() override { this->base_.loop(); }
|
|
void set_period(uint32_t ms) { this->base_.setPeriod(ms); }
|
|
void set_response_timeout(uint32_t ms) { this->base_.setTimeout(ms); }
|
|
void set_request_attempts(uint32_t attempts) { this->base_.setNumAttempts(attempts); }
|
|
void set_beeper_feedback(bool state) { this->base_.setBeeper(state); }
|
|
void set_autoconf(bool value) { this->base_.setAutoconf(value); }
|
|
void set_supported_modes(std::set<ClimateMode> modes) { this->supported_modes_ = std::move(modes); }
|
|
void set_supported_swing_modes(std::set<ClimateSwingMode> modes) { this->supported_swing_modes_ = std::move(modes); }
|
|
void set_supported_presets(std::set<ClimatePreset> presets) { this->supported_presets_ = std::move(presets); }
|
|
void set_custom_presets(std::set<std::string> presets) { this->supported_custom_presets_ = std::move(presets); }
|
|
void set_custom_fan_modes(std::set<std::string> modes) { this->supported_custom_fan_modes_ = std::move(modes); }
|
|
virtual void on_status_change() = 0;
|
|
#ifdef USE_REMOTE_TRANSMITTER
|
|
void set_transmitter(remote_transmitter::RemoteTransmitterComponent *transmitter) {
|
|
this->transmitter_ = transmitter;
|
|
}
|
|
void transmit_ir(remote_base::MideaData &data) {
|
|
data.finalize();
|
|
auto transmit = this->transmitter_->transmit();
|
|
remote_base::MideaProtocol().encode(transmit.get_data(), data);
|
|
transmit.perform();
|
|
}
|
|
#endif
|
|
|
|
int available() override { return uart::UARTDevice::available(); }
|
|
int read() override { return uart::UARTDevice::read(); }
|
|
int peek() override { return uart::UARTDevice::peek(); }
|
|
void flush() override { uart::UARTDevice::flush(); }
|
|
size_t write(uint8_t data) override { return uart::UARTDevice::write(data); }
|
|
|
|
protected:
|
|
T base_;
|
|
std::set<ClimateMode> supported_modes_{};
|
|
std::set<ClimateSwingMode> supported_swing_modes_{};
|
|
std::set<ClimatePreset> supported_presets_{};
|
|
std::set<std::string> supported_custom_presets_{};
|
|
std::set<std::string> supported_custom_fan_modes_{};
|
|
#ifdef USE_REMOTE_TRANSMITTER
|
|
remote_transmitter::RemoteTransmitterComponent *transmitter_{nullptr};
|
|
#endif
|
|
};
|
|
|
|
} // namespace midea
|
|
} // namespace esphome
|
|
|
|
#endif // USE_ARDUINO
|