mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-07 13:24:56 +02:00
Refactor fan platform to resemble climate/cover platforms (#2848)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: rob-deutsch <robzyb+altgithub@gmail.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/output/binary_output.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/components/fan/fan_state.h"
|
||||
#include "esphome/components/fan/fan.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace hbridge {
|
||||
@@ -13,7 +13,7 @@ enum DecayMode {
|
||||
DECAY_MODE_FAST = 1,
|
||||
};
|
||||
|
||||
class HBridgeFan : public fan::FanState {
|
||||
class HBridgeFan : public Component, public fan::Fan {
|
||||
public:
|
||||
HBridgeFan(int speed_count, DecayMode decay_mode) : speed_count_(speed_count), decay_mode_(decay_mode) {}
|
||||
|
||||
@@ -22,25 +22,22 @@ class HBridgeFan : public fan::FanState {
|
||||
void set_enable_pin(output::FloatOutput *enable) { enable_ = enable; }
|
||||
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||
fan::FanTraits get_traits() override;
|
||||
|
||||
fan::FanStateCall brake();
|
||||
|
||||
int get_speed_count() { return this->speed_count_; }
|
||||
// update Hbridge without a triggered FanState change, eg. for acceleration/deceleration ramping
|
||||
void internal_update() { this->next_update_ = true; }
|
||||
fan::FanCall brake();
|
||||
|
||||
protected:
|
||||
output::FloatOutput *pin_a_;
|
||||
output::FloatOutput *pin_b_;
|
||||
output::FloatOutput *enable_{nullptr};
|
||||
output::BinaryOutput *oscillating_{nullptr};
|
||||
bool next_update_{true};
|
||||
int speed_count_{};
|
||||
DecayMode decay_mode_{DECAY_MODE_SLOW};
|
||||
|
||||
void control(const fan::FanCall &call) override;
|
||||
void write_state_();
|
||||
|
||||
void set_hbridge_levels_(float a_level, float b_level);
|
||||
void set_hbridge_levels_(float a_level, float b_level, float enable);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user