mirror of
https://github.com/esphome/esphome.git
synced 2026-02-12 18:51:55 +00:00
Compare commits
2 Commits
json_web_s
...
speed_coun
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a30786b055 | ||
|
|
192abf95ce |
@@ -65,7 +65,7 @@ void FanCall::validate_() {
|
|||||||
auto traits = this->parent_.get_traits();
|
auto traits = this->parent_.get_traits();
|
||||||
|
|
||||||
if (this->speed_.has_value()) {
|
if (this->speed_.has_value()) {
|
||||||
this->speed_ = clamp(*this->speed_, 1, traits.supported_speed_count());
|
this->speed_ = clamp(*this->speed_, 1, static_cast<int>(traits.supported_speed_count()));
|
||||||
|
|
||||||
// https://developers.home-assistant.io/docs/core/entity/fan/#preset-modes
|
// https://developers.home-assistant.io/docs/core/entity/fan/#preset-modes
|
||||||
// "Manually setting a speed must disable any set preset mode"
|
// "Manually setting a speed must disable any set preset mode"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace fan {
|
|||||||
class FanTraits {
|
class FanTraits {
|
||||||
public:
|
public:
|
||||||
FanTraits() = default;
|
FanTraits() = default;
|
||||||
FanTraits(bool oscillation, bool speed, bool direction, int speed_count)
|
FanTraits(bool oscillation, bool speed, bool direction, uint8_t speed_count)
|
||||||
: oscillation_(oscillation), speed_(speed), direction_(direction), speed_count_(speed_count) {}
|
: oscillation_(oscillation), speed_(speed), direction_(direction), speed_count_(speed_count) {}
|
||||||
|
|
||||||
/// Return if this fan supports oscillation.
|
/// Return if this fan supports oscillation.
|
||||||
@@ -23,9 +23,9 @@ class FanTraits {
|
|||||||
/// Set whether this fan supports speed levels.
|
/// Set whether this fan supports speed levels.
|
||||||
void set_speed(bool speed) { this->speed_ = speed; }
|
void set_speed(bool speed) { this->speed_ = speed; }
|
||||||
/// Return how many speed levels the fan has
|
/// Return how many speed levels the fan has
|
||||||
int supported_speed_count() const { return this->speed_count_; }
|
uint8_t supported_speed_count() const { return this->speed_count_; }
|
||||||
/// Set how many speed levels this fan has.
|
/// Set how many speed levels this fan has.
|
||||||
void set_supported_speed_count(int speed_count) { this->speed_count_ = speed_count; }
|
void set_supported_speed_count(uint8_t speed_count) { this->speed_count_ = speed_count; }
|
||||||
/// Return if this fan supports changing direction
|
/// Return if this fan supports changing direction
|
||||||
bool supports_direction() const { return this->direction_; }
|
bool supports_direction() const { return this->direction_; }
|
||||||
/// Set whether this fan supports changing direction
|
/// Set whether this fan supports changing direction
|
||||||
@@ -61,7 +61,7 @@ class FanTraits {
|
|||||||
bool oscillation_{false};
|
bool oscillation_{false};
|
||||||
bool speed_{false};
|
bool speed_{false};
|
||||||
bool direction_{false};
|
bool direction_{false};
|
||||||
int speed_count_{};
|
uint8_t speed_count_{};
|
||||||
std::vector<const char *> preset_modes_{};
|
std::vector<const char *> preset_modes_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ CONFIG_SCHEMA = (
|
|||||||
cv.Optional(CONF_DECAY_MODE, default="SLOW"): cv.enum(
|
cv.Optional(CONF_DECAY_MODE, default="SLOW"): cv.enum(
|
||||||
DECAY_MODE_OPTIONS, upper=True
|
DECAY_MODE_OPTIONS, upper=True
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_SPEED_COUNT, default=100): cv.int_range(min=1),
|
cv.Optional(CONF_SPEED_COUNT, default=100): cv.int_range(min=1, max=255),
|
||||||
cv.Optional(CONF_ENABLE_PIN): cv.use_id(output.FloatOutput),
|
cv.Optional(CONF_ENABLE_PIN): cv.use_id(output.FloatOutput),
|
||||||
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ enum DecayMode {
|
|||||||
|
|
||||||
class HBridgeFan : public Component, public fan::Fan {
|
class HBridgeFan : public Component, public fan::Fan {
|
||||||
public:
|
public:
|
||||||
HBridgeFan(int speed_count, DecayMode decay_mode) : speed_count_(speed_count), decay_mode_(decay_mode) {}
|
HBridgeFan(uint8_t speed_count, DecayMode decay_mode) : speed_count_(speed_count), decay_mode_(decay_mode) {}
|
||||||
|
|
||||||
void set_pin_a(output::FloatOutput *pin_a) { pin_a_ = pin_a; }
|
void set_pin_a(output::FloatOutput *pin_a) { pin_a_ = pin_a; }
|
||||||
void set_pin_b(output::FloatOutput *pin_b) { pin_b_ = pin_b; }
|
void set_pin_b(output::FloatOutput *pin_b) { pin_b_ = pin_b; }
|
||||||
@@ -33,7 +33,7 @@ class HBridgeFan : public Component, public fan::Fan {
|
|||||||
output::FloatOutput *pin_b_;
|
output::FloatOutput *pin_b_;
|
||||||
output::FloatOutput *enable_{nullptr};
|
output::FloatOutput *enable_{nullptr};
|
||||||
output::BinaryOutput *oscillating_{nullptr};
|
output::BinaryOutput *oscillating_{nullptr};
|
||||||
int speed_count_{};
|
uint8_t speed_count_{};
|
||||||
DecayMode decay_mode_{DECAY_MODE_SLOW};
|
DecayMode decay_mode_{DECAY_MODE_SLOW};
|
||||||
fan::FanTraits traits_;
|
fan::FanTraits traits_;
|
||||||
std::vector<const char *> preset_modes_{};
|
std::vector<const char *> preset_modes_{};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ CONFIG_SCHEMA = (
|
|||||||
cv.Optional(CONF_SPEED): cv.invalid(
|
cv.Optional(CONF_SPEED): cv.invalid(
|
||||||
"Configuring individual speeds is deprecated."
|
"Configuring individual speeds is deprecated."
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_SPEED_COUNT, default=100): cv.int_range(min=1),
|
cv.Optional(CONF_SPEED_COUNT, default=100): cv.int_range(min=1, max=255),
|
||||||
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace speed {
|
|||||||
|
|
||||||
class SpeedFan : public Component, public fan::Fan {
|
class SpeedFan : public Component, public fan::Fan {
|
||||||
public:
|
public:
|
||||||
SpeedFan(int speed_count) : speed_count_(speed_count) {}
|
SpeedFan(uint8_t speed_count) : speed_count_(speed_count) {}
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_output(output::FloatOutput *output) { this->output_ = output; }
|
void set_output(output::FloatOutput *output) { this->output_ = output; }
|
||||||
@@ -26,7 +26,7 @@ class SpeedFan : public Component, public fan::Fan {
|
|||||||
output::FloatOutput *output_;
|
output::FloatOutput *output_;
|
||||||
output::BinaryOutput *oscillating_{nullptr};
|
output::BinaryOutput *oscillating_{nullptr};
|
||||||
output::BinaryOutput *direction_{nullptr};
|
output::BinaryOutput *direction_{nullptr};
|
||||||
int speed_count_{};
|
uint8_t speed_count_{};
|
||||||
fan::FanTraits traits_;
|
fan::FanTraits traits_;
|
||||||
std::vector<const char *> preset_modes_{};
|
std::vector<const char *> preset_modes_{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ CONFIG_SCHEMA = (
|
|||||||
{
|
{
|
||||||
cv.Optional(CONF_HAS_DIRECTION, default=False): cv.boolean,
|
cv.Optional(CONF_HAS_DIRECTION, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_HAS_OSCILLATING, default=False): cv.boolean,
|
cv.Optional(CONF_HAS_OSCILLATING, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_SPEED_COUNT): cv.int_range(min=1),
|
cv.Optional(CONF_SPEED_COUNT): cv.int_range(min=1, max=255),
|
||||||
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
cv.Optional(CONF_PRESET_MODES): validate_preset_modes,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class TemplateFan final : public Component, public fan::Fan {
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_has_direction(bool has_direction) { this->has_direction_ = has_direction; }
|
void set_has_direction(bool has_direction) { this->has_direction_ = has_direction; }
|
||||||
void set_has_oscillating(bool has_oscillating) { this->has_oscillating_ = has_oscillating; }
|
void set_has_oscillating(bool has_oscillating) { this->has_oscillating_ = has_oscillating; }
|
||||||
void set_speed_count(int count) { this->speed_count_ = count; }
|
void set_speed_count(uint8_t count) { this->speed_count_ = count; }
|
||||||
void set_preset_modes(std::initializer_list<const char *> presets) { this->preset_modes_ = presets; }
|
void set_preset_modes(std::initializer_list<const char *> presets) { this->preset_modes_ = presets; }
|
||||||
fan::FanTraits get_traits() override { return this->traits_; }
|
fan::FanTraits get_traits() override { return this->traits_; }
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ class TemplateFan final : public Component, public fan::Fan {
|
|||||||
|
|
||||||
bool has_oscillating_{false};
|
bool has_oscillating_{false};
|
||||||
bool has_direction_{false};
|
bool has_direction_{false};
|
||||||
int speed_count_{0};
|
uint8_t speed_count_{0};
|
||||||
fan::FanTraits traits_;
|
fan::FanTraits traits_;
|
||||||
std::vector<const char *> preset_modes_{};
|
std::vector<const char *> preset_modes_{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.Optional(CONF_SPEED_DATAPOINT): cv.uint8_t,
|
cv.Optional(CONF_SPEED_DATAPOINT): cv.uint8_t,
|
||||||
cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
|
cv.Optional(CONF_SWITCH_DATAPOINT): cv.uint8_t,
|
||||||
cv.Optional(CONF_DIRECTION_DATAPOINT): cv.uint8_t,
|
cv.Optional(CONF_DIRECTION_DATAPOINT): cv.uint8_t,
|
||||||
cv.Optional(CONF_SPEED_COUNT, default=3): cv.int_range(min=1, max=256),
|
cv.Optional(CONF_SPEED_COUNT, default=3): cv.int_range(min=1, max=255),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.COMPONENT_SCHEMA),
|
.extend(cv.COMPONENT_SCHEMA),
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace tuya {
|
|||||||
|
|
||||||
class TuyaFan : public Component, public fan::Fan {
|
class TuyaFan : public Component, public fan::Fan {
|
||||||
public:
|
public:
|
||||||
TuyaFan(Tuya *parent, int speed_count) : parent_(parent), speed_count_(speed_count) {}
|
TuyaFan(Tuya *parent, uint8_t speed_count) : parent_(parent), speed_count_(speed_count) {}
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_speed_id(uint8_t speed_id) { this->speed_id_ = speed_id; }
|
void set_speed_id(uint8_t speed_id) { this->speed_id_ = speed_id; }
|
||||||
@@ -27,7 +27,7 @@ class TuyaFan : public Component, public fan::Fan {
|
|||||||
optional<uint8_t> switch_id_{};
|
optional<uint8_t> switch_id_{};
|
||||||
optional<uint8_t> oscillation_id_{};
|
optional<uint8_t> oscillation_id_{};
|
||||||
optional<uint8_t> direction_id_{};
|
optional<uint8_t> direction_id_{};
|
||||||
int speed_count_{};
|
uint8_t speed_count_{};
|
||||||
TuyaDatapointType speed_type_{};
|
TuyaDatapointType speed_type_{};
|
||||||
TuyaDatapointType oscillation_type_{};
|
TuyaDatapointType oscillation_type_{};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user