Trying to prep this

This commit is contained in:
Jordan Zucker 2024-11-16 23:35:55 -08:00
parent dfa6c6f433
commit a5d0144ad7
10 changed files with 128 additions and 30 deletions

View file

@ -5,36 +5,52 @@ import esphome.config_validation as cv
from .. import CONF_VORNADO_ID, VornadoIR, vornado_ir_ns
CODEOWNERS = ["@jzucker2"]
FanButton = vornado_ir_ns.class_("FanButton", button.Button)
PowerButton = vornado_ir_ns.class_("PowerButton", button.Button)
ChangeDirectionButton = vornado_ir_ns.class_("ChangeDirectionButton", button.Button)
IncreaseButton = vornado_ir_ns.class_("IncreaseButton", button.Button)
DecreaseButton = vornado_ir_ns.class_("DecreaseButton", button.Button)
# Toto IR buttons
CONF_FAN = "fan"
# Vornado IR buttons
CONF_POWER = "power"
CONF_CHANGE_DIRECTION = "change_direction"
CONF_INCREASE = "increase"
CONF_DECREASE = "decrease"
# Additional icons
ICON_POWER_TOGGLE = "mdi:power-cycle"
ICON_FAN = "mdi:heat-wave"
ICON_CHANGE_DIRECTION = "mdi:power-cycle"
ICON_INCREASE = "mdi:power-cycle"
ICON_DECREASE = "mdi:power-cycle"
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_VORNADO_ID): cv.use_id(VornadoIR),
cv.Optional(CONF_FAN): button.button_schema(
FanButton,
icon=ICON_FAN,
),
cv.Optional(CONF_POWER): button.button_schema(
PowerButton,
icon=ICON_POWER_TOGGLE,
),
cv.Optional(CONF_CHANGE_DIRECTION): button.button_schema(
ChangeDirectionButton,
icon=ICON_CHANGE_DIRECTION,
),
cv.Optional(ICON_INCREASE): button.button_schema(
IncreaseButton,
icon=ICON_INCREASE,
),
cv.Optional(ICON_DECREASE): button.button_schema(
DecreaseButton,
icon=ICON_DECREASE,
),
}
).extend(cv.COMPONENT_SCHEMA)
async def to_code(config):
for button_type in [
CONF_FAN,
CONF_POWER,
CONF_CHANGE_DIRECTION,
CONF_INCREASE,
CONF_DECREASE,
]:
if conf := config.get(button_type):
btn = await button.new_button(conf)

View file

@ -0,0 +1,11 @@
#include "power.h"
namespace esphome {
namespace vornado_ir {
static const char *const TAG = "vornado_ir.change_direction_button";
void ChangeDirectionButton::press_action() { this->parent_->send_change_direction(); }
} // namespace vornado_ir
} // namespace esphome

View file

@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../vornado_ir.h"
namespace esphome {
namespace vornado_ir {
class ChangeDirectionButton : public button::Button, public Parented<VornadoIR> {
public:
ChangeDirectionButton() = default;
protected:
void press_action() override;
};
} // namespace vornado_ir
} // namespace esphome

View file

@ -0,0 +1,11 @@
#include "power.h"
namespace esphome {
namespace vornado_ir {
static const char *const TAG = "vornado_ir.decrease_button";
void DecreaseButton::press_action() { this->parent_->send_decrease(); }
} // namespace vornado_ir
} // namespace esphome

View file

@ -6,9 +6,9 @@
namespace esphome {
namespace vornado_ir {
class FanButton : public button::Button, public Parented<VornadoIR> {
class DecreaseButton : public button::Button, public Parented<VornadoIR> {
public:
FanButton() = default;
DecreaseButton() = default;
protected:
void press_action() override;

View file

@ -1,11 +0,0 @@
#include "fan.h"
namespace esphome {
namespace vornado_ir {
static const char *const TAG = "vornado_ir.fan_button";
void FanButton::press_action() { this->parent_->send_start_fans(true); }
} // namespace vornado_ir
} // namespace esphome

View file

@ -0,0 +1,11 @@
#include "power.h"
namespace esphome {
namespace vornado_ir {
static const char *const TAG = "vornado_ir.increase_button";
void IncreaseButton::press_action() { this->parent_->send_increase(); }
} // namespace vornado_ir
} // namespace esphome

View file

@ -0,0 +1,18 @@
#pragma once
#include "esphome/components/button/button.h"
#include "../vornado_ir.h"
namespace esphome {
namespace vornado_ir {
class IncreaseButton : public button::Button, public Parented<VornadoIR> {
public:
IncreaseButton() = default;
protected:
void press_action() override;
};
} // namespace vornado_ir
} // namespace esphome

View file

@ -12,19 +12,41 @@ void VornadoIR::setup() { ESP_LOGCONFIG(TAG, "Setting up VornadoIR ..."); }
void VornadoIR::loop() {}
void VornadoIR::dump_config() { ESP_LOGCONFIG(TAG, "Toto IR"); }
void VornadoIR::dump_config() { ESP_LOGCONFIG(TAG, "Vornado IR"); }
void VornadoIR::send_power_toggle(bool reset_timer) {
void VornadoIR::send_power_toggle() {
ESP_LOGI(TAG, "Sending power toggle request");
this->transmit_(TOTO_IR_FIRST_POWER_TIMINGS);
this->transmit_(TOTO_IR_SECOND_POWER_TIMINGS);
this->transmit_(TOTO_IR_THIRD_POWER_TIMINGS);
}
void VornadoIR::send_start_fans(bool reset_timer) {
ESP_LOGI(TAG, "Sending start fans request");
this->transmit_(TOTO_IR_FIRST_FAN_TIMINGS);
this->transmit_(TOTO_IR_SECOND_FAN_TIMINGS);
void VornadoIR::send_power_toggle() {
ESP_LOGI(TAG, "Sending power toggle request");
this->transmit_(TOTO_IR_FIRST_POWER_TIMINGS);
this->transmit_(TOTO_IR_SECOND_POWER_TIMINGS);
this->transmit_(TOTO_IR_THIRD_POWER_TIMINGS);
}
void VornadoIR::send_change_direction() {
ESP_LOGI(TAG, "Sending change direction request");
this->transmit_(TOTO_IR_FIRST_POWER_TIMINGS);
this->transmit_(TOTO_IR_SECOND_POWER_TIMINGS);
this->transmit_(TOTO_IR_THIRD_POWER_TIMINGS);
}
void VornadoIR::send_increase() {
ESP_LOGI(TAG, "Sending increase request");
this->transmit_(TOTO_IR_FIRST_POWER_TIMINGS);
this->transmit_(TOTO_IR_SECOND_POWER_TIMINGS);
this->transmit_(TOTO_IR_THIRD_POWER_TIMINGS);
}
void VornadoIR::send_decrease() {
ESP_LOGI(TAG, "Sending decrease request");
this->transmit_(TOTO_IR_FIRST_POWER_TIMINGS);
this->transmit_(TOTO_IR_SECOND_POWER_TIMINGS);
this->transmit_(TOTO_IR_THIRD_POWER_TIMINGS);
}
void VornadoIR::transmit_(RawTimings ir_code) {

View file

@ -19,8 +19,10 @@ class VornadoIR : public Component, public remote_base::RemoteTransmittable {
// general functions
void transmit_(RawTimings ir_code);
// direct actions
void send_power_toggle(bool reset_timer = false);
void send_start_fans(bool reset_timer = false);
void send_power_toggle();
void send_change_direction();
void send_increase();
void send_decrease();
};
} // namespace vornado_ir